mirror of
https://github.com/Relintai/material-maker.git
synced 2024-11-13 06:27:18 +01:00
Rewrote pattern, uniform and voronoi nodes using generic node.
This commit is contained in:
parent
0a4e84ec06
commit
ade213921c
@ -13,51 +13,6 @@ vec3 rand3(vec2 x) {
|
|||||||
dot(x, vec2(13.254, 5.867)))) * 43758.5453);
|
dot(x, vec2(13.254, 5.867)))) * 43758.5453);
|
||||||
}
|
}
|
||||||
|
|
||||||
float wave_constant(float x) {
|
|
||||||
return 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
float wave_sin(float x) {
|
|
||||||
return 0.5-0.5*cos(3.14159265359*2.0*x);
|
|
||||||
}
|
|
||||||
|
|
||||||
float wave_triangle(float x) {
|
|
||||||
x = fract(x);
|
|
||||||
return min(2.0*x, 2.0-2.0*x);
|
|
||||||
}
|
|
||||||
|
|
||||||
float wave_square(float x) {
|
|
||||||
return (fract(x) < 0.5) ? 0.0 : 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
float mix_multiply(float x, float y) {
|
|
||||||
return x*y;
|
|
||||||
}
|
|
||||||
|
|
||||||
float mix_add(float x, float y) {
|
|
||||||
return min(x+y, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
float mix_max(float x, float y) {
|
|
||||||
return max(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
float mix_min(float x, float y) {
|
|
||||||
return min(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
float mix_min(float x, float y) {
|
|
||||||
return min(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
float mix_xor(float x, float y) {
|
|
||||||
return min(x+y, 2.0-x-y);
|
|
||||||
}
|
|
||||||
|
|
||||||
float mix_pow(float x, float y) {
|
|
||||||
return pow(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 blend_normal(vec2 uv, vec3 c1, vec3 c2, float opacity) {
|
vec3 blend_normal(vec2 uv, vec3 c1, vec3 c2, float opacity) {
|
||||||
return opacity*c1 + (1.0-opacity)*c2;
|
return opacity*c1 + (1.0-opacity)*c2;
|
||||||
}
|
}
|
||||||
@ -145,36 +100,6 @@ vec2 transform_norepeat(vec2 uv, vec2 translate, float rotate, vec2 scale) {
|
|||||||
return clamp(transform(uv, translate, rotate, scale), vec2(0.0), vec2(1.0));
|
return clamp(transform(uv, translate, rotate, scale), vec2(0.0), vec2(1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 voronoi(vec2 uv, vec2 size, float intensity, int seed) {
|
|
||||||
vec2 seed2 = rand2(vec2(float(seed), 1.0-float(seed)));
|
|
||||||
uv *= size;
|
|
||||||
float best_distance0 = 1.0;
|
|
||||||
float best_distance1 = 1.0;
|
|
||||||
vec2 point0;
|
|
||||||
vec2 point1;
|
|
||||||
vec2 p0 = floor(uv);
|
|
||||||
for (int dx = -1; dx < 2; ++dx) {
|
|
||||||
for (int dy = -1; dy < 2; ++dy) {
|
|
||||||
vec2 d = vec2(float(dx), float(dy));
|
|
||||||
vec2 p = p0+d;
|
|
||||||
p += rand2(seed2+mod(p, size));
|
|
||||||
float distance = length((uv - p) / size);
|
|
||||||
if (best_distance0 > distance) {
|
|
||||||
best_distance1 = best_distance0;
|
|
||||||
best_distance0 = distance;
|
|
||||||
point1 = point0;
|
|
||||||
point0 = p;
|
|
||||||
} else if (best_distance1 > distance) {
|
|
||||||
best_distance1 = distance;
|
|
||||||
point1 = p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
float edge_distance = dot(uv - 0.5*(point0+point1), normalize(point0-point1));
|
|
||||||
|
|
||||||
return vec4(point0, best_distance0*length(size)*intensity, edge_distance);
|
|
||||||
}
|
|
||||||
|
|
||||||
// From http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl
|
// From http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl
|
||||||
vec3 rgb2hsv(vec3 c) {
|
vec3 rgb2hsv(vec3 c) {
|
||||||
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
||||||
|
@ -52,6 +52,7 @@ func update_node(data):
|
|||||||
uses_seed = true
|
uses_seed = true
|
||||||
if model_data.has("parameters") and typeof(model_data.parameters) == TYPE_ARRAY:
|
if model_data.has("parameters") and typeof(model_data.parameters) == TYPE_ARRAY:
|
||||||
var control_list = []
|
var control_list = []
|
||||||
|
var sizer = null
|
||||||
for p in model_data.parameters:
|
for p in model_data.parameters:
|
||||||
if !p.has("name") or !p.has("type"):
|
if !p.has("name") or !p.has("type"):
|
||||||
continue
|
continue
|
||||||
@ -64,6 +65,8 @@ func update_node(data):
|
|||||||
control.min_value = p.min
|
control.min_value = p.min
|
||||||
control.max_value = p.max
|
control.max_value = p.max
|
||||||
control.step = 0 if !p.has("step") else p.step
|
control.step = 0 if !p.has("step") else p.step
|
||||||
|
if p.has("default"):
|
||||||
|
control.value = p.default
|
||||||
control.rect_min_size.x = 80
|
control.rect_min_size.x = 80
|
||||||
parameters[p.name] = 0.5*(p.min+p.max)
|
parameters[p.name] = 0.5*(p.min+p.max)
|
||||||
elif p.type == "size":
|
elif p.type == "size":
|
||||||
@ -86,18 +89,19 @@ func update_node(data):
|
|||||||
var label = p.name
|
var label = p.name
|
||||||
control.name = label
|
control.name = label
|
||||||
control_list.append(control)
|
control_list.append(control)
|
||||||
var sizer = HBoxContainer.new()
|
|
||||||
sizer.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL
|
|
||||||
if p.has("label"):
|
if p.has("label"):
|
||||||
label = p.label
|
label = p.label
|
||||||
if label != "":
|
if sizer == null or label != "nonewline":
|
||||||
|
sizer = HBoxContainer.new()
|
||||||
|
sizer.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL
|
||||||
|
add_child(sizer)
|
||||||
|
if label != "" && label != "nonewline":
|
||||||
var label_widget = Label.new()
|
var label_widget = Label.new()
|
||||||
label_widget.text = label
|
label_widget.text = label
|
||||||
label_widget.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL
|
label_widget.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL
|
||||||
sizer.add_child(label_widget)
|
sizer.add_child(label_widget)
|
||||||
control.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL
|
control.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL
|
||||||
sizer.add_child(control)
|
sizer.add_child(control)
|
||||||
add_child(sizer)
|
|
||||||
initialize_properties(control_list)
|
initialize_properties(control_list)
|
||||||
else:
|
else:
|
||||||
model_data.parameters = []
|
model_data.parameters = []
|
||||||
|
1
addons/material_maker/nodes/pattern.mmn
Normal file
1
addons/material_maker/nodes/pattern.mmn
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"global":"float wave_constant(float x) {\n\treturn 1.0;\n}\n\nfloat wave_sine(float x) {\n\treturn 0.5-0.5*cos(3.14159265359*2.0*x);\n}\n\nfloat wave_triangle(float x) {\n\tx = fract(x);\n\treturn min(2.0*x, 2.0-2.0*x);\n}\n\nfloat wave_sawtooth(float x) {\n\treturn fract(x);\n}\n\nfloat wave_square(float x) {\n\treturn (fract(x) < 0.5) ? 0.0 : 1.0;\n}\n\nfloat mix_mul(float x, float y) {\n\treturn x*y;\n}\n\nfloat mix_add(float x, float y) {\n\treturn min(x+y, 1.0);\n}\n\nfloat mix_max(float x, float y) {\n\treturn max(x, y);\n}\n\nfloat mix_min(float x, float y) {\n\treturn min(x, y);\n}\n\nfloat mix_xor(float x, float y) {\n\treturn min(x+y, 2.0-x-y);\n}\n\nfloat mix_pow(float x, float y) {\n\treturn pow(x, y);\n}","instance":"float $(name)_fct(vec2 uv) {\n\treturn mix_$(mix)(wave_$(x_wave)($(x_scale)*uv.x), wave_$(y_wave)($(y_scale)*uv.y));\n}","name":"Pattern","outputs":[{"f":"$(name)_fct($(uv))"}],"parameters":[{"default":0,"label":"Combiner","name":"mix","type":"enum","values":[{"name":"Multiply","value":"mul"},{"name":"Add","value":"add"},{"name":"Max","value":"max"},{"name":"Min","value":"min"},{"name":"Xor","value":"xor"},{"name":"Pow","value":"pow"}]},{"default":0,"label":"X","name":"x_wave","type":"enum","values":[{"name":"Sine","value":"sine"},{"name":"Triangle","value":"triangle"},{"name":"Square","value":"square"},{"name":"Sawtooth","value":"sawtooth"},{"name":"Constant","value":"constant"}]},{"default":4,"label":"nonewline","max":32,"min":0,"name":"x_scale","step":1,"type":"float","widget":"spinbox"},{"default":0,"label":"Y","name":"y_wave","type":"enum","values":[{"name":"Sine","value":"sine"},{"name":"Triangle","value":"triangle"},{"name":"Square","value":"square"},{"name":"Sawtooth","value":"sawtooth"},{"name":"Constant","value":"constant"}]},{"default":4,"label":"nonewline","max":32,"min":0,"name":"y_scale","step":1,"type":"float","widget":"spinbox"}]}
|
1
addons/material_maker/nodes/uniform.mmn
Normal file
1
addons/material_maker/nodes/uniform.mmn
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"global":"","instance":"","name":"Uniform","outputs":[{"rgba":"$(color)"}],"parameters":[{"default":{"a":1,"b":1,"g":1,"r":1},"label":"","name":"color","type":"color"}]}
|
1
addons/material_maker/nodes/voronoi.mmn
Normal file
1
addons/material_maker/nodes/voronoi.mmn
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"global":"vec4 voronoi(vec2 uv, vec2 size, float intensity, int seed) {\n\tvec2 seed2 = rand2(vec2(float(seed), 1.0-float(seed)));\n uv *= size;\n float best_distance0 = 1.0;\n float best_distance1 = 1.0;\n vec2 point0;\n vec2 point1;\n vec2 p0 = floor(uv);\n for (int dx = -1; dx < 2; ++dx) {\n \tfor (int dy = -1; dy < 2; ++dy) {\n vec2 d = vec2(float(dx), float(dy));\n vec2 p = p0+d;\n p += rand2(seed2+mod(p, size));\n float distance = length((uv - p) / size);\n if (best_distance0 > distance) {\n \tbest_distance1 = best_distance0;\n \tbest_distance0 = distance;\n point1 = point0;\n point0 = p;\n } else if (best_distance1 > distance) {\n \tbest_distance1 = distance;\n point1 = p;\n }\n }\n }\n float edge_distance = dot(uv - 0.5*(point0+point1), normalize(point0-point1));\n \n return vec4(point0, best_distance0*length(size)*intensity, edge_distance);\n}\n","instance":"","name":"Voronoi","outputs":[{"f":"voronoi($(uv), vec2($(scale_x), $(scale_y)), $(intensity), $(seed)).z"},{"f":"voronoi($(uv), vec2($(scale_x), $(scale_y)), $(intensity), $(seed)).w"},{"rgb":"rand3(fract(voronoi($(uv), vec2($(scale_x), $(scale_y)), $(intensity), $(seed)).xy))"}],"parameters":[{"default":4,"label":"Scale X","max":32,"min":1,"name":"scale_x","step":1,"type":"float","widget":"spinbox"},{"default":4,"label":"Scale Y","max":32,"min":1,"name":"scale_y","step":1,"type":"float","widget":"spinbox"},{"default":0.5,"label":"Intensity","max":1,"min":0,"name":"intensity","step":0.05,"type":"float","widget":"spinbox"}]}
|
Loading…
Reference in New Issue
Block a user