Added singed distance function nodes

This commit is contained in:
RodZill4 2019-11-06 08:30:36 +01:00
parent 5141b3e297
commit 1c4e904a22
8 changed files with 503 additions and 0 deletions

View File

@ -0,0 +1,49 @@
{
"name": "sdannularshape",
"node_position": {
"x": 0,
"y": 0
},
"parameters": {
"bevel": 0,
"cx": 0,
"cy": 0,
"h": 0.08,
"k": 0.15,
"op": 0,
"r": 0.1,
"w": 0.28
},
"shader_model": {
"code": "",
"global": "float sdSmoothUnion( float d1, float d2, float k ) {\n float h = clamp( 0.5 + 0.5*(d2-d1)/k, 0.0, 1.0 );\n return mix( d2, d1, h ) - k*h*(1.0-h); }\n\nfloat sdSmoothSubtraction( float d1, float d2, float k ) {\n float h = clamp( 0.5 - 0.5*(d2+d1)/k, 0.0, 1.0 );\n return mix( d2, -d1, h ) + k*h*(1.0-h); }\n\nfloat sdSmoothIntersection( float d1, float d2, float k ) {\n float h = clamp( 0.5 - 0.5*(d2-d1)/k, 0.0, 1.0 );\n return mix( d2, d1, h ) + k*h*(1.0-h); }\n",
"inputs": [
{
"default": "0.0",
"label": "",
"name": "in",
"type": "f"
}
],
"instance": "",
"name": "sdAnnularShape",
"outputs": [
{
"f": "abs($in($uv)) - $r",
"type": "f"
}
],
"parameters": [
{
"default": 0,
"label": "",
"max": 1,
"min": 0,
"name": "r",
"step": 0.01,
"type": "float"
}
]
},
"type": "shader"
}

View File

@ -0,0 +1,65 @@
{
"name": "sdboolean",
"node_position": {
"x": 0,
"y": 0
},
"parameters": {
"bevel": 0,
"cx": 0,
"cy": 0,
"h": 0.08,
"op": 0,
"r": 0.3,
"w": 0.28
},
"shader_model": {
"code": "",
"global": "float sdUnion( float d1, float d2 ) { return min(d1,d2); }\nfloat sdSubtraction( float d1, float d2 ) { return max(-d1,d2); }\nfloat sdIntersection( float d1, float d2 ) { return max(d1,d2); }\n",
"inputs": [
{
"default": "0.0",
"label": "",
"name": "in1",
"type": "f"
},
{
"default": "0.0",
"label": "",
"name": "in2",
"type": "f"
}
],
"instance": "",
"name": "sdBoolean",
"outputs": [
{
"f": "sd$op($in1($uv), $in2($uv))",
"type": "f"
}
],
"parameters": [
{
"default": 0,
"label": "",
"name": "op",
"type": "enum",
"values": [
{
"name": "Union",
"value": "Union"
},
{
"name": "Subtraction",
"value": "Subtraction"
},
{
"name": "Intersection",
"value": "Intersection"
}
]
}
]
},
"type": "shader"
}

View File

@ -0,0 +1,68 @@
{
"name": "sdbox",
"node_position": {
"x": 0,
"y": 0
},
"parameters": {
"cx": 0,
"cy": 0,
"h": 0.2,
"r": 0.3,
"w": 0.3
},
"shader_model": {
"code": "",
"global": "float sdBox(in vec2 p, in vec2 b) {\n vec2 d = abs(p)-b;\n return length(max(d,vec2(0))) + min(max(d.x,d.y),0.0);\n}\n",
"inputs": [
],
"instance": "",
"name": "sdBox",
"outputs": [
{
"f": "sdBox($uv-0.5*vec2($cx+1.0, $cy+1.0), vec2($w, $h))",
"type": "f"
}
],
"parameters": [
{
"default": 0.5,
"label": "Width",
"max": 1,
"min": 0,
"name": "w",
"step": 0.01,
"type": "float"
},
{
"default": 1,
"label": "Height",
"max": 1,
"min": 0,
"name": "h",
"step": 0.01,
"type": "float"
},
{
"default": 0,
"label": "Center X",
"max": 1,
"min": -1,
"name": "cx",
"step": 0.01,
"type": "float"
},
{
"default": 0,
"label": "Center Y",
"max": 1,
"min": -1,
"name": "cy",
"step": 0.01,
"type": "float"
}
]
},
"type": "shader"
}

