Fixed switch, background 2D preview, node templates and examples

This commit is contained in:
RodZill4 2020-03-25 19:06:31 +01:00
parent a6f26464d2
commit 8beaabefdc
13 changed files with 389 additions and 648 deletions

View File

@ -73,6 +73,9 @@ func set_parameter(p, v) -> void:
parent.reconnect_outputs(self, outputs_changes) parent.reconnect_outputs(self, outputs_changes)
.set_parameter(p, v) .set_parameter(p, v)
emit_signal("parameter_changed", "__update_all__", null) emit_signal("parameter_changed", "__update_all__", null)
if p == "source":
for i in range(int(parameters.outputs)):
notify_output_change(i)
# get the list of outputs that depend on the input whose index is passed as parameter # get the list of outputs that depend on the input whose index is passed as parameter
func follow_input(input_index : int) -> Array: func follow_input(input_index : int) -> Array:
@ -89,7 +92,7 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext) -
while rv is GDScriptFunctionState: while rv is GDScriptFunctionState:
rv = yield(rv, "completed") rv = yield(rv, "completed")
return rv return rv
return { globals=[], defs="", code="", textures={} } return { globals=[], defs="", code="", textures={}, type="f", f="0.0" }
func _serialize(data: Dictionary) -> Dictionary: func _serialize(data: Dictionary) -> Dictionary:
return data return data

View File

