diff --git a/addons/material_maker/engine/gen_base.gd b/addons/material_maker/engine/gen_base.gd index 3611a75..7c5c050 100644 --- a/addons/material_maker/engine/gen_base.gd +++ b/addons/material_maker/engine/gen_base.gd @@ -204,7 +204,7 @@ func get_shader_code(uv : String, output_index : int, context : MMGenContext) -> var rv = _get_shader_code(uv, output_index, context) while rv is GDScriptFunctionState: rv = yield(rv, "completed") - if rv.has("type"): + if rv.has("type") and mm_io_types.types.has(rv.type): if mm_io_types.types[rv.type].has("convert"): for c in mm_io_types.types[rv.type].convert: if !rv.has(c.type): diff --git a/addons/material_maker/nodes/mul_detect.mmg b/addons/material_maker/nodes/mul_detect.mmg new file mode 100644 index 0000000..bb58248 --- /dev/null +++ b/addons/material_maker/nodes/mul_detect.mmg @@ -0,0 +1,60 @@ +{ + "name": "mul_detect", + "node_position": { + "x": 0, + "y": 0 + }, + "parameters": { + "t": 0.01, + "v": 0.5 + }, + "shader_model": { + "code": "float $(name_uv)_d = ($in($uv)-$v)/$t;", + "global": "", + "inputs": [ + { + "default": "1.0", + "label": "", + "name": "mul", + "type": "f" + }, + { + "default": "0.0", + "label": "", + "name": "in", + "type": "f" + } + ], + "instance": "", + "name": "MulDetect", + "outputs": [ + { + "f": "$mul($uv)*clamp(1.0-$(name_uv)_d*$(name_uv)_d, 0.0, 1.0)", + "type": "f" + } + ], + "parameters": [ + { + "control": "None", + "default": 0.5, + "label": "Value", + "max": 1, + "min": 0, + "name": "v", + "step": 0.01, + "type": "float" + }, + { + "control": "None", + "default": 0.1, + "label": "Tolerance", + "max": 1, + "min": 0.01, + "name": "t", + "step": 0.001, + "type": "float" + } + ] + }, + "type": "shader" +} \ No newline at end of file diff --git a/addons/material_maker/nodes/raymarching.mmg b/addons/material_maker/nodes/raymarching.mmg index 770058a..20012a6 100644 --- a/addons/material_maker/nodes/raymarching.mmg +++ b/addons/material_maker/nodes/raymarching.mmg @@ -8,7 +8,7 @@ }, "shader_model": { - "code": "float $(name_uv)_d = raymarch_$name($uv);\n", + "code": "vec2 $(name_uv)_d = raymarch_$name($uv);\n", "global": "", "inputs": [ { @@ -16,19 +16,23 @@ "function": true, "label": "", "name": "sdf", - "type": "sdf3d" + "type": "sdf3dc" } ], - "instance": "float input_$name(vec3 p) {\n\tif (p.z > 0.0) {\n\t\treturn $sdf(p);\n\t} else {\n\t\treturn p.z;\n\t}\n}\n\nfloat raymarch_$name(vec2 uv) {\n\tvec3 ro = vec3(uv-vec2(0.5), 1.0);\n\tvec3 rd = vec3(0.0, 0.0, -1.0);\n\tfloat dO=0.;\n \n for (int i=0; i < 25; i++) {\n \tvec3 p = ro + rd*dO;\n float dS = input_$name(p);\n dO += dS;\n if (dO > 1.0 || dS < 0.0001) break;\n }\n \n return dO;\n}\n\nvec3 normal_$name(vec3 p) {\n\tfloat d = input_$name(p);\n float e = .001;\n \n vec3 n = d - vec3(\n input_$name(p-vec3(e, 0.0, 0.0)),\n input_$name(p-vec3(0.0, e, 0.0)),\n input_$name(p-vec3(0.0, 0.0, e)));\n \n return vec3(-1.0, -1.0, -1.0)*normalize(n);\n}\n\n", + "instance": "vec2 raymarch_$name(vec2 uv) {\n\tvec3 ro = vec3(uv-vec2(0.5), 1.0);\n\tvec3 rd = vec3(0.0, 0.0, -1.0);\n\tfloat dO = 0.0;\n\tfloat c = 0.0;\n for (int i=0; i < 100; i++) {\n \tvec3 p = ro + rd*dO;\n vec2 dS = $sdf(p);\n dO += dS.x;\n\n if (dO >= 1.0) {\n\t\t\tbreak;\n\t\t} else if (dS.x < 0.0001) {\n\t\t\tc = dS.y;\n\t\t\tbreak;\n\t\t}\n }\n \n return vec2(dO, c);\n}\n\nvec3 normal_$name(vec3 p) {\n\tif (p.z <= 0.0) {\n\t\treturn vec3(0.0, 0.0, 1.0);\n\t}\n\n\tfloat d = $sdf(p).x;\n float e = .001;\n \n vec3 n = d - vec3(\n $sdf(p-vec3(e, 0.0, 0.0)).x,\n $sdf(p-vec3(0.0, e, 0.0)).x,\n $sdf(p-vec3(0.0, 0.0, e)).x);\n \n return vec3(-1.0, -1.0, -1.0)*normalize(n);\n}\n\n", "name": "Raymarching", "outputs": [ { - "f": "1.0-$(name_uv)_d", + "f": "1.0-$(name_uv)_d.x", "type": "f" }, { - "rgb": "vec3(0.5)+0.5*normal_$name(vec3($uv-vec2(0.5), 1.0-$(name_uv)_d))", + "rgb": "vec3(0.5)+0.5*normal_$name(vec3($uv-vec2(0.5), 1.0-$(name_uv)_d.x))", "type": "rgb" + }, + { + "f": "$(name_uv)_d.y", + "type": "f" } ], "parameters": [ diff --git a/addons/material_maker/nodes/sdf3d_boolean.mmg b/addons/material_maker/nodes/sdf3d_boolean.mmg index 417e9ba..ef4a803 100644 --- a/addons/material_maker/nodes/sdf3d_boolean.mmg +++ b/addons/material_maker/nodes/sdf3d_boolean.mmg @@ -15,47 +15,47 @@ }, "shader_model": { "code": "", - "global": "", + "global": "vec2 sdf3dc_union(vec2 a, vec2 b) {\n\treturn vec2(min(a.x, b.x), mix(b.y, a.y, step(a.x, b.x)));\n}\nvec2 sdf3dc_sub(vec2 a, vec2 b) {\n\treturn vec2(max(a.x, -b.x), a.y);\n}\nvec2 sdf3dc_inter(vec2 a, vec2 b) {\n\treturn vec2(max(a.x, b.x), mix(a.y, b.y, step(a.x, b.x)));\n}\n", "inputs": [ { - "default": "0.0", + "default": "vec2(0.0)", "label": "", "name": "in1", - "type": "sdf3d" + "type": "sdf3dc" }, { - "default": "0.0", + "default": "vec2(0.0)", "label": "", "name": "in2", - "type": "sdf3d" + "type": "sdf3dc" } ], "instance": "", "name": "Boolean", "outputs": [ { - "sdf3d": "$op $in1($uv), $in2($uv))", - "type": "sdf3d" + "sdf3dc": "$op($in1($uv), $in2($uv))", + "type": "sdf3dc" } ], "parameters": [ { - "default": 1, + "default": 2, "label": "", "name": "op", "type": "enum", "values": [ { "name": "Union", - "value": "min(" + "value": "sdf3dc_union" }, { "name": "Subtraction", - "value": "max(-" + "value": "sdf3dc_sub" }, { "name": "Intersection", - "value": "max(" + "value": "sdf3dc_inter" } ] } diff --git a/addons/material_maker/nodes/sdf3d_circle_repeat.mmg b/addons/material_maker/nodes/sdf3d_circle_repeat.mmg index 889944a..a0f65d1 100644 --- a/addons/material_maker/nodes/sdf3d_circle_repeat.mmg +++ b/addons/material_maker/nodes/sdf3d_circle_repeat.mmg @@ -6,7 +6,7 @@ }, "parameters": { "a": 0, - "c": 4, + "c": 5, "r": 0.24, "rx": 4, "ry": 4, @@ -20,22 +20,23 @@ "global": "vec3 circle_repeat_transform(vec3 p, float count) {\n\tfloat r = 6.28/count;\n\tfloat pa = atan(p.x, p.y);\n\tfloat a = mod(pa+0.5*r, r)-0.5*r;\n\tvec3 rv;\n\tfloat c = cos(a-pa);\n\tfloat s = sin(a-pa);\n\trv.x = p.x*c+p.y*s;\n\trv.y = -p.x*s+p.y*c;\n\trv.z = p.z;\n\treturn rv;\n}\n", "inputs": [ { - "default": "0.0", + "default": "vec2(0.0)", "label": "", "name": "in", - "type": "sdf3d" + "type": "sdf3dc" } ], "instance": "", "name": "Circle Repeat", "outputs": [ { - "sdf3d": "$in(circle_repeat_transform($uv, $c))", - "type": "sdf3d" + "sdf3dc": "$in(circle_repeat_transform($uv, $c))", + "type": "sdf3dc" } ], "parameters": [ { + "control": "None", "default": 4, "label": "", "max": 32, diff --git a/addons/material_maker/nodes/sdf3d_repeat.mmg b/addons/material_maker/nodes/sdf3d_repeat.mmg index 3e2875c..de3daed 100644 --- a/addons/material_maker/nodes/sdf3d_repeat.mmg +++ b/addons/material_maker/nodes/sdf3d_repeat.mmg @@ -6,9 +6,9 @@ }, "parameters": { "a": 0, - "r": 0.24, - "rx": 4, - "ry": 4, + "r": 0.3, + "rx": 3, + "ry": 3, "s": 0.3, "x": 0.35, "y": 0, @@ -19,22 +19,23 @@ "global": "vec3 repeat(vec3 p, vec3 r, float seed, float randomness) {\n\tvec3 a = (rand3(floor(mod((p.xy+0.5*r.xy)/r.xy, 1.0/r.xy)+vec2(seed)))-0.5)*6.28*randomness;\n\tp = mod(p+0.5*r,r)-0.5*r;\n\tvec3 rv;\n\tfloat c;\n\tfloat s;\n\tc = cos(a.x);\n\ts = sin(a.x);\n\trv.x = p.x;\n\trv.y = p.y*c+p.z*s;\n\trv.z = -p.y*s+p.z*c;\n\tc = cos(a.y);\n\ts = sin(a.y);\n\tp.x = rv.x*c+rv.z*s;\n\tp.y = rv.y;\n\tp.z = -rv.x*s+rv.z*c;\n\tc = cos(a.z);\n\ts = sin(a.z);\n\trv.x = p.x*c+p.y*s;\n\trv.y = -p.x*s+p.y*c;\n\trv.z = p.z;\n\treturn rv;\n}\n", "inputs": [ { - "default": "0.0", + "default": "vec2(0.0)", "label": "", "name": "in", - "type": "sdf3d" + "type": "sdf3dc" } ], "instance": "", "name": "Repeat", "outputs": [ { - "sdf3d": "$in(repeat($uv, vec3(1.0/$rx, 1.0/$ry, 0.0), $seed, $r))", - "type": "sdf3d" + "sdf3dc": "$in(repeat($uv, vec3(1.0/$rx, 1.0/$ry, 0.0), $seed, $r))", + "type": "sdf3dc" } ], "parameters": [ { + "control": "None", "default": 4, "label": "X", "max": 32, @@ -44,6 +45,7 @@ "type": "float" }, { + "control": "None", "default": 4, "label": "Y", "max": 32, @@ -53,6 +55,7 @@ "type": "float" }, { + "control": "None", "default": 0.5, "label": "R", "max": 1, diff --git a/addons/material_maker/nodes/sdf3d_rotate.mmg b/addons/material_maker/nodes/sdf3d_rotate.mmg index 588e943..f0f3dad 100644 --- a/addons/material_maker/nodes/sdf3d_rotate.mmg +++ b/addons/material_maker/nodes/sdf3d_rotate.mmg @@ -18,22 +18,23 @@ "global": "vec3 rotate3d(vec3 p, vec3 a) {\n\tvec3 rv;\n\tfloat c;\n\tfloat s;\n\tc = cos(a.x);\n\ts = sin(a.x);\n\trv.x = p.x;\n\trv.y = p.y*c+p.z*s;\n\trv.z = -p.y*s+p.z*c;\n\tc = cos(a.y);\n\ts = sin(a.y);\n\tp.x = rv.x*c+rv.z*s;\n\tp.y = rv.y;\n\tp.z = -rv.x*s+rv.z*c;\n\tc = cos(a.z);\n\ts = sin(a.z);\n\trv.x = p.x*c+p.y*s;\n\trv.y = -p.x*s+p.y*c;\n\trv.z = p.z;\n\treturn rv;\n}\n", "inputs": [ { - "default": "0.0", + "default": "vec2(0.0)", "label": "", "name": "in", - "type": "sdf3d" + "type": "sdf3dc" } ], "instance": "", "name": "Rotate", "outputs": [ { - "sdf3d": "$in(rotate3d($uv, -vec3($ax, $ay, $az)*0.01745329251))", - "type": "sdf3d" + "sdf3dc": "$in(rotate3d($uv, -vec3($ax, $ay, $az)*0.01745329251))", + "type": "sdf3dc" } ], "parameters": [ { + "control": "None", "default": 0, "label": "X", "max": 180, @@ -43,6 +44,7 @@ "type": "float" }, { + "control": "None", "default": 0, "label": "Y", "max": 180, @@ -52,6 +54,7 @@ "type": "float" }, { + "control": "None", "default": 0, "label": "Z", "max": 180, diff --git a/addons/material_maker/nodes/sdf3d_rounded.mmg b/addons/material_maker/nodes/sdf3d_rounded.mmg index 87ce10b..fdf3491 100644 --- a/addons/material_maker/nodes/sdf3d_rounded.mmg +++ b/addons/material_maker/nodes/sdf3d_rounded.mmg @@ -11,30 +11,31 @@ "h": 0.08, "k": 0.15, "op": 0, - "r": 0.05, + "r": 0.1, "w": 0.28 }, "shader_model": { - "code": "", + "code": "vec2 $(name_uv)_v = $in($uv);", "global": "", "inputs": [ { - "default": "0.0", + "default": "vec2(0.0)", "label": "", "name": "in", - "type": "sdf3d" + "type": "sdf3dc" } ], "instance": "", "name": "Rounded", "outputs": [ { - "sdf3d": "$in($uv)-$r", - "type": "sdf3d" + "sdf3dc": "vec2($(name_uv)_v.x-$r, $(name_uv)_v.y)", + "type": "sdf3dc" } ], "parameters": [ { + "control": "None", "default": 0, "label": "", "max": 1, diff --git a/addons/material_maker/nodes/sdf3d_scale.mmg b/addons/material_maker/nodes/sdf3d_scale.mmg index 9cec47e..b6727a9 100644 --- a/addons/material_maker/nodes/sdf3d_scale.mmg +++ b/addons/material_maker/nodes/sdf3d_scale.mmg @@ -12,22 +12,22 @@ "z": 0 }, "shader_model": { - "code": "", + "code": "vec2 $(name_uv)_in = $in(($uv)/$s);", "global": "", "inputs": [ { - "default": "0.0", + "default": "vec2(0.0)", "label": "", "name": "in", - "type": "sdf3d" + "type": "sdf3dc" } ], "instance": "", "name": "Scale", "outputs": [ { - "sdf3d": "$in(($uv)/$s)*$s", - "type": "sdf3d" + "sdf3dc": "vec2($(name_uv)_in.x*$s, $(name_uv)_in.y)", + "type": "sdf3dc" } ], "parameters": [ diff --git a/addons/material_maker/nodes/sdf3d_smoothboolean.mmg b/addons/material_maker/nodes/sdf3d_smoothboolean.mmg index ff3ac8a..42e2062 100644 --- a/addons/material_maker/nodes/sdf3d_smoothboolean.mmg +++ b/addons/material_maker/nodes/sdf3d_smoothboolean.mmg @@ -10,57 +10,58 @@ "cy": 0, "h": 0.08, "k": 0.1, - "op": 0, + "op": 2, "r": 0.3, "w": 0.28 }, "shader_model": { "code": "", - "global": "float sdf3SmoothUnion(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}\n\nfloat sdf3SmoothSubtraction( 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}\n\nfloat sdf3SmoothIntersection( 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}\n", + "global": "vec2 sdf3d_smooth_union(vec2 d1, vec2 d2, float k) {\n float h = clamp(0.5+0.5*(d2.x-d1.x)/k, 0.0, 1.0);\n return vec2(mix(d2.x, d1.x, h)-k*h*(1.0-h), mix(d2.y, d1.y, step(d1.x, d2.x)));\n}\n\nvec2 sdf3d_smooth_subtraction(vec2 d1, vec2 d2, float k ) {\n float h = clamp(0.5-0.5*(d2.x+d1.x)/k, 0.0, 1.0);\n return vec2(mix(d2.x, -d1.x, h )+k*h*(1.0-h), d2.y);\n}\n\nvec2 sdf3d_smooth_intersection(vec2 d1, vec2 d2, float k ) {\n float h = clamp(0.5-0.5*(d2.x-d1.x)/k, 0.0, 1.0);\n return vec2(mix(d2.x, d1.x, h)+k*h*(1.0-h), mix(d1.y, d2.y, step(d1.x, d2.x)));\n}\n", "inputs": [ { - "default": "0.0", + "default": "vec2(0.0)", "label": "", "name": "in1", - "type": "sdf3d" + "type": "sdf3dc" }, { - "default": "0.0", + "default": "vec2(0.0)", "label": "", "name": "in2", - "type": "sdf3d" + "type": "sdf3dc" } ], "instance": "", - "name": "sdSmoothBoolean", + "name": "SmoothBoolean", "outputs": [ { - "sdf3d": "sdf3Smooth$op($in1($uv), $in2($uv), $k)", - "type": "sdf3d" + "sdf3dc": "sdf3d_smooth_$op($in1($uv), $in2($uv), $k)", + "type": "sdf3dc" } ], "parameters": [ { - "default": 0, + "default": 2, "label": "", "name": "op", "type": "enum", "values": [ { "name": "Union", - "value": "Union" + "value": "union" }, { "name": "Subtraction", - "value": "Subtraction" + "value": "subtraction" }, { "name": "Intersection", - "value": "Intersection" + "value": "intersection" } ] }, { + "control": "None", "default": 0, "label": "", "max": 1, diff --git a/addons/material_maker/nodes/sdf3d_translate.mmg b/addons/material_maker/nodes/sdf3d_translate.mmg index 141810f..732a9b4 100644 --- a/addons/material_maker/nodes/sdf3d_translate.mmg +++ b/addons/material_maker/nodes/sdf3d_translate.mmg @@ -14,18 +14,18 @@ "global": "", "inputs": [ { - "default": "0.0", + "default": "vec2(0.0)", "label": "", "name": "in", - "type": "sdf3d" + "type": "sdf3dc" } ], "instance": "", "name": "Translate", "outputs": [ { - "sdf3d": "$in($uv-vec3($x, $y, $z))", - "type": "sdf3d" + "sdf3dc": "$in($uv-vec3($x, $y, $z))", + "type": "sdf3dc" } ], "parameters": [ diff --git a/material_maker/examples/mmm_donuts.ptex b/material_maker/examples/mmm_donuts.ptex index a162c0a..dc30143 100644 --- a/material_maker/examples/mmm_donuts.ptex +++ b/material_maker/examples/mmm_donuts.ptex @@ -48,60 +48,6 @@ "to": "raymarching", "to_port": 0 }, - { - "from": "raymarching", - "from_port": 0, - "to": "10053_2", - "to_port": 0 - }, - { - "from": "raymarching", - "from_port": 2, - "to": "10053_2", - "to_port": 1 - }, - { - "from": "raymarching", - "from_port": 0, - "to": "10053_2_2", - "to_port": 0 - }, - { - "from": "raymarching", - "from_port": 2, - "to": "10053_2_2", - "to_port": 1 - }, - { - "from": "raymarching", - "from_port": 0, - "to": "10053", - "to_port": 0 - }, - { - "from": "raymarching", - "from_port": 2, - "to": "10053", - "to_port": 1 - }, - { - "from": "10053", - "from_port": 0, - "to": "mwf_create_map", - "to_port": 0 - }, - { - "from": "10053_2_2", - "from_port": 0, - "to": "mwf_create_map_3", - "to_port": 0 - }, - { - "from": "10053_2", - "from_port": 0, - "to": "mwf_create_map_2", - "to_port": 0 - }, { "from": "mwf_create_map", "from_port": 0, @@ -396,17 +342,65 @@ "to": "colorize", "to_port": 0 }, - { - "from": "perlin_2", - "from_port": 0, - "to": "10053_2_2_2", - "to_port": 1 - }, { "from": "mwf_output", "from_port": 6, "to": "Material", "to_port": 6 + }, + { + "from": "raymarching", + "from_port": 0, + "to": "mul_detect", + "to_port": 0 + }, + { + "from": "raymarching", + "from_port": 2, + "to": "mul_detect", + "to_port": 1 + }, + { + "from": "mul_detect", + "from_port": 0, + "to": "mwf_create_map", + "to_port": 0 + }, + { + "from": "mul_detect_2", + "from_port": 0, + "to": "mwf_create_map_3", + "to_port": 0 + }, + { + "from": "raymarching", + "from_port": 0, + "to": "mul_detect_2", + "to_port": 0 + }, + { + "from": "raymarching", + "from_port": 2, + "to": "mul_detect_2", + "to_port": 1 + }, + { + "from": "raymarching", + "from_port": 0, + "to": "mul_detect_2_2", + "to_port": 0 + }, + { + "from": "mul_detect_2_2", + "from_port": 0, + "to": "mwf_create_map_2", + "to_port": 0 + }, + { + "from": "raymarching", + "from_port": 2, + "to": "mul_detect_2_2", + "to_port": 1 } ], "label": "Graph", @@ -419,8 +413,8 @@ { "name": "Material", "node_position": { - "x": 1730.920044, - "y": -7.312012 + "x": 1596.135986, + "y": -86.800011 }, "parameters": { "albedo_color": { @@ -444,8 +438,8 @@ { "name": "raymarching", "node_position": { - "x": -87.107498, - "y": 153.625015 + "x": -93.107498, + "y": 112.625015 }, "parameters": { @@ -568,8 +562,8 @@ "label": "Donut", "name": "graph", "node_position": { - "x": -685.679138, - "y": -17.270287 + "x": -664.759155, + "y": -18.094296 }, "nodes": [ { @@ -1126,8 +1120,8 @@ { "name": "sdf3d_repeat", "node_position": { - "x": -508.122192, - "y": -14.881775 + "x": -482.202179, + "y": -14.881774 }, "parameters": { "a": 0, @@ -1196,8 +1190,8 @@ { "name": "sdf3d_scale_2", "node_position": { - "x": -690.122192, - "y": 57.118225 + "x": -670.842224, + "y": 66.030228 }, "parameters": { "a": 0, @@ -1243,12 +1237,12 @@ { "name": "sdf3d_repeat_2", "node_position": { - "x": -506.122192, + "x": -480.202179, "y": 110.618225 }, "parameters": { "a": 0, - "r": 0.33, + "r": 0.21, "rx": 3, "ry": 3, "s": 0.3, @@ -1313,13 +1307,13 @@ { "name": "sdf3d_translate_3_2_2", "node_position": { - "x": -505.872192, + "x": -479.952209, "y": 213.034912 }, "parameters": { "x": 0.14, "y": 0.11, - "z": 0.1 + "z": 0.2 }, "shader_model": { "code": "", @@ -1378,8 +1372,8 @@ { "name": "sdf3d_boolean", "node_position": { - "x": -270.800781, - "y": 120.820618 + "x": -252.248795, + "y": 76.092621 }, "parameters": { "bevel": 0, @@ -1443,8 +1437,8 @@ { "name": "sdf3d_translate_3_2_2_2", "node_position": { - "x": -281.800781, - "y": 194.820618 + "x": -278.344788, + "y": 149.892624 }, "parameters": { "x": 0, @@ -1515,171 +1509,24 @@ }, "name": "comment", "node_position": { - "x": -718.245239, - "y": -47.346039 + "x": -681.957275, + "y": -50.802036 }, "parameters": { "size": 4 }, "size": { - "x": 790, - "y": 394.999969 + "x": 757.167969, + "y": 382.903992 }, "text": "\n", "title": "Render donuts with color indexes", "type": "comment" }, - { - "name": "10053", - "node_position": { - "x": 117.221985, - "y": -12.346039 - }, - "parameters": { - "v": 0.31 - }, - "shader_model": { - "code": "", - "global": "", - "inputs": [ - { - "default": "1.0", - "label": "Label", - "name": "mul", - "type": "f" - }, - { - "default": "0.0", - "label": "", - "name": "in", - "type": "f" - } - ], - "instance": "", - "name": "MulDetect", - "outputs": [ - { - "f": "$mul($uv)*(1.0-10.0*($in($uv)-$v)*($in($uv)-$v))", - "type": "f" - } - ], - "parameters": [ - { - "control": "None", - "default": 0.5, - "label": "", - "max": 1, - "min": 0, - "name": "v", - "step": 0.01, - "type": "float" - } - ] - }, - "type": "shader" - }, - { - "name": "10053_2", - "node_position": { - "x": 121.462341, - "y": 395.472137 - }, - "parameters": { - "v": 0.08 - }, - "shader_model": { - "code": "", - "global": "", - "inputs": [ - { - "default": "1.0", - "label": "Label", - "name": "mul", - "type": "f" - }, - { - "default": "0.0", - "label": "", - "name": "in", - "type": "f" - } - ], - "instance": "", - "name": "MulDetect", - "outputs": [ - { - "f": "$mul($uv)*(1.0-10.0*($in($uv)-$v)*($in($uv)-$v))", - "type": "f" - } - ], - "parameters": [ - { - "control": "None", - "default": 0.5, - "label": "", - "max": 1, - "min": 0, - "name": "v", - "step": 0.01, - "type": "float" - } - ] - }, - "type": "shader" - }, - { - "name": "10053_2_2", - "node_position": { - "x": 113.786713, - "y": 170.138794 - }, - "parameters": { - "v": 0.87 - }, - "shader_model": { - "code": "", - "global": "", - "inputs": [ - { - "default": "1.0", - "label": "Label", - "name": "mul", - "type": "f" - }, - { - "default": "0.0", - "label": "", - "name": "in", - "type": "f" - } - ], - "instance": "", - "name": "MulDetect", - "outputs": [ - { - "f": "$mul($uv)*clamp((1.0-10.0*($in($uv)-$v)*($in($uv)-$v)), 0.0, 1.0)", - "type": "f" - } - ], - "parameters": [ - { - "control": "None", - "default": 0.5, - "label": "", - "max": 1, - "min": 0, - "name": "v", - "step": 0.01, - "type": "float" - } - ] - }, - "type": "shader" - }, { "name": "mwf_create_map", "node_position": { - "x": 358.843994, + "x": 360.571991, "y": -128.630447 }, "parameters": { @@ -1765,8 +1612,8 @@ { "name": "mwf_mix", "node_position": { - "x": 864.268921, - "y": 189.119568 + "x": 853.900879, + "y": 164.927567 }, "parameters": { @@ -1776,8 +1623,8 @@ { "name": "mwf_mix_2", "node_position": { - "x": 1141.761108, - "y": -8.130447 + "x": 1083.009155, + "y": -87.618446 }, "parameters": { @@ -1874,8 +1721,8 @@ "label": "Output", "name": "mwf_output", "node_position": { - "x": 1405.761108, - "y": -1.630447 + "x": 1307.265137, + "y": -74.206451 }, "nodes": [ { @@ -2470,8 +2317,8 @@ { "name": "mwf_mix_3", "node_position": { - "x": 857.856567, - "y": -274.880432 + "x": 845.760559, + "y": -242.048431 }, "parameters": { @@ -2526,8 +2373,8 @@ { "name": "perlin", "node_position": { - "x": 358.92984, - "y": 508.119568 + "x": 363.92984, + "y": 499.119568 }, "parameters": { "iterations": 8, @@ -2571,21 +2418,21 @@ "color": { "a": 1, "b": 0, - "g": 0.5, - "r": 1, + "g": 1, + "r": 0.9375, "type": "Color" }, "name": "comment_2", "node_position": { - "x": 97.468719, - "y": -49.148132 + "x": 82.468719, + "y": -50.148132 }, "parameters": { "size": 4 }, "size": { - "x": 242, - "y": 533 + "x": 255.271576, + "y": 432.232056 }, "text": "", "title": "Separate colors", @@ -2618,100 +2465,62 @@ { "color": { "a": 1, - "b": 0, - "g": 0.6875, - "r": 1, + "b": 1, + "g": 0, + "r": 0.96875, "type": "Color" }, "name": "comment_2_2_2", "node_position": { - "x": 838.947449, - "y": -317.398193 + "x": 828.579407, + "y": -289.750183 }, "parameters": { "size": 4 }, "size": { - "x": 837, - "y": 783 + "x": 743.688171, + "y": 725.975952 }, "text": "", "title": "Mix the result and generate output", "type": "comment" }, { - "name": "10053_2_2_2", + "name": "mul_detect", "node_position": { - "x": -158.775818, - "y": -271.032806 + "x": 90.234436, + "y": -13.032837 }, "parameters": { - "t": 0.009, - "v": 0.47 + "t": 0.01, + "v": 0.31 }, - "shader_model": { - "code": "float $(name_uv)_d = ($in($uv)-$v)/$t;", - "global": "", - "inputs": [ - { - "default": "1.0", - "label": "", - "name": "mul", - "type": "f" - }, - { - "default": "0.0", - "label": "", - "name": "in", - "type": "f" - } - ], - "instance": "", - "name": "MulDetect", - "outputs": [ - { - "f": "$mul($uv)*clamp(1.0-$(name_uv)_d*$(name_uv)_d, 0.0, 1.0)", - "type": "f" - } - ], - "parameters": [ - { - "control": "None", - "default": 0.5, - "label": "Value", - "max": 1, - "min": 0, - "name": "v", - "step": 0.01, - "type": "float" - }, - { - "control": "None", - "default": 0.1, - "label": "Tolerance", - "max": 1, - "min": 0.01, - "name": "t", - "step": 0.001, - "type": "float" - } - ] - }, - "type": "shader" + "type": "mul_detect" }, { - "name": "perlin_2", + "name": "mul_detect_2", "node_position": { - "x": -463.275513, - "y": -249.782776 + "x": 94.964081, + "y": 132.26152 }, "parameters": { - "iterations": 3, - "persistence": 0.5, - "scale_x": 4, - "scale_y": 4 + "t": 0.01, + "v": 0.87 }, - "type": "perlin" + "type": "mul_detect" + }, + { + "name": "mul_detect_2_2", + "node_position": { + "x": 90.964081, + "y": 288.261536 + }, + "parameters": { + "t": 0.01, + "v": 0.08 + }, + "type": "mul_detect" } ], "parameters": { diff --git a/material_maker/examples/skulls.ptex b/material_maker/examples/skulls.ptex index 9e92938..424f826 100644 --- a/material_maker/examples/skulls.ptex +++ b/material_maker/examples/skulls.ptex @@ -138,12 +138,6 @@ "to": "sdf3d_boolean_2_2_2", "to_port": 1 }, - { - "from": "sdf3d_boolean_2_2_2", - "from_port": 0, - "to": "_3_2", - "to_port": 0 - }, { "from": "blend_2", "from_port": 0, @@ -156,12 +150,6 @@ "to": "normal_map", "to_port": 0 }, - { - "from": "_3_2", - "from_port": 1, - "to": "blend_2", - "to_port": 0 - }, { "from": "normal_map", "from_port": 0, @@ -180,12 +168,6 @@ "to": "sdf3d_scale", "to_port": 0 }, - { - "from": "_3_2", - "from_port": 0, - "to": "buffer", - "to_port": 0 - }, { "from": "buffer", "from_port": 0, @@ -233,6 +215,24 @@ "from_port": 0, "to": "blend", "to_port": 2 + }, + { + "from": "sdf3d_boolean_2_2_2", + "from_port": 0, + "to": "raymarching", + "to_port": 0 + }, + { + "from": "raymarching", + "from_port": 0, + "to": "buffer", + "to_port": 0 + }, + { + "from": "raymarching", + "from_port": 1, + "to": "blend_2", + "to_port": 0 } ], "label": "Graph", @@ -311,45 +311,6 @@ }, "type": "colorize" }, - { - "name": "_3_2", - "node_position": { - "x": -378.336426, - "y": 1476.947388 - }, - "parameters": { - - }, - "shader_model": { - "code": "float $(name_uv)_d = raymarch_$name($uv);\n", - "global": "", - "inputs": [ - { - "default": "0.0", - "function": true, - "label": "", - "name": "sdf", - "type": "sdf3d" - } - ], - "instance": "float input_$name(vec3 p) {\n\treturn min($sdf(p), p.z);\n}\n\nfloat raymarch_$name(vec2 uv) {\n\tvec3 ro = vec3(uv-vec2(0.5), 1.0);\n\tvec3 rd = vec3(0.0, 0.0, -1.0);\n\tfloat dO=0.;\n \n for (int i=0; i < 50; i++) {\n \tvec3 p = ro + rd*dO;\n float dS = input_$name(p);\n dO += dS;\n if (dO > 0.001 && dS < 0.0001) break;\n }\n \n return dO;\n}\n\nvec3 normal_$name(vec3 p) {\n\tfloat d = input_$name(p);\n float e = .001;\n \n vec3 n = d - vec3(\n input_$name(p-vec3(e, 0.0, 0.0)),\n input_$name(p-vec3(0.0, e, 0.0)),\n input_$name(p-vec3(0.0, 0.0, e)));\n \n return vec3(-1.0, -1.0, -1.0)*normalize(n);\n}\n\n", - "name": "Raymarching", - "outputs": [ - { - "f": "1.0-$(name_uv)_d", - "type": "f" - }, - { - "rgb": "vec3(0.5)+0.5*normal_$name(vec3($uv-vec2(0.5), 1.0-$(name_uv)_d))", - "type": "rgb" - } - ], - "parameters": [ - - ] - }, - "type": "shader" - }, { "name": "colorize_2", "node_position": { @@ -1108,6 +1069,8 @@ "param0": 11, "param1": 1.02, "param2": 0, + "param3": 0, + "param4": 1, "size": 4 }, "type": "normal_map" @@ -2007,6 +1970,17 @@ "blend_type": 3 }, "type": "blend" + }, + { + "name": "raymarching", + "node_position": { + "x": -371.992065, + "y": 1466.176514 + }, + "parameters": { + + }, + "type": "raymarching" } ], "parameters": {