View File

@ -0,0 +1,57 @@
{
"name": "sdcircle",
"node_position": {
"x": 0,
"y": 0
},
"parameters": {
"cx": 0,
"cy": 0,
"r": 0.5
},
"shader_model": {
"code": "",
"global": "float sdCircle(vec2 p, float r) {\n return length(p) - r;\n}\n",
"inputs": [
],
"instance": "",
"name": "sdCircle",
"outputs": [
{
"f": "sdCircle($uv-0.5*vec2($cx+1.0, $cy+1.0), $r)",
"type": "f"
}
],
"parameters": [
{
"default": 0.5,
"label": "Radius",
"max": 1,
"min": 0,
"name": "r",
"step": 0.01,
"type": "float"
},
{
"default": 0,
"label": "Center X",
"max": 1,
"min": -1,
"name": "cx",
"step": 0.01,
"type": "float"
},
{
"default": 0,
"label": "Center Y",
"max": 1,
"min": -1,
"name": "cy",
"step": 0.01,
"type": "float"
}
]
},
"type": "shader"
}

View File

@ -0,0 +1,72 @@
{
"name": "sdline",
"node_position": {
"x": 0,
"y": 0
},
"parameters": {
"ax": 0.2,
"ay": 0.2,
"bx": 0.8,
"by": 0.8,
"cx": 0,
"cy": 0,
"h": 0.2,
"r": 0.3,
"w": 0.3
},
"shader_model": {
"code": "",
"global": "float sdLine( in vec2 p, in vec2 a, in vec2 b ) {\n vec2 pa = p-a, ba = b-a;\n float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n return length( pa - ba*h );\n}\n",
"inputs": [
],
"instance": "",
"name": "sdLine",
"outputs": [
{
"f": "sdLine($uv, vec2($ax, $ay), vec2($bx, $by))",
"type": "f"
}
],
"parameters": [
{
"default": 0,
"label": "A X",
"max": 1,
"min": 0,
"name": "ax",
"step": 0.01,
"type": "float"
},
{
"default": 0,
"label": "A Y",
"max": 1,
"min": 0,
"name": "ay",
"step": 0.01,
"type": "float"
},
{
"default": 1,
"label": "B X",
"max": 1,
"min": 0,
"name": "bx",
"step": 0.01,
"type": "float"
},
{
"default": 1,
"label": "B Y",
"max": 1,
"min": 0,
"name": "by",
"step": 0.01,
"type": "float"
}
]
},
"type": "shader"
}

View File

@ -0,0 +1,68 @@
{
"name": "sdrhombus",
"node_position": {
"x": 0,
"y": 0
},
"parameters": {
"cx": 0,
"cy": 0,
"h": 0.2,
"r": 0.3,
"w": 0.3
},
"shader_model": {
"code": "",
"global": "float sdr_ndot(vec2 a, vec2 b) { return a.x*b.x - a.y*b.y; }\nfloat sdRhombus(in vec2 p, in vec2 b) {\n vec2 q = abs(p);\n float h = clamp((-2.0*sdr_ndot(q,b)+sdr_ndot(b,b))/dot(b,b),-1.0,1.0);\n float d = length( q - 0.5*b*vec2(1.0-h,1.0+h) );\n return d * sign( q.x*b.y + q.y*b.x - b.x*b.y );\n}",
"inputs": [
],
"instance": "",
"name": "sdRhombus",
"outputs": [
{
"f": "sdRhombus($uv-0.5*vec2($cx+1.0, $cy+1.0), vec2($w, $h))",
"type": "f"
}
],
"parameters": [
{
"default": 0.5,
"label": "Width",
"max": 1,
"min": 0,
"name": "w",
"step": 0.01,
"type": "float"
},
{
"default": 1,
"label": "Height",
"max": 1,
"min": 0,
"name": "h",
"step": 0.01,
"type": "float"
},
{
"default": 0,
"label": "Center X",
"max": 1,
"min": -1,
"name": "cx",
"step": 0.01,
"type": "float"
},
{
"default": 0,
"label": "Center Y",
"max": 1,
"min": -1,
"name": "cy",
"step": 0.01,
"type": "float"
}
]
},
"type": "shader"
}

