Skip to content

Commit

Permalink
make 2d sdf boolean nodes variadic
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchange committed Dec 17, 2023
1 parent 13255b7 commit 05c3f58
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 32 deletions.
33 changes: 20 additions & 13 deletions addons/material_maker/nodes/sdboolean.mmg
Original file line number Diff line number Diff line change
@@ -1,51 +1,58 @@
{
"generic_size": 1,
"name": "sdboolean",
"node_position": {
"x": 0,
"y": 0
},
"parameters": {
"op": 0
"op1": 0
},
"seed_int": 0,
"shader_model": {
"code": "",
"code": [
"float $(name_uv)_b = $b($uv);",
"",
"#for",
"$(name_uv)_b = $op# $s#($uv), $(name_uv)_b);",
"#end"
],
"global": "",
"inputs": [
{
"default": "0.0",
"label": "",
"longdesc": "The first shape, defined as a signed distance function",
"name": "in1",
"shortdesc": "Input1",
"name": "b",
"shortdesc": "Base Shape",
"type": "sdf2d"
},
{
"default": "0.0",
"label": "",
"longdesc": "The second shape, defined as a signed distance function",
"name": "in2",
"shortdesc": "Input2",
"longdesc": "The subsequent shape, defined as a signed distance function",
"name": "s#",
"shortdesc": "Shape#",
"type": "sdf2d"
}
],
"instance": "",
"longdesc": "Performs a boolean operation (union, intersection or difference) between two shapes",
"longdesc": "Performs boolean operation(s) (union, intersection or difference) between two or more shapes",
"name": "sdBoolean",
"outputs": [
{
"longdesc": "The shape generated by the boolean operation",
"sdf2d": "$op $in1($uv), $in2($uv))",
"longdesc": "The shape generated by the boolean operation(s)",
"sdf2d": "$(name_uv)_b",
"shortdesc": "Output",
"type": "sdf2d"
}
],
"parameters": [
{
"default": 2,
"label": "",
"default": 0,
"label": "2:",
"longdesc": "The operation performed by this node",
"name": "op",
"name": "op#",
"shortdesc": "Operation",
"type": "enum",
"values": [
Expand Down
41 changes: 24 additions & 17 deletions addons/material_maker/nodes/sdsmoothboolean.mmg
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
{
"generic_size": 1,
"name": "sdsmoothboolean",
"node_position": {
"x": 0,
"y": 0
},
"parameters": {
"k": 0.15,
"op": 0
"k1": 0,
"op1": 0
},
"seed_int": 0,
"shader_model": {
"code": "",
"code": [
"float $(name_uv)_b = $b($uv);",
"",
"#for",
"$(name_uv)_b = sdSmooth$op#($s#($uv), $(name_uv)_b, $k#);",
"#end"
],
"global": [
"float sdSmoothUnion( float d1, float d2, float k ) {",
"\tfloat h = clamp( 0.5 + 0.5*(d2-d1)/k, 0.0, 1.0 );",
Expand All @@ -30,37 +37,37 @@
"default": "0.0",
"label": "",
"longdesc": "The first shape, defined as a signed distance function",
"name": "in1",
"shortdesc": "Input1",
"name": "b",
"shortdesc": "Base Shape",
"type": "sdf2d"
},
{
"default": "0.0",
"label": "",
"longdesc": "The second shape, defined as a signed distance function",
"name": "in2",
"shortdesc": "Input2",
"longdesc": "The subsequent shape, defined as a signed distance function",
"name": "s#",
"shortdesc": "Shape#",
"type": "sdf2d"
}
],
"instance": "",
"longdesc": "Performs a smooth boolean operation (union, intersection or difference) between two shapes",
"longdesc": "Performs smooth boolean operations (union, intersection or difference) between two or more shapes",
"name": "sdSmoothBoolean",
"outputs": [
{
"longdesc": "The shape generated by the boolean operation",
"sdf2d": "sdSmooth$op($in1($uv), $in2($uv), $k)",
"longdesc": "The shape generated by the boolean operation(s)",
"sdf2d": "$(name_uv)_b",
"shortdesc": "Output",
"type": "sdf2d"
}
],
"parameters": [
{
"default": 0,
"label": "",
"label": "2:",
"longdesc": "The operation performed by this node",
"name": "op",
"shortdesc": "Operation",
"name": "op#",
"shortdesc": "Operation#",
"type": "enum",
"values": [
{
Expand All @@ -80,12 +87,12 @@
{
"control": "None",
"default": 0,
"label": "",
"label": "2:",
"longdesc": "The smoothness of the boolean operation",
"max": 1,
"min": 0,
"name": "k",
"shortdesc": "Smoothness",
"name": "k#",
"shortdesc": "Smoothness#",
"step": 0.01,
"type": "float"
}
Expand Down
Binary file modified material_maker/doc/images/node_simple_sdf_operators_sdboolean.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion material_maker/doc/node_simple_sdf_operators_sdboolean.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ intersection or difference) of its inputs.
Inputs
::::::

The **sdBoolean** node accepts 2 inputs in signed distance function format.
The **sdBoolean** node accepts two or more inputs in signed distance function format.

This node is variadic, and more shapes can be added.

Outputs
:::::::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ intersection or difference) of its inputs.
Inputs
::::::

The **sdSmoothBoolean** node accepts 2 inputs in signed distance function format.
The **sdSmoothBoolean** node accepts two or more inputs in signed distance function format.

This node is variadic, and more shapes can be added.

Outputs
:::::::
Expand Down

0 comments on commit 05c3f58

Please sign in to comment.