@ -5,7 +5,7 @@
"y": 0 "y": 0
}, },
"parameters": { "parameters": {
"iterations": 3, "iterations": 2,
"noise": 0, "noise": 0,
"persistence": 0.5, "persistence": 0.5,
"scale_x": 4, "scale_x": 4,
@ -13,7 +13,7 @@
}, },
"shader_model": { "shader_model": {
"code": "", "code": "",
"global": "float fbm_value(vec2 coord, vec2 size, float seed) {\n\tvec2 o = floor(coord)+rand2(vec2(float(seed), 1.0-float(seed)))+size;\n\tvec2 f = fract(coord);\n\tfloat p00 = rand(mod(o, size));\n\tfloat p01 = rand(mod(o + vec2(0.0, 1.0), size));\n\tfloat p10 = rand(mod(o + vec2(1.0, 0.0), size));\n\tfloat p11 = rand(mod(o + vec2(1.0, 1.0), size));\n\tvec2 t = f * f * (3.0 - 2.0 * f);\n\treturn mix(mix(p00, p10, t.x), mix(p01, p11, t.x), t.y);\n}\n\nfloat fbm_perlin(vec2 coord, vec2 size, float seed) {\n\tvec2 o = floor(coord)+rand2(vec2(float(seed), 1.0-float(seed)))+size;\n\tvec2 f = fract(coord);\n\tfloat a00 = rand(mod(o, size)) * 6.28318530718;\n\tfloat a01 = rand(mod(o + vec2(0.0, 1.0), size)) * 6.28318530718;\n\tfloat a10 = rand(mod(o + vec2(1.0, 0.0), size)) * 6.28318530718;\n\tfloat a11 = rand(mod(o + vec2(1.0, 1.0), size)) * 6.28318530718;\n\tvec2 v00 = vec2(cos(a00), sin(a00));\n\tvec2 v01 = vec2(cos(a01), sin(a01));\n\tvec2 v10 = vec2(cos(a10), sin(a10));\n\tvec2 v11 = vec2(cos(a11), sin(a11));\n\tfloat p00 = dot(v00, f);\n\tfloat p01 = dot(v01, f - vec2(0.0, 1.0));\n\tfloat p10 = dot(v10, f - vec2(1.0, 0.0));\n\tfloat p11 = dot(v11, f - vec2(1.0, 1.0));\n\tvec2 t = f * f * (3.0 - 2.0 * f);\n\treturn 0.5 + mix(mix(p00, p10, t.x), mix(p01, p11, t.x), t.y);\n}\n\nfloat fbm_cellular(vec2 coord, vec2 size, float seed) {\n\tvec2 o = floor(coord)+rand2(vec2(float(seed), 1.0-float(seed)))+size;\n\tvec2 f = fract(coord);\n\tfloat min_dist = 2.0;\n\tfor(float x = -1.0; x <= 1.0; x++) {\n\t\tfor(float y = -1.0; y <= 1.0; y++) {\n\t\t\tvec2 node = rand2(mod(o + vec2(x, y), size)) + vec2(x, y);\n\t\t\tfloat dist = sqrt((f - node).x * (f - node).x + (f - node).y * (f - node).y);\n\t\t\tmin_dist = min(min_dist, dist);\n\t\t}\n\t}\n\treturn min_dist;\n}\n", "global": "float fbm_value(vec2 coord, vec2 size, float seed) {\n\tvec2 o = floor(coord)+rand2(vec2(float(seed), 1.0-float(seed)))+size;\n\tvec2 f = fract(coord);\n\tfloat p00 = rand(mod(o, size));\n\tfloat p01 = rand(mod(o + vec2(0.0, 1.0), size));\n\tfloat p10 = rand(mod(o + vec2(1.0, 0.0), size));\n\tfloat p11 = rand(mod(o + vec2(1.0, 1.0), size));\n\tvec2 t = f * f * (3.0 - 2.0 * f);\n\treturn mix(mix(p00, p10, t.x), mix(p01, p11, t.x), t.y);\n}\n\nfloat fbm_perlin(vec2 coord, vec2 size, float seed) {\n\tvec2 o = floor(coord)+rand2(vec2(float(seed), 1.0-float(seed)))+size;\n\tvec2 f = fract(coord);\n\tfloat a00 = rand(mod(o, size)) * 6.28318530718;\n\tfloat a01 = rand(mod(o + vec2(0.0, 1.0), size)) * 6.28318530718;\n\tfloat a10 = rand(mod(o + vec2(1.0, 0.0), size)) * 6.28318530718;\n\tfloat a11 = rand(mod(o + vec2(1.0, 1.0), size)) * 6.28318530718;\n\tvec2 v00 = vec2(cos(a00), sin(a00));\n\tvec2 v01 = vec2(cos(a01), sin(a01));\n\tvec2 v10 = vec2(cos(a10), sin(a10));\n\tvec2 v11 = vec2(cos(a11), sin(a11));\n\tfloat p00 = dot(v00, f);\n\tfloat p01 = dot(v01, f - vec2(0.0, 1.0));\n\tfloat p10 = dot(v10, f - vec2(1.0, 0.0));\n\tfloat p11 = dot(v11, f - vec2(1.0, 1.0));\n\tvec2 t = f * f * (3.0 - 2.0 * f);\n\treturn 0.5 + mix(mix(p00, p10, t.x), mix(p01, p11, t.x), t.y);\n}\n\nfloat fbm_cellular(vec2 coord, vec2 size, float seed) {\n\tvec2 o = floor(coord)+rand2(vec2(float(seed), 1.0-float(seed)))+size;\n\tvec2 f = fract(coord);\n\tfloat min_dist = 2.0;\n\tfor(float x = -1.0; x <= 1.0; x++) {\n\t\tfor(float y = -1.0; y <= 1.0; y++) {\n\t\t\tvec2 node = rand2(mod(o + vec2(x, y), size)) + vec2(x, y);\n\t\t\tfloat dist = sqrt((f - node).x * (f - node).x + (f - node).y * (f - node).y);\n\t\t\tmin_dist = min(min_dist, dist);\n\t\t}\n\t}\n\treturn min_dist;\n}\n\nfloat fbm_cellular2(vec2 coord, vec2 size, float seed) {\n\tvec2 o = floor(coord)+rand2(vec2(float(seed), 1.0-float(seed)))+size;\n\tvec2 f = fract(coord);\n\tfloat min_dist1 = 2.0;\n\tfloat min_dist2 = 2.0;\n\tfor(float x = -1.0; x <= 1.0; x++) {\n\t\tfor(float y = -1.0; y <= 1.0; y++) {\n\t\t\tvec2 node = rand2(mod(o + vec2(x, y), size)) + vec2(x, y);\n\t\t\tfloat dist = sqrt((f - node).x * (f - node).x + (f - node).y * (f - node).y);\n\t\t\tif (min_dist1 > dist) {\n\t\t\t\tmin_dist2 = min_dist1;\n\t\t\t\tmin_dist1 = dist;\n\t\t\t} else if (min_dist2 > dist) {\n\t\t\t\tmin_dist2 = dist;\n\t\t\t}\n\t\t}\n\t}\n\treturn min_dist2-min_dist1;\n}\n\nfloat fbm_cellular3(vec2 coord, vec2 size, float seed) {\n\tvec2 o = floor(coord)+rand2(vec2(float(seed), 1.0-float(seed)))+size;\n\tvec2 f = fract(coord);\n\tfloat min_dist = 2.0;\n\tfor(float x = -1.0; x <= 1.0; x++) {\n\t\tfor(float y = -1.0; y <= 1.0; y++) {\n\t\t\tvec2 node = rand2(mod(o + vec2(x, y), size)) + vec2(x, y);\n\t\t\tfloat dist = abs((f - node).x) + abs((f - node).y);\n\t\t\tmin_dist = min(min_dist, dist);\n\t\t}\n\t}\n\treturn min_dist;\n}\n\nfloat fbm_cellular4(vec2 coord, vec2 size, float seed) {\n\tvec2 o = floor(coord)+rand2(vec2(float(seed), 1.0-float(seed)))+size;\n\tvec2 f = fract(coord);\n\tfloat min_dist1 = 2.0;\n\tfloat min_dist2 = 2.0;\n\tfor(float x = -1.0; x <= 1.0; x++) {\n\t\tfor(float y = -1.0; y <= 1.0; y++) {\n\t\t\tvec2 node = rand2(mod(o + vec2(x, y), size)) + vec2(x, y);\n\t\t\tfloat dist = abs((f - node).x) + abs((f - node).y);\n\t\t\tif (min_dist1 > dist) {\n\t\t\t\tmin_dist2 = min_dist1;\n\t\t\t\tmin_dist1 = dist;\n\t\t\t} else if (min_dist2 > dist) {\n\t\t\t\tmin_dist2 = dist;\n\t\t\t}\n\t\t}\n\t}\n\treturn min_dist2-min_dist1;\n}\n\nfloat fbm_cellular5(vec2 coord, vec2 size, float seed) {\n\tvec2 o = floor(coord)+rand2(vec2(float(seed), 1.0-float(seed)))+size;\n\tvec2 f = fract(coord);\n\tfloat min_dist = 2.0;\n\tfor(float x = -1.0; x <= 1.0; x++) {\n\t\tfor(float y = -1.0; y <= 1.0; y++) {\n\t\t\tvec2 node = rand2(mod(o + vec2(x, y), size)) + vec2(x, y);\n\t\t\tfloat dist = max(abs((f - node).x), abs((f - node).y));\n\t\t\tmin_dist = min(min_dist, dist);\n\t\t}\n\t}\n\treturn min_dist;\n}\n\nfloat fbm_cellular6(vec2 coord, vec2 size, float seed) {\n\tvec2 o = floor(coord)+rand2(vec2(float(seed), 1.0-float(seed)))+size;\n\tvec2 f = fract(coord);\n\tfloat min_dist1 = 2.0;\n\tfloat min_dist2 = 2.0;\n\tfor(float x = -1.0; x <= 1.0; x++) {\n\t\tfor(float y = -1.0; y <= 1.0; y++) {\n\t\t\tvec2 node = rand2(mod(o + vec2(x, y), size)) + vec2(x, y);\n\t\t\tfloat dist = max(abs((f - node).x), abs((f - node).y));\n\t\t\tif (min_dist1 > dist) {\n\t\t\t\tmin_dist2 = min_dist1;\n\t\t\t\tmin_dist1 = dist;\n\t\t\t} else if (min_dist2 > dist) {\n\t\t\t\tmin_dist2 = dist;\n\t\t\t}\n\t\t}\n\t}\n\treturn min_dist2-min_dist1;\n}\n",
"inputs": [ "inputs": [
], ],
@ -21,13 +21,13 @@
"name": "FBM", "name": "FBM",
"outputs": [ "outputs": [
{ {
"f": "$(name)_fbm($(uv), vec2($(scale_x), $(scale_y)), int($(iterations)), $(persistence), $(seed))", "f": "$(name)_fbm($(uv), vec2($(scale_x), $(scale_y)), int($(iterations)), $(persistence), float($(seed)))",
"type": "f" "type": "f"
} }
], ],
"parameters": [ "parameters": [
{ {
"default": 2, "default": 7,
"label": "Noise", "label": "Noise",
"name": "noise", "name": "noise",
"type": "enum", "type": "enum",
@ -43,6 +43,26 @@
{ {
"name": "Cellular", "name": "Cellular",
"value": "cellular" "value": "cellular"
},
{
"name": "Cellular2",
"value": "cellular2"
},
{
"name": "Cellular3",
"value": "cellular3"
},
{
"name": "Cellular4",
"value": "cellular4"
},
{
"name": "Cellular5",
"value": "cellular5"
},
{
"name": "Cellular6",
"value": "cellular6"
} }
] ]
}, },

View File

@ -25,7 +25,7 @@ vec3 normal(vec3 p) {
} }
vec4 preview_2d(vec2 uv) { vec4 preview_2d(vec2 uv) {
vec2 uv -= vec2(0.5); uv -= vec2(0.5);
vec3 p = vec3(uv, 2.0-raymarch(vec3(uv, 2.0), vec3(0.0, 0.0, -1.0))); vec3 p = vec3(uv, 2.0-raymarch(vec3(uv, 2.0), vec3(0.0, 0.0, -1.0)));
vec3 n = normal(p); vec3 n = normal(p);
vec3 l = vec3(5.0, 5.0, 10.0); vec3 l = vec3(5.0, 5.0, 10.0);

View File

@ -5,7 +5,6 @@
"y": 0 "y": 0
}, },
"parameters": { "parameters": {
"Randomness": 0.5,
"angle": -1, "angle": -1,
"layers": 5, "layers": 5,
"length": 0.25, "length": 0.25,
@ -23,12 +22,13 @@
"name": "Scratches", "name": "Scratches",
"outputs": [ "outputs": [
{ {
"f": "scratches($uv, int($layers), vec2($length, $width), $waviness, $angle, $randomness, vec2($seed, 0.0))", "f": "scratches($uv, int($layers), vec2($length, $width), $waviness, $angle, $randomness, vec2(float($seed), 0.0))",
"type": "f" "type": "f"
} }
], ],
"parameters": [ "parameters": [
{ {
"control": "None",
"default": 0.25, "default": 0.25,
"label": "Length", "label": "Length",
"max": 1, "max": 1,
@ -38,6 +38,7 @@
"type": "float" "type": "float"
}, },
{ {
"control": "None",
"default": 0.5, "default": 0.5,
"label": "Width", "label": "Width",
"max": 1, "max": 1,
@ -47,6 +48,7 @@
"type": "float" "type": "float"
}, },
{ {
"control": "None",
"default": 4, "default": 4,
"label": "Layers", "label": "Layers",
"max": 10, "max": 10,
@ -56,6 +58,7 @@
"type": "float" "type": "float"
}, },
{ {
"control": "None",
"default": 0.5, "default": 0.5,
"label": "Waviness", "label": "Waviness",
"max": 1, "max": 1,
@ -65,6 +68,7 @@
"type": "float" "type": "float"
}, },
{ {
"control": "None",
"default": 0, "default": 0,
"label": "Angle", "label": "Angle",
"max": 180, "max": 180,
@ -74,6 +78,7 @@
"type": "float" "type": "float"
}, },
{ {
"control": "None",
"default": 0.5, "default": 0.5,
"label": "Randomness", "label": "Randomness",
"max": 1, "max": 1,

View File

@ -5,14 +5,9 @@
"y": 0 "y": 0
}, },
"parameters": { "parameters": {
"a": 0,
"r": 0.3, "r": 0.3,
"rx": 3, "rx": 3,
"ry": 3, "ry": 3
"s": 0.3,
"x": 0.35,
"y": 0,
"z": 0
}, },
"shader_model": { "shader_model": {
"code": "", "code": "",
@ -29,7 +24,7 @@
"name": "Repeat", "name": "Repeat",
"outputs": [ "outputs": [
{ {
"sdf3dc": "$in(repeat($uv, vec3(1.0/$rx, 1.0/$ry, 0.0), $seed, $r))", "sdf3dc": "$in(repeat($uv, vec3(1.0/$rx, 1.0/$ry, 0.0), float($seed), $r))",
"type": "sdf3dc" "type": "sdf3dc"
} }
], ],

View File

@ -22,7 +22,7 @@
"name": "TEX3D FBM", "name": "TEX3D FBM",
"outputs": [ "outputs": [
{ {
"tex3d": "vec3($(name)_fbm($(uv).xyz, vec3($(scale_x), $(scale_y), $(scale_z)), int($(iterations)), $(persistence), $(seed)))", "tex3d": "vec3($(name)_fbm($(uv).xyz, vec3($(scale_x), $(scale_y), $(scale_z)), int($(iterations)), $(persistence), float($(seed))))",
"type": "tex3d" "type": "tex3d"
} }
], ],

View File

@ -15,7 +15,7 @@
}, },
"shader_model": { "shader_model": {
"code": "", "code": "",
"global": "float wave3d_constant(float x) {\n\treturn 1.0;\n}\n\nfloat wave3d_sine(float x) {\n\treturn 0.5-0.5*cos(3.14159265359*2.0*x);\n}\n\nfloat wave3d_triangle(float x) {\n\tx = fract(x);\n\treturn min(2.0*x, 2.0-2.0*x);\n}\n\nfloat wave3d_sawtooth(float x) {\n\treturn fract(x);\n}\n\nfloat wave3d_square(float x) {\n\treturn (fract(x) < 0.5) ? 0.0 : 1.0;\n}\n\nfloat wave3d_bounce(float x) {\n\tx = 2.0*(fract(x)-0.5);\n\treturn sqrt(1.0-x*x);\n}\n\nfloat mix3d_mul(float x, float y, float z) {\n\treturn x*y*z;\n}\n\nfloat mix3d_add(float x, float y, float z) {\n\treturn min(x+y+z, 1.0);\n}\n\nfloat mix3d_max(float x, float y, float z) {\n\treturn max(max(x, y), z);\n}\n\nfloat mix_min(float x, float y, float z) {\n\treturn min(min(x, y), z);\n}\n\nfloat mix3d_xor(float x, float y, float z) {\n\tfloat xy = min(x+y, 2.0-x-y);\n\treturn min(xy+z, 2.0-xy-z);\n}\n\nfloat mix3d_pow(float x, float y, float z) {\n\treturn pow(pow(x, y), z);\n}", "global": "float wave3d_constant(float x) {\n\treturn 1.0;\n}\n\nfloat wave3d_sine(float x) {\n\treturn 0.5-0.5*cos(3.14159265359*2.0*x);\n}\n\nfloat wave3d_triangle(float x) {\n\tx = fract(x);\n\treturn min(2.0*x, 2.0-2.0*x);\n}\n\nfloat wave3d_sawtooth(float x) {\n\treturn fract(x);\n}\n\nfloat wave3d_square(float x) {\n\treturn (fract(x) < 0.5) ? 0.0 : 1.0;\n}\n\nfloat wave3d_bounce(float x) {\n\tx = 2.0*(fract(x)-0.5);\n\treturn sqrt(1.0-x*x);\n}\n\nfloat mix3d_mul(float x, float y, float z) {\n\treturn x*y*z;\n}\n\nfloat mix3d_add(float x, float y, float z) {\n\treturn min(x+y+z, 1.0);\n}\n\nfloat mix3d_max(float x, float y, float z) {\n\treturn max(max(x, y), z);\n}\n\nfloat mix3d_min(float x, float y, float z) {\n\treturn min(min(x, y), z);\n}\n\nfloat mix3d_xor(float x, float y, float z) {\n\tfloat xy = min(x+y, 2.0-x-y);\n\treturn min(xy+z, 2.0-xy-z);\n}\n\nfloat mix3d_pow(float x, float y, float z) {\n\treturn pow(pow(x, y), z);\n}",
"inputs": [ "inputs": [
], ],

View File

@ -1,309 +1,4 @@
{ {
"connections": [
{
"from": "graph",
"from_port": 0,
"to": "Material",
"to_port": 4
},
{
"from": "graph",
"from_port": 1,
"to": "Material",
"to_port": 6
},
{
"from": "graph",
"from_port": 2,
"to": "Material",
"to_port": 1
},
{
"from": "graph",
"from_port": 3,
"to": "Material",
"to_port": 2
},
{
"from": "graph",
"from_port": 4,
"to": "Material",
"to_port": 0
}
],
"label": "Graph",
"name": "49",
"node_position": {
"x": 0,
"y": 0
},
"nodes": [
{
"name": "Material",
"node_position": {
"x": -28,
"y": -37
},
"parameters": {
"albedo_color": {
"a": 1,
"b": 1,
"g": 1,
"r": 1,
"type": "Color"
},
"ao_light_affect": 1,
"depth_scale": 0.2,
"emission_energy": 1,
"metallic": 1,
"normal_scale": 1,
"roughness": 1,
"size": 11,
"subsurf_scatter_strength": 0
},
"type": "material"
},
{
"connections": [
{
"from": "normal_map",
"from_port": 0,
"to": "gen_outputs",
"to_port": 0
},
{
"from": "graph",
"from_port": 0,
"to": "normal_map",
"to_port": 0
},
{
"from": "graph",
"from_port": 0,
"to": "colorize_3",
"to_port": 0
},
{
"from": "colorize_3",
"from_port": 0,
"to": "gen_outputs",
"to_port": 1
},
{
"from": "uniform_greyscale",
"from_port": 0,
"to": "gen_outputs",
"to_port": 2
},
{
"from": "colorize_4",
"from_port": 0,
"to": "gen_outputs",
"to_port": 3
},
{
"from": "colorize_5",
"from_port": 0,
"to": "gen_outputs",
"to_port": 4
},
{
"from": "graph",
"from_port": 0,
"to": "colorize_5",
"to_port": 0
},
{
"from": "graph",
"from_port": 0,
"to": "colorize_4",
"to_port": 0
}
],
"label": "Graph",
"name": "graph",
"node_position": {
"x": -353.865601,
"y": 6.860606
},
"nodes": [
{
"name": "colorize_5",
"node_position": {
"x": -240.009644,
"y": -136
},
"parameters": {
"gradient": {
"interpolation": 1,
"points": [
{
"a": 1,
"b": 0,
"g": 0.068034,
"pos": 0,
"r": 0.098958
},
{
"a": 1,
"b": 0,
"g": 0.6875,
"pos": 0.881818,
"r": 1
}
],
"type": "Gradient"
}
},
"type": "colorize"
},
{
"name": "colorize_4",
"node_position": {
"x": -245.009644,
"y": 15
},
"parameters": {
"gradient": {
"interpolation": 1,
"points": [
{
"a": 1,
"b": 0.65625,
"g": 0.65625,
"pos": 0.518182,
"r": 0.65625
},
{
"a": 1,
"b": 0,
"g": 0,
"pos": 0.890909,
"r": 0
}
],
"type": "Gradient"
}
},
"type": "colorize"
},
{
"name": "uniform_greyscale",
"node_position": {
"x": -246.009644,
"y": -55.5
},
"parameters": {
"color": 0.16
},
"type": "uniform_greyscale"
},
{
"name": "colorize_3",
"node_position": {
"x": -244.009644,
"y": 233.5
},
"parameters": {
"gradient": {
"interpolation": 1,
"points": [
{
"a": 1,
"b": 1,
"g": 1,
"pos": 0,
"r": 1
},
{
"a": 1,
"b": 0,
"g": 0,
"pos": 1,
"r": 0
}
],
"type": "Gradient"
}
},
"type": "colorize"
},
{
"name": "normal_map",
"node_position": {
"x": -235.009644,
"y": 96
},
"parameters": {
"param0": 11,
"param1": 1.02,
"param2": 0,
"param4": 1
},
"type": "normal_map"
},
{
"name": "gen_inputs",
"node_position": {
"x": -802.009644,
"y": 6.860606
},
"parameters": {
},
"ports": [
],
"type": "ios"
},
{
"name": "gen_outputs",
"node_position": {
"x": 64.990356,
"y": 6.860606
},
"parameters": {
},
"ports": [
{
"name": "port0",
"type": "rgba"
},
{
"name": "port1",
"type": "rgba"
},
{
"name": "port2",
"type": "f"
},
{
"name": "port3",
"type": "rgba"
},
{
"name": "port4",
"type": "rgba"
}
],
"type": "ios"
},
{
"name": "gen_parameters",
"node_position": {
"x": -553.865601,
"y": -452.254547
},
"parameters": {
},
"type": "remote",
"widgets": [
]
},
{
"connections": [ "connections": [
{ {
"from": "colorize_2", "from": "colorize_2",
@ -317,30 +12,6 @@
"to": "blend", "to": "blend",
"to_port": 1 "to_port": 1
}, },
{
"from": "blend",
"from_port": 0,
"to": "gen_outputs",
"to_port": 0
},
{
"from": "blend",
"from_port": 0,
"to": "gen_outputs",
"to_port": 0
},
{
"from": "blend",
"from_port": 0,
"to": "gen_outputs",
"to_port": 0
},
{
"from": "blend",
"from_port": 0,
"to": "gen_outputs",
"to_port": 0
},
{ {
"from": "beehive_2", "from": "beehive_2",
"from_port": 0, "from_port": 0,
@ -352,20 +23,102 @@
"from_port": 1, "from_port": 1,
"to": "colorize", "to": "colorize",
"to_port": 0 "to_port": 0
},
{
"from": "blend",
"from_port": 0,
"to": "colorize_5",
"to_port": 0
},
{
"from": "blend",
"from_port": 0,
"to": "colorize_4",
"to_port": 0
},
{
"from": "blend",
"from_port": 0,
"to": "normal_map",
"to_port": 0
},
{
"from": "blend",
"from_port": 0,
"to": "colorize_3",
"to_port": 0
},
{
"from": "colorize_5",
"from_port": 0,
"to": "Material",
"to_port": 0
},
{
"from": "uniform_greyscale",
"from_port": 0,
"to": "Material",
"to_port": 1
},
{
"from": "colorize_4",
"from_port": 0,
"to": "Material",
"to_port": 2
},
{
"from": "normal_map",
"from_port": 0,
"to": "Material",
"to_port": 4
},
{
"from": "colorize_3",
"from_port": 0,
"to": "Material",
"to_port": 6
} }
], ],
"label": "Graph", "label": "Graph",
"name": "graph", "name": "49",
"node_position": { "node_position": {
"x": -514.685547, "x": 0,
"y": 2.186363 "y": 0
}, },
"nodes": [ "nodes": [
{
"export_paths": {
},
"name": "Material",
"node_position": {
"x": -28,
"y": -37
},
"parameters": {
"albedo_color": {
"a": 1,
"b": 1,
"g": 1,
"r": 1,
"type": "Color"
},
"ao": 1,
"depth_scale": 0.2,
"emission_energy": 1,
"metallic": 1,
"normal": 1,
"roughness": 1,
"size": 11,
"sss": 0
},
"type": "material"
},
{ {
"name": "colorize", "name": "colorize",
"node_position": { "node_position": {
"x": -510.5, "x": -591.193665,
"y": 45 "y": 41.163864
}, },
"parameters": { "parameters": {
"gradient": { "gradient": {
@ -401,8 +154,8 @@
{ {
"name": "colorize_2", "name": "colorize_2",
"node_position": { "node_position": {
"x": -510.5, "x": -591.193665,
"y": -26 "y": -29.836136
}, },
"parameters": { "parameters": {
"gradient": { "gradient": {
@ -445,8 +198,8 @@
{ {
"name": "blend", "name": "blend",
"node_position": { "node_position": {
"x": -523.009644, "x": -603.703308,
"y": 117 "y": 113.163872
}, },
"parameters": { "parameters": {
"amount": 1, "amount": 1,
@ -455,74 +208,132 @@
"seed_value": -12215, "seed_value": -12215,
"type": "blend" "type": "blend"
}, },
{
"name": "normal_map",
"node_position": {
"x": -270.375671,
"y": 88.194351
},
"parameters": {
"param0": 11,
"param1": 1.02,
"param2": 0,
"param4": 1
},
"type": "normal_map"
},
{
"name": "colorize_3",
"node_position": {
"x": -279.375671,
"y": 225.694351
},
"parameters": {
"gradient": {
"interpolation": 1,
"points": [
{
"a": 1,
"b": 1,
"g": 1,
"pos": 0,
"r": 1
},
{
"a": 1,
"b": 0,
"g": 0,
"pos": 1,
"r": 0
}
],
"type": "Gradient"
}
},
"type": "colorize"
},
{
"name": "uniform_greyscale",
"node_position": {
"x": -281.375671,
"y": -63.305649
},
"parameters": {
"color": 0.16
},
"type": "uniform_greyscale"
},
{
"name": "colorize_4",
"node_position": {
"x": -280.375671,
"y": 7.194351
},
"parameters": {
"gradient": {
"interpolation": 1,
"points": [
{
"a": 1,
"b": 0.65625,
"g": 0.65625,
"pos": 0.518182,
"r": 0.65625
},
{
"a": 1,
"b": 0,
"g": 0,
"pos": 0.890909,
"r": 0
}
],
"type": "Gradient"
}
},
"type": "colorize"
},
{
"name": "colorize_5",
"node_position": {
"x": -275.375671,
"y": -143.805649
},
"parameters": {
"gradient": {
"interpolation": 1,
"points": [
{
"a": 1,
"b": 0,
"g": 0.068034,
"pos": 0,
"r": 0.098958
},
{
"a": 1,
"b": 0,
"g": 0.6875,
"pos": 0.881818,
"r": 1
}
],
"type": "Gradient"
}
},
"type": "colorize"
},
{ {
"name": "beehive_2", "name": "beehive_2",
"node_position": { "node_position": {
"x": -514.732483, "x": -595.426147,
"y": -127.254547 "y": -131.090683
}, },
"parameters": { "parameters": {
"sx": 20, "sx": 20,
"sy": 12 "sy": 12
}, },
"type": "beehive" "type": "beehive"
},
{
"name": "gen_inputs",
"node_position": {
"x": -823.009644,
"y": 2.186363
},
"parameters": {
},
"ports": [
],
"type": "ios"
},
{
"name": "gen_outputs",
"node_position": {
"x": -210.5,
"y": 2.186363
},
"parameters": {
},
"ports": [
{
"name": "port0",
"type": "rgba"
}
],
"type": "ios"
},
{
"name": "gen_parameters",
"node_position": {
"x": -714.685547,
"y": -427.254547
},
"parameters": {
},
"type": "remote",
"widgets": [
]
}
],
"parameters": {
},
"type": "graph"
}
],
"parameters": {
},
"type": "graph"
} }
], ],
"parameters": { "parameters": {

View File

@ -255,6 +255,9 @@
}, },
"nodes": [ "nodes": [
{ {
"export_paths": {
},
"name": "Material", "name": "Material",
"node_position": { "node_position": {
"x": 424, "x": 424,
@ -268,14 +271,14 @@
"r": 1, "r": 1,
"type": "Color" "type": "Color"
}, },
"ao_light_affect": 0.95, "ao": 1,
"depth_scale": 0, "depth_scale": 0,
"emission_energy": 1, "emission_energy": 1,
"metallic": 1, "metallic": 1,
"normal_scale": 1, "normal": 1,
"roughness": 1, "roughness": 1,
"size": 11, "size": 11,
"subsurf_scatter_strength": 0 "sss": 0
}, },
"type": "material" "type": "material"
}, },
@ -286,7 +289,7 @@
"y": 34.016663 "y": 34.016663
}, },
"parameters": { "parameters": {
"steps": 6
}, },
"type": "invert" "type": "invert"
}, },
@ -328,21 +331,21 @@
"to_port": 0 "to_port": 0
}, },
{ {
"from": "_2_2_2_2", "from": "blend",
"from_port": 0, "from_port": 0,
"to": "gen_outputs", "to": "mwf_create_map",
"to_port": 0 "to_port": 0
}, },
{ {
"from": "bricks", "from": "bricks",
"from_port": 1, "from_port": 1,
"to": "_2_2_2_2", "to": "mwf_create_map",
"to_port": 1 "to_port": 1
}, },
{ {
"from": "blend", "from": "mwf_create_map",
"from_port": 0, "from_port": 0,
"to": "_2_2_2_2", "to": "gen_outputs",
"to_port": 0 "to_port": 0
} }
], ],
@ -371,7 +374,7 @@
"y": -369.233337 "y": -369.233337
}, },
"parameters": { "parameters": {
"steps": 6
}, },
"type": "invert" "type": "invert"
}, },
@ -484,67 +487,6 @@
} }
] ]
}, },
{
"name": "_2_2_2_2",
"node_position": {
"x": -467.634766,
"y": -373.905029
},
"parameters": {
"angle": 0,
"height": 1
},
"seed_value": -41854,
"shader_model": {
"code": "",
"global": "",
"inputs": [
{
"default": "0.0",
"label": "",
"name": "in",
"type": "f"
},
{
"default": "0.0",
"label": "",
"name": "rand",
"type": "f"
}
],
"instance": "",
"name": "Create Map",
"outputs": [
{
"rgb": "vec3($height*$in($uv), $angle*0.01745329251, rand(vec2($seed.0+$rand($uv))))",
"type": "rgb"
}
],
"parameters": [
{
"control": "None",
"default": 1,
"label": "Height",
"max": 1,
"min": 0,
"name": "height",
"step": 0.01,
"type": "float"
},
{
"control": "None",
"default": 0,
"label": "Angle",
"max": 180,
"min": -180,
"name": "angle",
"step": 0.1,
"type": "float"
}
]
},
"type": "shader"
},
{ {
"name": "uniform_greyscale_2", "name": "uniform_greyscale_2",
"node_position": { "node_position": {
@ -555,6 +497,18 @@
"color": 1 "color": 1
}, },
"type": "uniform_greyscale" "type": "uniform_greyscale"
},
{
"name": "mwf_create_map",
"node_position": {
"x": -497.801086,
"y": -339.560547
},
"parameters": {
"angle": 0,
"height": 1
},
"type": "mwf_create_map"
} }
], ],
"parameters": { "parameters": {
@ -609,14 +563,7 @@
"y": -230.983337 "y": -230.983337
}, },
"parameters": { "parameters": {
"color": {
"a": 1,
"b": 1,
"g": 1,
"r": 1,
"type": "Color"
},
"name": 0
}, },
"type": "combine" "type": "combine"
}, },
@ -1108,14 +1055,7 @@
"y": 39.197388 "y": 39.197388
}, },
"parameters": { "parameters": {
"color": {
"a": 1,
"b": 1,
"g": 1,
"r": 1,
"type": "Color"
},
"name": 0
}, },
"type": "combine" "type": "combine"
}, },
@ -1137,13 +1077,10 @@
"y": 186.780701 "y": 186.780701
}, },
"parameters": { "parameters": {
"amount": 0.5,
"param0": 11, "param0": 11,
"param1": 2, "param1": 2,
"param2": 0, "param2": 0,
"param3": 0, "param4": 0
"param4": 0,
"size": 4
}, },
"type": "normal_map" "type": "normal_map"
}, },
@ -1171,7 +1108,6 @@
"y": 149.637848 "y": 149.637848
}, },
"parameters": { "parameters": {
"Randomness": 0.5,
"angle": -1, "angle": -1,
"layers": 10, "layers": 10,
"length": 0.05, "length": 0.05,
@ -1784,14 +1720,7 @@
"y": 39.197388 "y": 39.197388
}, },
"parameters": { "parameters": {
"color": {
"a": 1,
"b": 1,
"g": 1,
"r": 1,
"type": "Color"
},
"name": 0
}, },
"type": "combine" "type": "combine"
}, },
@ -1813,13 +1742,10 @@
"y": 186.780701 "y": 186.780701
}, },
"parameters": { "parameters": {
"amount": 0.5,
"param0": 11, "param0": 11,
"param1": 2, "param1": 2,
"param2": 0, "param2": 0,
"param3": 0, "param4": 0
"param4": 0,
"size": 4
}, },
"type": "normal_map" "type": "normal_map"
}, },
@ -1847,7 +1773,6 @@
"y": 149.637848 "y": 149.637848
}, },
"parameters": { "parameters": {
"Randomness": 0.5,
"angle": -1, "angle": -1,
"layers": 10, "layers": 10,
"length": 0.05, "length": 0.05,
@ -2129,7 +2054,6 @@
}, },
"parameters": { "parameters": {
"param0": 1, "param0": 1,
"param1": 10,
"param2": 1 "param2": 1
}, },
"type": "mwf_output" "type": "mwf_output"