View File

@ -0,0 +1,49 @@
{
"name": "sdroundedshape",
"node_position": {
"x": 0,
"y": 0
},
"parameters": {
"bevel": 0,
"cx": 0,
"cy": 0,
"h": 0.08,
"k": 0.15,
"op": 0,
"r": 0.2,
"w": 0.28
},
"shader_model": {
"code": "",
"global": "float sdSmoothUnion( float d1, float d2, float k ) {\n float h = clamp( 0.5 + 0.5*(d2-d1)/k, 0.0, 1.0 );\n return mix( d2, d1, h ) - k*h*(1.0-h); }\n\nfloat sdSmoothSubtraction( float d1, float d2, float k ) {\n float h = clamp( 0.5 - 0.5*(d2+d1)/k, 0.0, 1.0 );\n return mix( d2, -d1, h ) + k*h*(1.0-h); }\n\nfloat sdSmoothIntersection( float d1, float d2, float k ) {\n float h = clamp( 0.5 - 0.5*(d2-d1)/k, 0.0, 1.0 );\n return mix( d2, d1, h ) + k*h*(1.0-h); }\n",
"inputs": [
{
"default": "0.0",
"label": "",
"name": "in",
"type": "f"
}
],
"instance": "",
"name": "sdRoundedShape",
"outputs": [
{
"f": "$in($uv) - $r",
"type": "f"
}
],
"parameters": [
{
"default": 0,
"label": "",
"max": 1,
"min": 0,
"name": "r",
"step": 0.01,
"type": "float"
}
]
},
"type": "shader"
}

View File

@ -0,0 +1,75 @@
{
"name": "sdsmoothboolean",
"node_position": {
"x": 0,
"y": 0
},
"parameters": {
"bevel": 0,
"cx": 0,
"cy": 0,
"h": 0.08,
"k": 0.1,
"op": 0,
"r": 0.3,
"w": 0.28
},
"shader_model": {
"code": "",
"global": "float sdSmoothUnion( float d1, float d2, float k ) {\n float h = clamp( 0.5 + 0.5*(d2-d1)/k, 0.0, 1.0 );\n return mix( d2, d1, h ) - k*h*(1.0-h); }\n\nfloat sdSmoothSubtraction( float d1, float d2, float k ) {\n float h = clamp( 0.5 - 0.5*(d2+d1)/k, 0.0, 1.0 );\n return mix( d2, -d1, h ) + k*h*(1.0-h); }\n\nfloat sdSmoothIntersection( float d1, float d2, float k ) {\n float h = clamp( 0.5 - 0.5*(d2-d1)/k, 0.0, 1.0 );\n return mix( d2, d1, h ) + k*h*(1.0-h); }\n",
"inputs": [
{
"default": "0.0",
"label": "",
"name": "in1",
"type": "f"
},
{
"default": "0.0",
"label": "",
"name": "in2",
"type": "f"
}
],
"instance": "",
"name": "sdSmoothBoolean",
"outputs": [
{
"f": "sdSmooth$op($in1($uv), $in2($uv), $k)",
"type": "f"
}
],
"parameters": [
{
"default": 0,
"label": "",
"name": "op",
"type": "enum",
"values": [
{
"name": "Union",
"value": "Union"
},
{
"name": "Subtraction",
"value": "Subtraction"
},
{
"name": "Intersection",
"value": "Intersection"
}
]
},
{
"default": 0,
"label": "",
"max": 1,
"min": 0,
"name": "k",
"step": 0.01,
"type": "float"
}
]
},
"type": "shader"
}