mirror of
https://github.com/Relintai/material-maker.git
synced 2024-11-13 06:27:18 +01:00
Updates in transform and voronoi, and compatibility fix
- Fixed compatibility with v0.5 files - Added a randomness parameter to voronoi - Changed tranform order (translate applies first so rotate and scale are relative to the center of the source)
This commit is contained in:
parent
19b9d804b9
commit
8006f07e04
@ -38,16 +38,18 @@ func get_parameter_defs():
|
||||
i += 1
|
||||
"linked_control":
|
||||
var linked = w.linked_widgets[0]
|
||||
var gen = get_parent().get_node(linked.node)
|
||||
if gen != null:
|
||||
var gen_params = gen.get_parameter_defs()
|
||||
for pd in gen_params:
|
||||
if pd.name == linked.widget:
|
||||
var p = pd.duplicate(true)
|
||||
p.name = "param"+str(i)
|
||||
p.label = w.label
|
||||
rv.append(p)
|
||||
break
|
||||
var p = {}
|
||||
if linked != null && is_inside_tree():
|
||||
var gen = get_parent().get_node(linked.node)
|
||||
if gen != null:
|
||||
var gen_params = gen.get_parameter_defs()
|
||||
for pd in gen_params:
|
||||
if pd.name == linked.widget:
|
||||
p = pd.duplicate(true)
|
||||
break
|
||||
p.name = "param"+str(i)
|
||||
p.label = w.label
|
||||
rv.append(p)
|
||||
i += 1
|
||||
_:
|
||||
print(w.type)
|
||||
|
@ -4,6 +4,12 @@ class_name MMGenLoader
|
||||
|
||||
const STD_GENDEF_PATH = "res://addons/material_maker/nodes"
|
||||
|
||||
static func generator_name_from_path(path : String) -> String:
|
||||
for p in [ STD_GENDEF_PATH, OS.get_executable_path().get_base_dir()+"/generators" ]:
|
||||
print(p)
|
||||
print(path.get_base_dir())
|
||||
return path.get_basename().get_file()
|
||||
|
||||
static func load_gen(filename: String) -> MMGenBase:
|
||||
var file = File.new()
|
||||
if file.open(filename, File.READ) == OK:
|
||||
@ -104,6 +110,10 @@ static func create_gen(data) -> MMGenBase:
|
||||
if data.has("parameters"):
|
||||
for p in data.parameters.keys():
|
||||
generator.parameters[p] = MMType.deserialize_value(data.parameters[p])
|
||||
else:
|
||||
for p in generator.get_parameter_defs():
|
||||
if data.has(p.name):
|
||||
generator.parameters[p.name] = MMType.deserialize_value(data[p.name])
|
||||
return generator
|
||||
|
||||
static func get_generator_list() -> Array:
|
||||
|
@ -13,6 +13,6 @@ func create_node(type):
|
||||
var node_type = load(file_name)
|
||||
if node_type != null:
|
||||
node = node_type.instance()
|
||||
else:
|
||||
if node == null:
|
||||
node = preload("res://addons/material_maker/nodes/generic.tscn").instance()
|
||||
return node
|
||||
|
@ -321,9 +321,9 @@ func do_load_generator(file_name : String):
|
||||
else:
|
||||
new_generator = MMGenLoader.load_gen(file_name)
|
||||
if new_generator != null:
|
||||
var gen_name = MMGenLoader.generator_from_path(file_name)
|
||||
var gen_name = MMGenLoader.generator_name_from_path(file_name)
|
||||
if gen_name != "":
|
||||
new_generator.type = gen_name
|
||||
new_generator.model = gen_name
|
||||
var parent_generator = generator.get_parent()
|
||||
parent_generator.replace_generator(generator, new_generator)
|
||||
generator = new_generator
|
||||
|
@ -1,182 +0,0 @@
|
||||
tool
|
||||
extends "res://addons/material_maker/node_base.gd"
|
||||
|
||||
var generator = null
|
||||
|
||||
var texture_list
|
||||
|
||||
var current_material_list = []
|
||||
var generated_textures = {}
|
||||
|
||||
const TEXTURE_LIST = [
|
||||
{ port=0, texture="albedo" },
|
||||
{ port=1, texture="metallic" },
|
||||
{ port=2, texture="roughness" },
|
||||
{ port=3, texture="emission" },
|
||||
{ port=4, texture="normal_map" },
|
||||
{ port=5, texture="ambient_occlusion" },
|
||||
{ port=6, texture="depth_map" }
|
||||
]
|
||||
|
||||
const ADDON_TEXTURE_LIST = [
|
||||
{ port=0, texture="albedo" },
|
||||
{ port=3, texture="emission" },
|
||||
{ port=4, texture="normal_map" },
|
||||
{ ports=[1, 2, 5], default_values=["0.0", "1.0", "1.0"], texture="mrao" },
|
||||
{ port=6, texture="depth_map" }
|
||||
]
|
||||
|
||||
func _ready():
|
||||
texture_list = TEXTURE_LIST
|
||||
if Engine.editor_hint:
|
||||
texture_list = ADDON_TEXTURE_LIST
|
||||
for t in texture_list:
|
||||
generated_textures[t.texture] = { shader=null, source=null, texture=null }
|
||||
initialize_properties([ $resolution, $Albedo/albedo_color, $Metallic/metallic, $Roughness/roughness, $Emission/emission_energy, $NormalMap/normal_scale, $AmbientOcclusion/ao_light_affect, $DepthMap/depth_scale ])
|
||||
|
||||
func _rerender():
|
||||
var size = int(pow(2, 8+parameters.resolution))
|
||||
var has_textures = false
|
||||
for t in texture_list:
|
||||
var shader = generated_textures[t.texture].shader
|
||||
if shader != null:
|
||||
var input_textures = {}
|
||||
for s in generated_textures[t.texture].sources:
|
||||
var source_textures = s.get_textures()
|
||||
for st in source_textures.keys():
|
||||
input_textures[st] = source_textures[st]
|
||||
get_parent().renderer.precalculate_shader(shader, input_textures, size, generated_textures[t.texture].texture, self, "do_update_materials", [ current_material_list ])
|
||||
has_textures = true
|
||||
if !has_textures:
|
||||
do_update_materials(current_material_list)
|
||||
|
||||
func _get_shader_code(uv, slot = 0):
|
||||
var rv = { defs="", code="", f="0.0" }
|
||||
var src = get_source()
|
||||
if src != null:
|
||||
rv = src.get_shader_code(uv)
|
||||
return rv
|
||||
|
||||
func update_materials(material_list):
|
||||
current_material_list = material_list
|
||||
var has_textures = false
|
||||
for t in texture_list:
|
||||
var shader = null
|
||||
var sources = []
|
||||
if t.has("port"):
|
||||
var source = get_source(t.port)
|
||||
if source != null:
|
||||
shader = source.generate_shader()
|
||||
sources.append(source)
|
||||
elif t.has("ports"):
|
||||
var source = [ null, null, null ]
|
||||
generated_textures[t.texture].mask = 0
|
||||
for i in range(3):
|
||||
source[i] = get_source(t.ports[i])
|
||||
if source[i] != null:
|
||||
sources.append(source[i])
|
||||
generated_textures[t.texture].mask |= 1 << i
|
||||
if !sources.empty():
|
||||
for c in get_parent().get_children():
|
||||
if c is GraphNode:
|
||||
c.reset()
|
||||
var source_code = [ null, null, null ]
|
||||
for i in range(3):
|
||||
if source[i] != null:
|
||||
source_code[i] = source[i].get_shader_code_with_globals("UV")
|
||||
else:
|
||||
source_code[i] = { defs="", code="", f=t.default_values[i] }
|
||||
shader = get_parent().renderer.generate_combined_shader(source_code[0], source_code[1], source_code[2])
|
||||
generated_textures[t.texture].shader = shader
|
||||
generated_textures[t.texture].sources = sources
|
||||
if shader == null:
|
||||
if generated_textures[t.texture].texture != null:
|
||||
generated_textures[t.texture].texture = null
|
||||
else:
|
||||
if generated_textures[t.texture].texture == null:
|
||||
generated_textures[t.texture].texture = ImageTexture.new()
|
||||
_rerender()
|
||||
|
||||
func get_generated_texture(slot, file_prefix = null):
|
||||
if file_prefix != null:
|
||||
var file_name = "%s_%s.png" % [ file_prefix, slot ]
|
||||
if File.new().file_exists(file_name):
|
||||
return load(file_name)
|
||||
else:
|
||||
return null
|
||||
else:
|
||||
return generated_textures[slot].texture
|
||||
|
||||
func update_spatial_material(m, file_prefix = null):
|
||||
var texture
|
||||
m.albedo_color = parameters.albedo_color
|
||||
m.albedo_texture = get_generated_texture("albedo", file_prefix)
|
||||
m.metallic = parameters.metallic
|
||||
m.roughness = parameters.roughness
|
||||
if Engine.editor_hint:
|
||||
texture = get_generated_texture("mrao", file_prefix)
|
||||
m.metallic_texture = texture
|
||||
m.metallic_texture_channel = SpatialMaterial.TEXTURE_CHANNEL_RED
|
||||
m.roughness_texture = texture
|
||||
m.roughness_texture_channel = SpatialMaterial.TEXTURE_CHANNEL_GREEN
|
||||
else:
|
||||
m.metallic_texture = get_generated_texture("metallic", file_prefix)
|
||||
m.roughness_texture = get_generated_texture("roughness", file_prefix)
|
||||
texture = get_generated_texture("emission", file_prefix)
|
||||
if texture != null:
|
||||
m.emission_enabled = true
|
||||
m.emission_energy = parameters.emission_energy
|
||||
m.emission_texture = texture
|
||||
else:
|
||||
m.emission_enabled = false
|
||||
texture = get_generated_texture("normal_map", file_prefix)
|
||||
if texture != null:
|
||||
m.normal_enabled = true
|
||||
m.normal_texture = texture
|
||||
else:
|
||||
m.normal_enabled = false
|
||||
if Engine.editor_hint:
|
||||
if (generated_textures.mrao.mask & (1 << 2)) != 0:
|
||||
m.ao_enabled = true
|
||||
m.ao_light_affect = parameters.ao_light_affect
|
||||
m.ao_texture = m.metallic_texture
|
||||
m.ao_texture_channel = SpatialMaterial.TEXTURE_CHANNEL_BLUE
|
||||
else:
|
||||
m.ao_enabled = false
|
||||
else:
|
||||
texture = get_generated_texture("ambient_occlusion", file_prefix)
|
||||
if texture != null:
|
||||
m.ao_enabled = true
|
||||
m.ao_light_affect = parameters.ao_light_affect
|
||||
m.ao_texture = texture
|
||||
else:
|
||||
m.ao_enabled = false
|
||||
texture = get_generated_texture("depth_map", file_prefix)
|
||||
if texture != null:
|
||||
m.depth_enabled = true
|
||||
m.depth_scale = parameters.depth_scale
|
||||
m.depth_texture = texture
|
||||
else:
|
||||
m.depth_enabled = false
|
||||
|
||||
func do_update_materials(material_list):
|
||||
for m in material_list:
|
||||
if m is SpatialMaterial:
|
||||
update_spatial_material(m)
|
||||
|
||||
func export_textures(prefix, size = null):
|
||||
if size == null:
|
||||
size = int(pow(2, 8+parameters.resolution))
|
||||
for t in texture_list:
|
||||
var texture = generated_textures[t.texture].texture
|
||||
if texture != null:
|
||||
var image = texture.get_data()
|
||||
image.save_png("%s_%s.png" % [ prefix, t.texture ])
|
||||
if Engine.editor_hint:
|
||||
var resource_filesystem = get_parent().editor_interface.get_resource_filesystem()
|
||||
resource_filesystem.scan()
|
||||
yield(resource_filesystem, "filesystem_changed")
|
||||
var new_material = SpatialMaterial.new()
|
||||
update_spatial_material(new_material, prefix)
|
||||
ResourceSaver.save("%s.tres" % [ prefix ], new_material)
|
||||
resource_filesystem.scan()
|
@ -1,223 +0,0 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://addons/material_maker/nodes/material.gd" type="Script" id=1]
|
||||
|
||||
[sub_resource type="Theme" id=1]
|
||||
|
||||
[node name="Material" type="GraphNode"]
|
||||
margin_right = 230.0
|
||||
margin_bottom = 199.0
|
||||
mouse_filter = 1
|
||||
theme = SubResource( 1 )
|
||||
title = "Material"
|
||||
slot/0/left_enabled = false
|
||||
slot/0/left_type = 0
|
||||
slot/0/left_color = Color( 0.411765, 1, 0.388235, 0.352941 )
|
||||
slot/0/right_enabled = false
|
||||
slot/0/right_type = 0
|
||||
slot/0/right_color = Color( 0.5, 0.5, 1, 1 )
|
||||
slot/1/left_enabled = true
|
||||
slot/1/left_type = 0
|
||||
slot/1/left_color = Color( 0.411765, 1, 0.388235, 0.352941 )
|
||||
slot/1/right_enabled = false
|
||||
slot/1/right_type = 0
|
||||
slot/1/right_color = Color( 0.5, 0.5, 1, 1 )
|
||||
slot/2/left_enabled = true
|
||||
slot/2/left_type = 0
|
||||
slot/2/left_color = Color( 0.756863, 0.756863, 0.756863, 1 )
|
||||
slot/2/right_enabled = false
|
||||
slot/2/right_type = 0
|
||||
slot/2/right_color = Color( 0.5, 0.5, 1, 1 )
|
||||
slot/3/left_enabled = true
|
||||
slot/3/left_type = 0
|
||||
slot/3/left_color = Color( 0.756863, 0.756863, 0.756863, 1 )
|
||||
slot/3/right_enabled = false
|
||||
slot/3/right_type = 0
|
||||
slot/3/right_color = Color( 0.498039, 0.498039, 1, 1 )
|
||||
slot/4/left_enabled = true
|
||||
slot/4/left_type = 0
|
||||
slot/4/left_color = Color( 0.498039, 0.498039, 1, 1 )
|
||||
slot/4/right_enabled = false
|
||||
slot/4/right_type = 0
|
||||
slot/4/right_color = Color( 0.498039, 0.498039, 1, 1 )
|
||||
slot/5/left_enabled = true
|
||||
slot/5/left_type = 0
|
||||
slot/5/left_color = Color( 0.498039, 0.498039, 1, 1 )
|
||||
slot/5/right_enabled = false
|
||||
slot/5/right_type = 0
|
||||
slot/5/right_color = Color( 0.498039, 0.498039, 1, 1 )
|
||||
slot/6/left_enabled = true
|
||||
slot/6/left_type = 0
|
||||
slot/6/left_color = Color( 0.756863, 0.756863, 0.756863, 1 )
|
||||
slot/6/right_enabled = false
|
||||
slot/6/right_type = 0
|
||||
slot/6/right_color = Color( 0.498039, 0.498039, 1, 1 )
|
||||
slot/7/left_enabled = true
|
||||
slot/7/left_type = 0
|
||||
slot/7/left_color = Color( 0.756863, 0.756863, 0.756863, 1 )
|
||||
slot/7/right_enabled = false
|
||||
slot/7/right_type = 0
|
||||
slot/7/right_color = Color( 0.494118, 0.494118, 1, 1 )
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="resolution" type="OptionButton" parent="."]
|
||||
margin_left = 16.0
|
||||
margin_top = 24.0
|
||||
margin_right = 214.0
|
||||
margin_bottom = 44.0
|
||||
text = "512x512"
|
||||
items = [ "256x256", null, false, 0, null, "512x512", null, false, 1, null, "1024x1024", null, false, 2, null, "2048x2048", null, false, -1, null ]
|
||||
selected = 1
|
||||
|
||||
[node name="Albedo" type="HBoxContainer" parent="."]
|
||||
margin_left = 16.0
|
||||
margin_top = 44.0
|
||||
margin_right = 214.0
|
||||
margin_bottom = 64.0
|
||||
|
||||
[node name="Label" type="Label" parent="Albedo"]
|
||||
margin_top = 3.0
|
||||
margin_right = 114.0
|
||||
margin_bottom = 17.0
|
||||
size_flags_horizontal = 3
|
||||
text = "Albedo"
|
||||
|
||||
[node name="albedo_color" type="ColorPickerButton" parent="Albedo"]
|
||||
margin_left = 118.0
|
||||
margin_right = 198.0
|
||||
margin_bottom = 20.0
|
||||
rect_min_size = Vector2( 80, 0 )
|
||||
color = Color( 1, 1, 1, 1 )
|
||||
edit_alpha = false
|
||||
|
||||
[node name="Metallic" type="HBoxContainer" parent="."]
|
||||
editor/display_folded = true
|
||||
margin_left = 16.0
|
||||
margin_top = 65.0
|
||||
margin_right = 214.0
|
||||
margin_bottom = 89.0
|
||||
|
||||
[node name="Label" type="Label" parent="Metallic"]
|
||||
margin_top = 5.0
|
||||
margin_right = 120.0
|
||||
margin_bottom = 19.0
|
||||
size_flags_horizontal = 3
|
||||
text = "Metallic"
|
||||
|
||||
[node name="metallic" type="SpinBox" parent="Metallic"]
|
||||
margin_left = 124.0
|
||||
margin_right = 198.0
|
||||
margin_bottom = 24.0
|
||||
max_value = 1.0
|
||||
step = 0.05
|
||||
value = 1.0
|
||||
|
||||
[node name="Roughness" type="HBoxContainer" parent="."]
|
||||
editor/display_folded = true
|
||||
margin_left = 16.0
|
||||
margin_top = 90.0
|
||||
margin_right = 214.0
|
||||
margin_bottom = 114.0
|
||||
|
||||
[node name="Label" type="Label" parent="Roughness"]
|
||||
margin_top = 5.0
|
||||
margin_right = 120.0
|
||||
margin_bottom = 19.0
|
||||
size_flags_horizontal = 3
|
||||
text = "Roughness"
|
||||
|
||||
[node name="roughness" type="SpinBox" parent="Roughness"]
|
||||
margin_left = 124.0
|
||||
margin_right = 198.0
|
||||
margin_bottom = 24.0
|
||||
max_value = 1.0
|
||||
step = 0.05
|
||||
value = 1.0
|
||||
|
||||
[node name="Emission" type="HBoxContainer" parent="."]
|
||||
editor/display_folded = true
|
||||
margin_left = 16.0
|
||||
margin_top = 115.0
|
||||
margin_right = 214.0
|
||||
margin_bottom = 139.0
|
||||
|
||||
[node name="Label" type="Label" parent="Emission"]
|
||||
margin_top = 5.0
|
||||
margin_right = 120.0
|
||||
margin_bottom = 19.0
|
||||
size_flags_horizontal = 3
|
||||
text = "Emission"
|
||||
|
||||
[node name="emission_energy" type="SpinBox" parent="Emission"]
|
||||
margin_left = 124.0
|
||||
margin_right = 198.0
|
||||
margin_bottom = 24.0
|
||||
max_value = 5.0
|
||||
step = 0.05
|
||||
value = 1.0
|
||||
|
||||
[node name="NormalMap" type="HBoxContainer" parent="."]
|
||||
editor/display_folded = true
|
||||
margin_left = 16.0
|
||||
margin_top = 140.0
|
||||
margin_right = 214.0
|
||||
margin_bottom = 164.0
|
||||
|
||||
[node name="Label" type="Label" parent="NormalMap"]
|
||||
margin_top = 5.0
|
||||
margin_right = 120.0
|
||||
margin_bottom = 19.0
|
||||
size_flags_horizontal = 3
|
||||
text = "Normal map"
|
||||
|
||||
[node name="normal_scale" type="SpinBox" parent="NormalMap"]
|
||||
margin_left = 124.0
|
||||
margin_right = 198.0
|
||||
margin_bottom = 24.0
|
||||
max_value = 5.0
|
||||
step = 0.05
|
||||
value = 1.0
|
||||
|
||||
[node name="AmbientOcclusion" type="HBoxContainer" parent="."]
|
||||
editor/display_folded = true
|
||||
margin_left = 16.0
|
||||
margin_top = 165.0
|
||||
margin_right = 214.0
|
||||
margin_bottom = 189.0
|
||||
|
||||
[node name="Label" type="Label" parent="AmbientOcclusion"]
|
||||
margin_top = 5.0
|
||||
margin_right = 120.0
|
||||
margin_bottom = 19.0
|
||||
size_flags_horizontal = 3
|
||||
text = "Ambient occlusion"
|
||||
|
||||
[node name="ao_light_affect" type="SpinBox" parent="AmbientOcclusion"]
|
||||
margin_left = 124.0
|
||||
margin_right = 198.0
|
||||
margin_bottom = 24.0
|
||||
max_value = 5.0
|
||||
step = 0.05
|
||||
value = 1.0
|
||||
|
||||
[node name="DepthMap" type="HBoxContainer" parent="."]
|
||||
editor/display_folded = true
|
||||
margin_left = 16.0
|
||||
margin_top = 190.0
|
||||
margin_right = 214.0
|
||||
margin_bottom = 214.0
|
||||
|
||||
[node name="Label" type="Label" parent="DepthMap"]
|
||||
margin_top = 5.0
|
||||
margin_right = 120.0
|
||||
margin_bottom = 19.0
|
||||
size_flags_horizontal = 3
|
||||
text = "Depth map"
|
||||
|
||||
[node name="depth_scale" type="SpinBox" parent="DepthMap"]
|
||||
margin_left = 124.0
|
||||
margin_right = 198.0
|
||||
margin_bottom = 24.0
|
||||
max_value = 5.0
|
||||
step = 0.05
|
||||
value = 1.0
|
@ -1 +1 @@
|
||||
{"name":"transform","node_position":{"x":0,"y":0},"parameters":{"repeat":false,"rotate":120,"scale_x":1,"scale_y":1,"translate_x":0,"translate_y":0},"shader_model":{"global":"vec2 transform(vec2 uv, vec2 translate, float rotate, vec2 scale, bool repeat) {\n \tvec2 rv;\n\tuv -= vec2(0.5);\n\trv.x = cos(rotate)*uv.x + sin(rotate)*uv.y;\n\trv.y = -sin(rotate)*uv.x + cos(rotate)*uv.y;\n\trv /= scale;\n\trv += vec2(0.5);\n\trv -= translate;\n if (repeat) {\n\t\treturn fract(rv);\n\t} else {\n\t\treturn clamp(rv, vec2(0.0), vec2(1.0));\n\t}\t\n}","inputs":[{"default":"vec4($uv, 0.0, 1.0)","label":"","name":"i","type":"rgba"},{"default":"1.0","label":"","name":"tx","type":"f"},{"default":"1.0","label":"","name":"ty","type":"f"},{"default":"1.0","label":"","name":"r","type":"f"},{"default":"1.0","label":"","name":"sx","type":"f"},{"default":"1.0","label":"","name":"sy","type":"f"}],"instance":"","name":"Transform","outputs":[{"rgba":"$i(transform($uv, vec2($translate_x*(2.0*$tx($uv)-1.0), $translate_y*(2.0*$ty($uv)-1.0)), $rotate*0.01745329251*(2.0*$r($uv)-1.0), vec2($scale_x*(2.0*$sx($uv)-1.0), $scale_y*(2.0*$sy($uv)-1.0)), $repeat))","type":"rgba"}],"parameters":[{"default":0,"label":"2:Translate X:","max":1,"min":-1,"name":"translate_x","step":0.005,"type":"float","widget":"spinbox"},{"default":0,"label":"Translate Y:","max":1,"min":-1,"name":"translate_y","step":0.005,"type":"float","widget":"spinbox"},{"default":0,"label":"Rotate:","max":720,"min":-720,"name":"rotate","step":0.005,"type":"float","widget":"spinbox"},{"default":1,"label":"Scale X:","max":50,"min":0,"name":"scale_x","step":0.005,"type":"float","widget":"spinbox"},{"default":1,"label":"Scale Y:","max":50,"min":0,"name":"scale_y","step":0.005,"type":"float","widget":"spinbox"},{"default":false,"label":"Repeat:","name":"repeat","type":"boolean"}]},"type":"shader"}
|
||||
{"name":"transform","node_position":{"x":0,"y":0},"parameters":{"repeat":false,"rotate":0,"scale_x":1,"scale_y":1,"translate_x":0,"translate_y":0},"shader_model":{"code":"","global":"vec2 transform(vec2 uv, vec2 translate, float rotate, vec2 scale, bool repeat) {\n \tvec2 rv;\n\tuv -= translate;\n\tuv -= vec2(0.5);\n\trv.x = cos(rotate)*uv.x + sin(rotate)*uv.y;\n\trv.y = -sin(rotate)*uv.x + cos(rotate)*uv.y;\n\trv /= scale;\n\trv += vec2(0.5);\n if (repeat) {\n\t\treturn fract(rv);\n\t} else {\n\t\treturn clamp(rv, vec2(0.0), vec2(1.0));\n\t}\t\n}","inputs":[{"default":"vec4($uv, 0.0, 1.0)","label":"","name":"i","type":"rgba"},{"default":"1.0","label":"","name":"tx","type":"f"},{"default":"1.0","label":"","name":"ty","type":"f"},{"default":"1.0","label":"","name":"r","type":"f"},{"default":"1.0","label":"","name":"sx","type":"f"},{"default":"1.0","label":"","name":"sy","type":"f"}],"instance":"","name":"Transform","outputs":[{"rgba":"$i(transform($uv, vec2($translate_x*(2.0*$tx($uv)-1.0), $translate_y*(2.0*$ty($uv)-1.0)), $rotate*0.01745329251*(2.0*$r($uv)-1.0), vec2($scale_x*(2.0*$sx($uv)-1.0), $scale_y*(2.0*$sy($uv)-1.0)), $repeat))","type":"rgba"}],"parameters":[{"default":0,"label":"2:Translate X:","max":1,"min":-1,"name":"translate_x","step":0.005,"type":"float","widget":"spinbox"},{"default":0,"label":"Translate Y:","max":1,"min":-1,"name":"translate_y","step":0.005,"type":"float","widget":"spinbox"},{"default":0,"label":"Rotate:","max":720,"min":-720,"name":"rotate","step":0.005,"type":"float","widget":"spinbox"},{"default":1,"label":"Scale X:","max":50,"min":0,"name":"scale_x","step":0.005,"type":"float","widget":"spinbox"},{"default":1,"label":"Scale Y:","max":50,"min":0,"name":"scale_y","step":0.005,"type":"float","widget":"spinbox"},{"default":false,"label":"Repeat:","name":"repeat","type":"boolean"}]},"type":"shader"}
|
@ -1 +1 @@
|
||||
{"name":"voronoi","node_position":{"x":0,"y":0},"parameters":{"intensity":0.5,"scale_x":4,"scale_y":4},"shader_model":{"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"}]}}
|
||||
{"name":"voronoi","node_position":{"x":0,"y":0},"parameters":{"intensity":0.4,"randomness":1,"scale_x":16,"scale_y":16},"shader_model":{"code":"","global":"vec4 voronoi(vec2 uv, vec2 size, float intensity, float randomness, 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 += randomness*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","inputs":[],"instance":"","name":"Voronoi","outputs":[{"f":"voronoi($uv, vec2($scale_x, $scale_y), $intensity, $randomness, $seed).z","type":"f"},{"f":"voronoi($uv, vec2($scale_x, $scale_y), $intensity, $randomness, $seed).w","type":"f"},{"rgb":"rand3(fract(voronoi($uv, vec2($scale_x, $scale_y), $intensity, $randomness, $seed).xy))","type":"rgb"}],"parameters":[{"default":4,"label":"Scale X","max":32,"min":1,"name":"scale_x","step":1,"type":"float"},{"default":4,"label":"Scale Y","max":32,"min":1,"name":"scale_y","step":1,"type":"float"},{"default":0.5,"label":"Intensity","max":1,"min":0,"name":"intensity","step":0.05,"type":"float"},{"default":1,"label":"Randomness","max":1,"min":0,"name":"randomness","step":0.01,"type":"float"}]},"type":"shader"}
|
Loading…
Reference in New Issue
Block a user