Skip to content

Commit

Permalink
Merge pull request #650 from williamchange/variadic-sdf-boolean
Browse files Browse the repository at this point in the history
Make SDF boolean nodes variadic
  • Loading branch information
RodZill4 authored Apr 30, 2024
2 parents 08d5c77 + 72d6921 commit ba328bf
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 95 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
36 changes: 21 additions & 15 deletions addons/material_maker/nodes/sdf3d_boolean.mmg
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
{
"generic_size": 1,
"name": "sdf3d_boolean",
"node_position": {
"x": 0,
"y": 0
},
"parameters": {
"op": 0
"op1": 0
},
"seed": 60292,
"seed_locked": true,
"seed_int": 0,
"shader_model": {
"code": "",
"code": [
"vec2 $(name_uv)_b = $b($uv);",
"",
"#for",
"$(name_uv)_b = $op#($s#($uv), $(name_uv)_b);",
"#end"
],
"global": [
"vec2 sdf3dc_union(vec2 a, vec2 b) {",
"\treturn vec2(min(a.x, b.x), mix(b.y, a.y, step(a.x, b.x)));",
Expand All @@ -28,36 +34,36 @@
"default": "vec2(100.0, 0.0)",
"label": "",
"longdesc": "The first shape, defined as a signed distance function",
"name": "in1",
"shortdesc": "Input1",
"name": "b",
"shortdesc": "Base Shape",
"type": "sdf3dc"
},
{
"default": "vec2(100.0, 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": "sdf3dc"
}
],
"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": "Boolean",
"outputs": [
{
"longdesc": "The shape generated by the boolean operation",
"sdf3dc": "$op($in1($uv), $in2($uv))",
"longdesc": "The shape generated by the boolean operation(s)",
"sdf3dc": "$(name_uv)_b",
"shortdesc": "Output",
"type": "sdf3dc"
}
],
"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
39 changes: 23 additions & 16 deletions addons/material_maker/nodes/sdf3d_smoothboolean.mmg
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
{
"generic_size": 1,
"name": "sdf3d_smoothboolean",
"node_position": {
"x": 0,
"y": 0
},
"parameters": {
"k": 0.15,
"op": 0
"k1": 0.15,
"op1": 0
},
"seed_int": 0,
"shader_model": {
"code": "",
"code": [
"vec2 $(name_uv)_b = $b($uv);",
"",
"#for",
"$(name_uv)_b = sdf3d_smooth_$op#($s#($uv), $(name_uv)_b, $k#);",
"#end"
],
"global": [
"vec2 sdf3d_smooth_union(vec2 d1, vec2 d2, float k) {",
"\tfloat h = clamp(0.5+0.5*(d2.x-d1.x)/k, 0.0, 1.0);",
Expand All @@ -33,36 +40,36 @@
"default": "vec2(100.0, 0.0)",
"label": "",
"longdesc": "The first shape, defined as a signed distance function",
"name": "in1",
"shortdesc": "Input1",
"name": "b",
"shortdesc": "Base Shape",
"type": "sdf3dc"
},
{
"default": "vec2(100.0, 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": "sdf3dc"
}
],
"instance": "",
"longdesc": "Performs a smooth boolean operation (union, intersection or difference) between two shapes",
"longdesc": "Performs smooth boolean operation(s) (union, intersection or difference) between two or more shapes",
"name": "SmoothBoolean",
"outputs": [
{
"longdesc": "The shape generated by the boolean operation",
"sdf3dc": "sdf3d_smooth_$op($in1($uv), $in2($uv), $k)",
"longdesc": "The shape generated by the boolean operation(s)",
"sdf3dc": "$(name_uv)_b",
"shortdesc": "Output",
"type": "sdf3dc"
}
],
"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 All @@ -83,11 +90,11 @@
{
"control": "None",
"default": 0,
"label": "",
"label": "2:",
"longdesc": "The smoothness of the boolean operation",
"max": 1,
"min": 0,
"name": "k",
"name": "k#",
"shortdesc": "Smoothness",
"step": 0.01,
"type": "float"
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.15,
"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_3d_sdf_operators_boolean.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified material_maker/doc/images/node_3d_sdf_operators_smoothboolean.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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_3d_sdf_operators_boolean.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ boolean node applies them to the output.
Inputs
::::::

The **Boolean** node accepts 2 inputs in 3D signed distance function format.
The **Boolean** node accepts two or more inputs in 3D signed distance function format.

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

Outputs
:::::::
Expand Down
4 changes: 3 additions & 1 deletion material_maker/doc/node_3d_sdf_operators_smoothboolean.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ smooth boolean node applies them to the output.
Inputs
::::::

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

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

Outputs
:::::::
Expand Down
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
Loading

0 comments on commit ba328bf

Please sign in to comment.