View File

@ -153,6 +153,9 @@
}, },
"nodes": [ "nodes": [
{ {
"export_paths": {
},
"name": "Material", "name": "Material",
"node_position": { "node_position": {
"x": 12, "x": 12,
@ -166,14 +169,14 @@
"r": 1, "r": 1,
"type": "Color" "type": "Color"
}, },
"ao_light_affect": 1, "ao": 1,
"depth_scale": 1, "depth_scale": 1,
"emission_energy": 1, "emission_energy": 1,
"metallic": 1, "metallic": 1,
"normal_scale": 1, "normal": 1,
"roughness": 1, "roughness": 1,
"size": 11, "size": 11,
"subsurf_scatter_strength": 0 "sss": 0
}, },
"type": "material" "type": "material"
}, },
@ -2187,7 +2190,7 @@
"parameters": { "parameters": {
"choices": 3, "choices": 3,
"outputs": 4, "outputs": 4,
"source": 0 "source": 2
}, },
"type": "switch" "type": "switch"
}, },

View File

@ -2,6 +2,7 @@
[ext_resource path="res://material_maker/main_window.gd" type="Script" id=1] [ext_resource path="res://material_maker/main_window.gd" type="Script" id=1]
[ext_resource path="res://material_maker/main_window_layout.gd" type="Script" id=2] [ext_resource path="res://material_maker/main_window_layout.gd" type="Script" id=2]
[ext_resource path="res://material_maker/preview/preview_2d.tscn" type="PackedScene" id=3]
[ext_resource path="res://material_maker/preview/preview_3d.tscn" type="PackedScene" id=4] [ext_resource path="res://material_maker/preview/preview_3d.tscn" type="PackedScene" id=4]
[ext_resource path="res://material_maker/preview/preview_3d_ui.tscn" type="PackedScene" id=5] [ext_resource path="res://material_maker/preview/preview_3d_ui.tscn" type="PackedScene" id=5]
[ext_resource path="res://material_maker/widgets/tabs.gd" type="Script" id=6] [ext_resource path="res://material_maker/widgets/tabs.gd" type="Script" id=6]
@ -9,27 +10,13 @@
[ext_resource path="res://material_maker/icons/icons.svg" type="Texture" id=8] [ext_resource path="res://material_maker/icons/icons.svg" type="Texture" id=8]
[ext_resource path="res://material_maker/node_factory.gd" type="Script" id=9] [ext_resource path="res://material_maker/node_factory.gd" type="Script" id=9]
[ext_resource path="res://material_maker/theme/default.tres" type="Theme" id=10] [ext_resource path="res://material_maker/theme/default.tres" type="Theme" id=10]
[ext_resource path="res://material_maker/preview/preview_2d.gd" type="Script" id=11]
[sub_resource type="Shader" id=1] [sub_resource type="Shader" id=1]
code = "shader_type canvas_item; resource_local_to_scene = true
uniform sampler2D tex;
uniform vec2 size;
void fragment() {
float ms = max(size.x, size.y);
vec2 uv = fract(0.5+1.2*(UV-vec2(0.5))*ms/size.yx);
vec2 m2 = min(fract(uv), 1.0-fract(uv));
vec4 image = texture(tex, uv);
vec3 image_with_background = mix(vec3(mod(floor(uv.x*32.0)+floor(uv.y*32.0), 2.0)), image.xyz, image.a);
float lines_color = 0.5*(cos(5.0*TIME+100.0*(UV.x+UV.y))+1.0);
COLOR = vec4(mix(image_with_background, vec3(lines_color), step(min(m2.x*size.x, m2.y*size.y), 1.0)), 1.0);
}"
[sub_resource type="ShaderMaterial" id=2] [sub_resource type="ShaderMaterial" id=2]
resource_local_to_scene = true
shader = SubResource( 1 ) shader = SubResource( 1 )
shader_param/size = Vector2( 947, 682 )
[sub_resource type="AtlasTexture" id=3] [sub_resource type="AtlasTexture" id=3]
flags = 4 flags = 4
@ -127,20 +114,11 @@ size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
size_flags_stretch_ratio = 3.0 size_flags_stretch_ratio = 3.0
[node name="Preview2D" type="ColorRect" parent="VBoxContainer/Layout/SplitRight/ProjectsPane"] [node name="Preview2D" parent="VBoxContainer/Layout/SplitRight/ProjectsPane" instance=ExtResource( 3 )]
visible = false visible = false
material = SubResource( 2 ) material = SubResource( 2 )
anchor_right = 1.0 margin_right = 0.0
anchor_bottom = 1.0 margin_bottom = 0.0
rect_min_size = Vector2( 64, 64 )
rect_clip_content = true
mouse_filter = 1
size_flags_horizontal = 0
size_flags_vertical = 8
script = ExtResource( 11 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Preview3D" parent="VBoxContainer/Layout/SplitRight/ProjectsPane" instance=ExtResource( 4 )] [node name="Preview3D" parent="VBoxContainer/Layout/SplitRight/ProjectsPane" instance=ExtResource( 4 )]
margin_left = 0.0 margin_left = 0.0
@ -269,7 +247,6 @@ script = ExtResource( 9 )
[connection signal="tab_changed" from="VBoxContainer/Layout/Left/Top" to="VBoxContainer/Layout" method="_on_tab_changed"] [connection signal="tab_changed" from="VBoxContainer/Layout/Left/Top" to="VBoxContainer/Layout" method="_on_tab_changed"]
[connection signal="tab_changed" from="VBoxContainer/Layout/Left/Bottom" to="VBoxContainer/Layout" method="_on_tab_changed"] [connection signal="tab_changed" from="VBoxContainer/Layout/Left/Bottom" to="VBoxContainer/Layout" method="_on_tab_changed"]
[connection signal="dragged" from="VBoxContainer/Layout/SplitRight" to="VBoxContainer/Layout" method="_on_Right_dragged"] [connection signal="dragged" from="VBoxContainer/Layout/SplitRight" to="VBoxContainer/Layout" method="_on_Right_dragged"]
[connection signal="resized" from="VBoxContainer/Layout/SplitRight/ProjectsPane/Preview2D" to="VBoxContainer/Layout/SplitRight/ProjectsPane/Preview2D" method="on_resized"]
[connection signal="need_update" from="VBoxContainer/Layout/SplitRight/ProjectsPane/Preview3D" to="." method="update_preview_3d"] [connection signal="need_update" from="VBoxContainer/Layout/SplitRight/ProjectsPane/Preview3D" to="." method="update_preview_3d"]
[connection signal="no_more_tabs" from="VBoxContainer/Layout/SplitRight/ProjectsPane/Projects" to="." method="new_material"] [connection signal="no_more_tabs" from="VBoxContainer/Layout/SplitRight/ProjectsPane/Projects" to="." method="new_material"]
[connection signal="resized" from="VBoxContainer/Layout/SplitRight/ProjectsPane/Projects" to="VBoxContainer/Layout/SplitRight/ProjectsPane/Projects" method="_on_Projects_resized"] [connection signal="resized" from="VBoxContainer/Layout/SplitRight/ProjectsPane/Projects" to="VBoxContainer/Layout/SplitRight/ProjectsPane/Projects" method="_on_Projects_resized"]

View File

@ -48,7 +48,6 @@ func update_node() -> void:
sizer.add_child(control) sizer.add_child(control)
control.connect("value_changed", self, "_on_value_changed", [ l.name ]) control.connect("value_changed", self, "_on_value_changed", [ l.name ])
controls[l.name] = control controls[l.name] = control
sizer.add_child(preload("res://material_maker/widgets/preview_button.tscn").instance())
add_child(sizer) add_child(sizer)
else: else:
# Keep lines with controls # Keep lines with controls
@ -64,22 +63,12 @@ func update_node() -> void:
var sizer = HBoxContainer.new() var sizer = HBoxContainer.new()
var input_label = Label.new() var input_label = Label.new()
sizer.add_child(input_label) sizer.add_child(input_label)
if get_child_count() < 5:
var space = Control.new()
space.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL
sizer.add_child(space)
var button = preload("res://material_maker/widgets/preview_button.tscn").instance()
sizer.add_child(button)
button.connect("toggled", self, "on_preview_button", [ get_child_count()-1 ])
add_child(sizer) add_child(sizer)
rect_size = Vector2(0, 0) rect_size = Vector2(0, 0)
for i in range(get_child_count()): for i in range(get_child_count()):
var sizer = get_child(i) var sizer = get_child(i)
var has_input = true var has_input = true
var has_output = false var has_output = i < output_count
if i < 5:
has_output = i < output_count
sizer.get_child(sizer.get_child_count()-1).visible = has_output
if i >= input_count: if i >= input_count:
sizer.get_child(0).text = "" sizer.get_child(0).text = ""
has_input = false has_input = false

View File

@ -3,11 +3,16 @@ extends ColorRect
export(String, MULTILINE) var shader : String = "" export(String, MULTILINE) var shader : String = ""
var generator : MMGenBase = null var generator : MMGenBase = null
var output : int = 0
func set_generator(g : MMGenBase, output : int = 0) -> void: func set_generator(g : MMGenBase, o : int = 0) -> void:
if is_instance_valid(generator):
generator.disconnect("parameter_changed", self, "on_parameter_changed")
var source = { defs="", code="", textures={}, type="f", f="1.0" } var source = { defs="", code="", textures={}, type="f", f="1.0" }
if is_instance_valid(g): if is_instance_valid(g):
generator = g generator = g
output = o
generator.connect("parameter_changed", self, "on_parameter_changed")
var param_defs : Array = generator.get_parameter_defs() var param_defs : Array = generator.get_parameter_defs()
for c in get_children(): for c in get_children():
c.setup_control(generator, param_defs) c.setup_control(generator, param_defs)
@ -35,6 +40,15 @@ func set_generator(g : MMGenBase, output : int = 0) -> void:
for k in source.textures.keys(): for k in source.textures.keys():
material.set_shader_param(k, source.textures[k]) material.set_shader_param(k, source.textures[k])
func on_parameter_changed(n : String, v) -> void:
var p = generator.get_parameter_def(n)
if p.has("type"):
match p.type:
"float":
pass
_:
set_generator(generator, output)
func on_float_parameter_changed(n : String, v : float) -> void: func on_float_parameter_changed(n : String, v : float) -> void:
for p in VisualServer.shader_get_param_list(material.shader.get_rid()): for p in VisualServer.shader_get_param_list(material.shader.get_rid()):
if p.name == n: if p.name == n: