Preloaded renderer, support for subsurface scattering, minor fixes

This commit is contained in:
RodZill4 2019-11-06 22:33:01 +01:00
parent 51787b713c
commit bbfe288b15
17 changed files with 92 additions and 445 deletions

View File

@ -151,15 +151,15 @@ func get_input_shader(input_index : int):
func get_shader(output_index : int, context) -> Dictionary:
return get_shader_code("UV", output_index, context)
func render(output_index : int, renderer : MMGenRenderer, size : int):
var context : MMGenContext = MMGenContext.new(renderer)
func render(output_index : int, size : int):
var context : MMGenContext = MMGenContext.new()
var source = get_shader_code("UV", output_index, context)
while source is GDScriptFunctionState:
source = yield(source, "completed")
if source.empty():
source = { defs="", code="", textures={}, rgba="vec4(0.0)" }
var shader : String = renderer.generate_shader(source)
var result = renderer.render_shader(shader, source.textures, size)
var shader : String = mm_renderer.generate_shader(source)
var result = mm_renderer.render_shader(shader, source.textures, size)
while result is GDScriptFunctionState:
result = yield(result, "completed")
return result

View File

@ -38,7 +38,7 @@ func source_changed(input_port_index : int):
func _get_shader_code(uv : String, output_index : int, context : MMGenContext) -> Dictionary:
var source = get_source(0)
if source != null and !updated:
var result = source.generator.render(source.output_index, context.renderer, pow(2, parameters.size))
var result = source.generator.render(source.output_index, pow(2, parameters.size))
while result is GDScriptFunctionState:
result = yield(result, "completed")
result.copy_to_texture(texture)

View File

@ -2,11 +2,9 @@ tool
extends Object
class_name MMGenContext
var renderer : MMGenRenderer
var variants : Dictionary = {}
func _init(r : MMGenRenderer) -> void:
renderer = r
func has_variant(generator) -> bool:
return variants.has(generator)

View File

@ -34,11 +34,10 @@ func get_parameter_defs() -> Array:
func get_input_defs() -> Array:
return [ { name="in", type="rgba" } ]
func render_textures(renderer : MMGenRenderer) -> void:
print("rendering texture...")
func render_textures() -> void:
var source = get_source(0)
if source != null:
var result = source.generator.render(source.output_index, renderer, get_image_size())
var result = source.generator.render(source.output_index, get_image_size())
while result is GDScriptFunctionState:
result = yield(result, "completed")
texture = ImageTexture.new()
@ -48,7 +47,6 @@ func render_textures(renderer : MMGenRenderer) -> void:
texture = null
func export_textures(prefix, __ = null) -> void:
print("exporting texture")
if texture != null:
var image = texture.get_data()
image.save_png("%s_%s.png" % [ prefix, parameters.suffix])

View File

@ -8,9 +8,10 @@ var generated_textures = {}
const TEXTURE_LIST = [
{ port=0, texture="albedo" },
{ port=3, texture="emission" },
{ port=4, texture="normal_texture" },
{ port=4, texture="normal" },
{ ports=[5, 2, 1], default_values=["1.0", "1.0", "1.0"], texture="orm" },
{ port=6, texture="depth_texture" }
{ port=6, texture="depth" },
{ port=7, texture="subsurf_scatter" }
]
# The minimum allowed texture size as a power-of-two exponent
@ -45,6 +46,7 @@ func get_parameter_defs() -> Array:
{ name="normal_scale", label="Normal", type="float", min=0.0, max=8.0, step=0.05, default=1.0 },
{ name="ao_light_affect", label="Ambient occlusion", type="float", min=0.0, max=1.0, step=0.05, default=1.0 },
{ name="depth_scale", label="Depth", type="float", min=0.0, max=1.0, step=0.05, default=1.0 },
{ name="subsurf_scatter_strength", label="Subsurf. Scatter.", type="float", min=0.0, max=1.0, step=0.05, default=0.0 },
{ name="size", label="Size", type="size", first=TEXTURE_SIZE_MIN, last=TEXTURE_SIZE_MAX, default=TEXTURE_SIZE_DEFAULT }
]
@ -56,7 +58,8 @@ func get_input_defs() -> Array:
{ name="emission_texture", label="", type="rgb" },
{ name="normal_texture", label="", type="rgb" },
{ name="ao_texture", label="", type="f" },
{ name="depth_texture", label="", type="f" }
{ name="depth_texture", label="", type="f" },
{ name="subsurf_scatter_texture", label="", type="f" }
]
func get_image_size() -> int:
@ -86,7 +89,7 @@ func source_changed(input_index : int) -> void:
generated_textures[t.texture] = null
update_preview()
func render_textures(renderer : MMGenRenderer) -> void:
func render_textures() -> void:
for t in TEXTURE_LIST:
var texture = null
if t.has("port"):
@ -94,7 +97,7 @@ func render_textures(renderer : MMGenRenderer) -> void:
continue
var source = get_source(t.port)
if source != null:
var result = source.generator.render(source.output_index, renderer, get_image_size())
var result = source.generator.render(source.output_index, get_image_size())
while result is GDScriptFunctionState:
result = yield(result, "completed")
texture = ImageTexture.new()
@ -108,7 +111,7 @@ func render_textures(renderer : MMGenRenderer) -> void:
if texture.get_size().x <= 128:
texture.flags ^= ImageTexture.FLAG_FILTER
elif t.has("ports"):
var context : MMGenContext = MMGenContext.new(renderer)
var context : MMGenContext = MMGenContext.new()
var code = []
var shader_textures = {}
for i in range(t.ports.size()):
@ -119,11 +122,11 @@ func render_textures(renderer : MMGenRenderer) -> void:
status = yield(status, "completed")
code.push_back(status)
for t in status.textures.keys():
shader_textures[t] = code.textures[t]
shader_textures[t] = status.textures[t]
else:
code.push_back({ defs="", code="", f=t.default_values[i] })
var shader : String = renderer.generate_combined_shader(code[0], code[1], code[2])
var result = renderer.render_shader(shader, shader_textures, get_image_size())
var shader : String = mm_renderer.generate_combined_shader(code[0], code[1], code[2])
var result = mm_renderer.render_shader(shader, shader_textures, get_image_size())
while result is GDScriptFunctionState:
result = yield(result, "completed")
texture = ImageTexture.new()
@ -180,7 +183,7 @@ func update_spatial_material(m, file_prefix = null) -> void:
else:
m.emission_enabled = false
# Normal map
texture = get_generated_texture("normal_texture", file_prefix)
texture = get_generated_texture("normal", file_prefix)
if texture != null:
m.normal_enabled = true
m.normal_texture = texture
@ -195,7 +198,7 @@ func update_spatial_material(m, file_prefix = null) -> void:
else:
m.ao_enabled = false
# Depth
texture = get_generated_texture("depth_texture", file_prefix)
texture = get_generated_texture("depth", file_prefix)
if texture != null:
m.depth_enabled = true
m.depth_deep_parallax = true
@ -203,6 +206,14 @@ func update_spatial_material(m, file_prefix = null) -> void:
m.depth_texture = texture
else:
m.depth_enabled = false
# Subsurface scattering
texture = get_generated_texture("subsurf_scatter", file_prefix)
if texture != null:
m.subsurf_scatter_enabled = true
m.subsurf_scatter_strength = parameters.subsurf_scatter_strength
m.subsurf_scatter_texture = texture
else:
m.subsurf_scatter_enabled = false
else:
m.set_shader_param("albedo", parameters.albedo_color)
m.set_shader_param("texture_albedo", get_generated_texture("albedo", file_prefix))
@ -215,9 +226,9 @@ func update_spatial_material(m, file_prefix = null) -> void:
m.set_shader_param("emission_energy", parameters.emission_energy)
m.set_shader_param("texture_emission", get_generated_texture("emission", file_prefix))
m.set_shader_param("normal_scale", parameters.normal_scale)
m.set_shader_param("texture_normal", get_generated_texture("normal_texture", file_prefix))
m.set_shader_param("texture_normal", get_generated_texture("normal", file_prefix))
m.set_shader_param("depth_scale", parameters.depth_scale * 0.2)
m.set_shader_param("texture_depth", get_generated_texture("depth_texture", file_prefix))
m.set_shader_param("texture_depth", get_generated_texture("depth", file_prefix))
func export_textures(prefix, editor_interface = null) -> SpatialMaterial:
for t in TEXTURE_LIST:

View File

@ -4,7 +4,6 @@ class_name MMGraphEdit
var editor_interface = null
var node_factory = null
var renderer = null
var save_path = null setget set_save_path
var need_save = false
@ -216,7 +215,7 @@ func export_textures() -> void:
for c in get_children():
if c is GraphNode:
if c.generator.has_method("render_textures"):
c.generator.render_textures(renderer)
c.generator.render_textures()
if c.generator.has_method("export_textures"):
c.generator.export_textures(prefix, editor_interface)

View File

@ -9,7 +9,6 @@ var current_tab = null
var updating : bool = false
var need_update : bool = false
onready var renderer = $Renderer
onready var projects = $VBoxContainer/HBoxContainer/ProjectsPane/Projects
onready var library = $VBoxContainer/HBoxContainer/VBoxContainer/Library
@ -192,7 +191,6 @@ func menu_about_to_show(name, menu) -> void:
func new_pane() -> GraphEdit:
var graph_edit = preload("res://addons/material_maker/graph_edit.tscn").instance()
graph_edit.node_factory = $NodeFactory
graph_edit.renderer = $Renderer
graph_edit.editor_interface = editor_interface
projects.add_child(graph_edit)
projects.current_tab = graph_edit.get_index()
@ -347,7 +345,7 @@ func do_add_to_user_library(name, nodes) -> void:
dir.make_dir("user://library/user")
data.library = "user://library/user.json"
data.icon = name.right(name.rfind("/")+1).to_lower()
var result = nodes[0].generator.render(0, renderer, 64)
var result = nodes[0].generator.render(0, 64)
while result is GDScriptFunctionState:
result = yield(result, "completed")
result.save_to_file("user://library/user/"+data.icon+".png")
@ -433,7 +431,7 @@ func update_preview_2d(node = null) -> void:
node = n
break
if node != null:
var result = node.generator.render(0, renderer, 1024)
var result = node.generator.render(0, 1024)
while result is GDScriptFunctionState:
result = yield(result, "completed")
var tex = ImageTexture.new()
@ -445,7 +443,7 @@ func update_preview_3d() -> void:
var graph_edit : MMGraphEdit = get_current_graph_edit()
if graph_edit != null and graph_edit.top_generator != null and graph_edit.top_generator.has_node("Material"):
var gen_material = graph_edit.top_generator.get_node("Material")
var status = gen_material.render_textures(renderer)
var status = gen_material.render_textures()
while status is GDScriptFunctionState:
status = yield(status, "completed")
gen_material.update_materials($VBoxContainer/HBoxContainer/VBoxContainer/Preview.get_materials())

View File

@ -1,12 +1,11 @@
[gd_scene load_steps=10 format=2]
[gd_scene load_steps=9 format=2]
[ext_resource path="res://addons/material_maker/main_window.gd" type="Script" id=1]
[ext_resource path="res://addons/material_maker/library.tscn" type="PackedScene" id=2]
[ext_resource path="res://addons/material_maker/preview/preview.tscn" type="PackedScene" id=3]
[ext_resource path="res://addons/material_maker/preview/panoramas/epping_forest_01.hdr" type="Texture" id=4]
[ext_resource path="res://addons/material_maker/widgets/tabs.gd" type="Script" id=5]
[ext_resource path="res://addons/material_maker/engine/renderer.tscn" type="PackedScene" id=6]
[ext_resource path="res://addons/material_maker/node_factory.gd" type="Script" id=7]
[ext_resource path="res://addons/material_maker/node_factory.gd" type="Script" id=6]
[sub_resource type="PanoramaSky" id=1]
resource_local_to_scene = true
@ -67,14 +66,14 @@ margin_left = 125.0
margin_right = 171.0
margin_bottom = 20.0
text = "Tools"
items = [ "Create", null, 0, false, false, -1, 0, null, "PopupMenu", false, "Create group", null, 0, false, false, 18, 268435527, null, "", false, "Make selected nodes editable", null, 0, false, false, 19, 268435525, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "Add selected node to user library", null, 0, false, false, 21, 0, null, "", false ]
items = [ "Create", null, 0, false, false, -1, 0, null, "PopupMenu", false, "Create group", null, 0, false, false, 18, 268435527, null, "", false, "Make selected nodes editable", null, 0, false, false, 19, 268435525, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "Add selected node to user library", null, 0, false, false, 21, 0, null, "", false, "Export the nodes library", null, 0, false, false, 22, 0, null, "", false ]
[node name="Help" type="MenuButton" parent="VBoxContainer/Menu"]
margin_left = 175.0
margin_right = 217.0
margin_bottom = 20.0
text = "Help"
items = [ "User manual", null, 0, false, false, 22, 0, null, "", false, "Report a bug", null, 0, false, false, 23, 0, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "About", null, 0, false, false, 25, 0, null, "", false ]
items = [ "User manual", null, 0, false, false, 23, 0, null, "", false, "Report a bug", null, 0, false, false, 24, 0, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "About", null, 0, false, false, 26, 0, null, "", false ]
[node name="HBoxContainer" type="HSplitContainer" parent="VBoxContainer"]
margin_top = 24.0
@ -101,6 +100,7 @@ margin_left = 0.0
margin_top = 416.0
margin_right = 311.0
margin_bottom = 684.0
rect_min_size = Vector2( 300, 200 )
[node name="ProjectsPane" type="Control" parent="VBoxContainer/HBoxContainer"]
margin_left = 323.0
@ -143,12 +143,8 @@ margin_bottom = 24.0
tab_align = 0
tab_close_display_policy = 1
[node name="Renderer" parent="." instance=ExtResource( 6 )]
size = Vector2( 2048, 2048 )
debug_path = null
[node name="NodeFactory" type="Node" parent="."]
script = ExtResource( 7 )
script = ExtResource( 6 )
[connection signal="need_update" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview" to="." method="update_preview_3d"]
[connection signal="show_background_preview" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview" to="." method="_on_Preview_show_background_preview"]
[connection signal="no_more_tabs" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects" to="." method="new_material"]
@ -156,13 +152,41 @@ script = ExtResource( 7 )
[connection signal="tab_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects" to="." method="_on_Projects_tab_changed"]
[connection signal="connection_request" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit" method="connect_node"]
[connection signal="disconnection_request" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit" method="disconnect_node"]
[connection signal="value_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" method="update_label"]
[connection signal="value_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" method="update_label"]
[connection signal="value_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" method="update_label"]
[connection signal="value_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" method="update_label"]
[connection signal="value_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" method="update_label"]
[connection signal="value_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" method="update_label"]
[connection signal="value_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" method="update_label"]
[connection signal="focus_exited" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" method="_on_LineEdit_focus_exited"]
[connection signal="gui_input" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" method="_on_LineEdit_gui_input"]
[connection signal="resized" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" method="do_update"]
[connection signal="text_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" method="_on_LineEdit_text_changed"]
[connection signal="text_entered" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" method="_on_LineEdit_text_entered"]
[connection signal="focus_exited" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" method="_on_LineEdit_focus_exited"]
[connection signal="gui_input" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" method="_on_LineEdit_gui_input"]
[connection signal="resized" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" method="do_update"]
[connection signal="text_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" method="_on_LineEdit_text_changed"]
[connection signal="text_entered" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" method="_on_LineEdit_text_entered"]
[connection signal="focus_exited" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" method="_on_LineEdit_focus_exited"]
[connection signal="gui_input" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" method="_on_LineEdit_gui_input"]
[connection signal="resized" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" method="do_update"]
[connection signal="text_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" method="_on_LineEdit_text_changed"]
[connection signal="text_entered" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" method="_on_LineEdit_text_entered"]
[connection signal="focus_exited" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" method="_on_LineEdit_focus_exited"]
[connection signal="gui_input" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" method="_on_LineEdit_gui_input"]
[connection signal="resized" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" method="do_update"]
[connection signal="text_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" method="_on_LineEdit_text_changed"]
[connection signal="text_entered" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" method="_on_LineEdit_text_entered"]
[connection signal="focus_exited" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" method="_on_LineEdit_focus_exited"]
[connection signal="gui_input" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" method="_on_LineEdit_gui_input"]
[connection signal="resized" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" method="do_update"]
[connection signal="text_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" method="_on_LineEdit_text_changed"]
[connection signal="text_entered" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" method="_on_LineEdit_text_entered"]
[connection signal="focus_exited" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" method="_on_LineEdit_focus_exited"]
[connection signal="gui_input" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" method="_on_LineEdit_gui_input"]
[connection signal="resized" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" method="do_update"]
[connection signal="text_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" method="_on_LineEdit_text_changed"]
[connection signal="text_entered" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" method="_on_LineEdit_text_entered"]
[connection signal="focus_exited" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" method="_on_LineEdit_focus_exited"]
[connection signal="gui_input" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" method="_on_LineEdit_gui_input"]
[connection signal="resized" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" method="do_update"]
[connection signal="text_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" method="_on_LineEdit_text_changed"]
[connection signal="text_entered" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" method="_on_LineEdit_text_entered"]
[connection signal="reposition_active_tab_request" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/Tabs" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects" method="move_active_tab_to"]
[connection signal="tab_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/Tabs" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects" method="set_current_tab"]
[connection signal="tab_close" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/Tabs" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects" method="close_tab"]

View File

@ -1,307 +0,0 @@
tool
extends GraphNode
# A class that provides the shader node interface for a node port
class OutPort:
var node = null
var port = null
func get_shader_code(uv) -> String:
return node.get_shader_code(uv, port)
func generate_shader() -> String:
return node.generate_shader(port)
func get_globals() -> String:
return node.get_globals()
func get_textures() -> Dictionary:
return node.get_textures()
var generated = false
var generated_variants = []
var parameters = {}
var property_widgets = []
const Types = preload("res://addons/material_maker/types/types.gd")
func _ready():
pass
func initialize_properties(object_list):
property_widgets = object_list
for o in object_list:
if o == null:
print("error in node "+name)
elif o is LineEdit:
parameters[o.name] = float(o.text)
o.connect("text_changed", self, "_on_text_changed", [ o.name ])
elif o is SpinBox:
parameters[o.name] = o.value
o.connect("value_changed", self, "_on_value_changed", [ o.name ])
elif o is HSlider:
parameters[o.name] = o.value
o.connect("value_changed", self, "_on_value_changed", [ o.name ])
elif o is OptionButton:
parameters[o.name] = o.selected
o.connect("item_selected", self, "_on_value_changed", [ o.name ])
elif o is CheckBox:
parameters[o.name] = o.pressed
o.connect("toggled", self, "_on_value_changed", [ o.name ])
elif o is ColorPickerButton:
parameters[o.name] = o.color
o.connect("color_changed", self, "_on_color_changed", [ o.name ])
elif o is Control and o.filename == "res://addons/material_maker/widgets/gradient_editor.tscn":
parameters[o.name] = o.value
o.connect("updated", self, "_on_gradient_changed", [ o.name ])
else:
print("unsupported widget "+str(o))
func get_seed():
return int(offset.x)*3+int(offset.y)*5
func update_property_widgets():
for o in property_widgets:
if parameters.has(o.name) and parameters[o.name] != null:
if o is LineEdit:
o.text = str(parameters[o.name])
elif o is SpinBox:
o.value = parameters[o.name]
elif o is HSlider:
o.value = parameters[o.name]
elif o is OptionButton:
o.selected = parameters[o.name]
elif o is CheckBox:
o.pressed = parameters[o.name]
elif o is ColorPickerButton:
o.color = parameters[o.name]
elif o is Control and o.filename == "res://addons/material_maker/widgets/gradient_editor.tscn":
print("Updating "+o.name+" = "+str(parameters[o.name].to_string()))
o.value = parameters[o.name]
else:
print("Failed to update "+o.name)
func update_shaders():
get_parent().send_changed_signal()
func _on_text_changed(new_text, variable):
parameters[variable] = float(new_text)
update_shaders()
func _on_value_changed(new_value, variable):
parameters[variable] = new_value
update_shaders()
func _on_color_changed(new_color, variable):
parameters[variable] = new_color
update_shaders()
func _on_gradient_changed(new_gradient, variable):
parameters[variable] = new_gradient
update_shaders()
func get_source(index = 0):
for c in get_parent().get_connection_list():
if c.to == name and c.to_port == index:
if c.from_port == 0:
return get_parent().get_node(c.from)
else:
var out_port = OutPort.new()
out_port.node = get_parent().get_node(c.from)
out_port.port = c.from_port
return out_port
return null
func get_source_f(source) -> String:
var rv
if source.has("f"):
rv = source.f
elif source.has("rgb") or source.has("rgba"):
rv = "dot("+source.rgb+", vec3(1.0))/3.0"
else:
rv = "***error***"
return rv
func get_source_rgb(source) -> String:
var rv
if source.has("rgb") or source.has("rgba"):
rv = source.rgb
elif source.has("f"):
rv = "vec3("+source.f+")"
else:
rv = "***error***"
return rv
func get_source_rgba(source) -> String:
var rv
if source.has("rgba"):
rv = source.rgba
elif source.has("rgb"):
rv = "vec4("+source.rgb+", 1.0)"
elif source.has("f"):
rv = "vec4(vec3("+source.f+"), 1.0)"
else:
rv = "***error***"
return rv
func reset() -> void:
generated = false
generated_variants = []
func _get_shader_code(uv, slot = 0) -> Dictionary:
return {}
func get_shader_code(uv, slot = 0) -> String:
var rv
if slot == 0:
rv = _get_shader_code(uv)
else:
rv = _get_shader_code(uv, slot)
if !rv.has("f"):
if rv.has("rgb"):
rv.f = "(dot("+rv.rgb+", vec3(1.0))/3.0)"
elif rv.has("rgba"):
rv.f = "(dot("+rv.rgba+".rgb, vec3(1.0))/3.0)"
else:
rv.f = "0.0"
if !rv.has("rgb"):
if rv.has("rgba"):
rv.rgb = rv.rgba+".rgb"
else:
rv.rgb = "vec3("+rv.f+")"
if !rv.has("rgba"):
rv.rgba = "vec4("+rv.rgb+", 1.0)"
return rv
func get_shader_code_with_globals(uv, slot = 0) -> String:
var code = get_shader_code(uv, slot)
code.globals = get_globals()
return code
func get_globals() -> Array:
var list = []
for i in range(get_connection_input_count()):
var source = get_source(i)
if source != null:
var source_list = source.get_globals()
for g in source_list:
if list.find(g) == -1:
list.append(g)
return list
func get_textures() -> Dictionary:
var list = {}
for i in range(get_connection_input_count()):
var source = get_source(i)
if source != null:
var source_list = source.get_textures()
for k in source_list.keys():
list[k] = source_list[k]
return list
func serialize_element(e):
if typeof(e) == TYPE_COLOR:
return { type= "Color", r=e.r, g=e.g, b=e.b, a=e.a }
return e
func deserialize_element(e):
if typeof(e) == TYPE_DICTIONARY:
if e.has("type") and e.type == "Color":
return Color(e.r, e.g, e.b, e.a)
elif typeof(e) == TYPE_ARRAY:
var gradient = preload("res://addons/material_maker/types/gradient.gd").new()
gradient.deserialize(e)
return gradient
return e
func generate_shader(slot = 0) -> String:
# Reset all nodes
for c in get_parent().get_children():
if c is GraphNode:
c.reset()
return get_parent().renderer.generate_shader(get_shader_code_with_globals("UV", slot))
func serialize():
var type = get_script().resource_path
type = type.right(type.find_last("/")+1)
type = type.left(type.find_last("."))
var data = { name=name, type=type, node_position={x=offset.x, y=offset.y}, parameters={} }
for w in property_widgets:
var variable = w.name
data.parameters[variable] = Types.serialize_value(parameters[variable])
return data
func deserialize(data):
if data.has("node_position"):
offset = Vector2(data.node_position.x, data.node_position.y)
for w in property_widgets:
var variable = w.name
if data.has("parameters") and data.parameters.has(variable):
var value = Types.deserialize_value(data.parameters[variable])
parameters[variable] = value
elif data.has(variable):
var value = Types.deserialize_value(data[variable])
parameters[variable] = value
update_property_widgets()
# Render targets again for multipass filters
func rerender_targets() -> void:
for c in get_parent().get_connection_list():
if c.from == name:
var node = get_parent().get_node(c.to)
if node != null and node is GraphNode:
node._rerender()
func _rerender() -> void:
rerender_targets()
# Generic code for convolution nodes
func get_convolution_shader(convolution) -> String:
var shader_code
shader_code = "shader_type canvas_item;\n"
shader_code += "uniform sampler2D input_tex;\n"
shader_code += "void fragment() {\n"
shader_code += "vec3 color = vec3(0.0);\n"
for dy in range(-convolution.y, convolution.y+1):
for dx in range(-convolution.x, convolution.x+1):
var i = (2*convolution.x+1)*(dy+convolution.y)+dx+convolution.x
var coef = convolution.kernel[i]
if typeof(coef) == TYPE_INT:
coef = float(coef)
if typeof(coef) == TYPE_REAL:
coef = Vector3(coef, coef, coef)
if typeof(coef) != TYPE_VECTOR3 or coef == Vector3(0, 0, 0):
continue
shader_code += "color += vec3(%.9f, %.9f, %.9f) * textureLod(input_tex, UV+vec2(%.9f, %.9f), %.9f).rgb;\n" % [ coef.x, coef.y, coef.z, dx*convolution.epsilon, dy*convolution.epsilon, convolution.epsilon ]
if convolution.has("scale_before_normalize"):
shader_code += "color *= %.9f;\n" % [ convolution.scale_before_normalize ]
if convolution.has("translate_before_normalize"):
shader_code += "color += vec3(%.9f, %.9f, %.9f);\n" % [ convolution.translate_before_normalize.x, convolution.translate_before_normalize.y, convolution.translate_before_normalize.z ]
if convolution.has("normalize") and convolution.normalize:
shader_code += "color = normalize(color);\n"
if convolution.has("scale"):
shader_code += "color *= %.9f;\n" % [ convolution.scale ]
if convolution.has("translate"):
shader_code += "color += vec3(%.9f, %.9f, %.9f);\n" % [ convolution.translate.x, convolution.translate.y, convolution.translate.z ]
shader_code += "COLOR = vec4(color, 1.0);\n"
shader_code += "}\n"
return shader_code
func get_shader_code_convolution(src, convolution, uv) -> String:
var rv = { defs="", code="" }
var variant_index = generated_variants.find(uv)
var need_defs = false
if generated_variants.empty():
need_defs = true
if variant_index == -1:
variant_index = generated_variants.size()
generated_variants.append(uv)
var inputs_code = ""
var code = "vec3 %s_%d_rgb = " % [ name, variant_index ]
rv.code += inputs_code + code
rv.rgb = name+"_"+str(variant_index)+"_rgb"
return rv

View File

@ -1,31 +0,0 @@
tool
extends "res://addons/material_maker/node_base.gd"
var suffix = "suffix"
func _ready() -> void:
initialize_properties([ $resolution ])
func _get_shader_code(uv, slot = 0) -> Dictionary:
var rv = { defs="", code="", f="0.0" }
var src = get_source()
if src != null:
rv = src.get_shader_code(uv)
return rv
func export_textures(prefix, size = null) -> void:
var suffix = $Suffix.text
if suffix != "":
if size == null:
size = int(pow(2, 8+parameters.resolution))
get_parent().renderer.export_texture(get_source(), "%s_%s.png" % [ prefix, suffix ], size)
func serialize() -> Dictionary:
var data = .serialize()
data.suffix = $Suffix.text
return data
func deserialize(data) -> void:
if data.has("suffix"):
$Suffix.text = data.suffix
.deserialize(data)

View File

@ -1,44 +0,0 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://addons/material_maker/nodes/export/export.gd" type="Script" id=1]
[sub_resource type="Theme" id=1]
[node name="Export" type="GraphNode"]
margin_right = 90.0
margin_bottom = 53.0
mouse_filter = 1
theme = SubResource( 1 )
title = "Export"
show_close = true
slot/0/left_enabled = true
slot/0/left_type = 0
slot/0/left_color = Color( 0.5, 0.5, 1, 1 )
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 = false
slot/1/left_type = 0
slot/1/left_color = Color( 1, 1, 1, 1 )
slot/1/right_enabled = false
slot/1/right_type = 0
slot/1/right_color = Color( 1, 1, 1, 1 )
script = ExtResource( 1 )
[node name="resolution" type="OptionButton" parent="."]
margin_left = 16.0
margin_top = 24.0
margin_right = 126.0
margin_bottom = 44.0
rect_min_size = Vector2( 110, 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="Suffix" type="LineEdit" parent="."]
margin_left = 16.0
margin_top = 44.0
margin_right = 126.0
margin_bottom = 68.0
text = "suffix"

View File

@ -380,8 +380,7 @@ func update_preview(size : int = 0) -> void:
preview_timer.start(0.2)
func do_update_preview() -> void:
var renderer = get_parent().renderer
var result = generator.render(preview_index, renderer, preview_size)
var result = generator.render(preview_index, preview_size)
while result is GDScriptFunctionState:
result = yield(result, "completed")
if preview.texture == null:

View File

@ -4,13 +4,10 @@ extends EditorPlugin
var mm_button = null
var material_maker = null
var importer = null
var renderer = null
func _enter_tree() -> void:
add_tool_menu_item("Material Maker", self, "open_material_maker")
add_tool_menu_item("Register Material Maker Import", self, "register_material_maker_import")
renderer = preload("res://addons/material_maker/engine/renderer.tscn").instance()
add_child(renderer)
func register_material_maker_import(__) -> void:
importer = preload("res://addons/material_maker/import_plugin/ptex_import.gd").new(self)
@ -62,7 +59,7 @@ func generate_material(ptex_filename: String) -> Material:
if generator.has_node("Material"):
var gen_material = generator.get_node("Material")
if gen_material != null:
var return_value = gen_material.render_textures(renderer)
var return_value = gen_material.render_textures(mm_renderer)
while return_value is GDScriptFunctionState:
return_value = yield(return_value, "completed")
var prefix = ptex_filename.left(ptex_filename.rfind("."))

View File

@ -67,11 +67,7 @@ func get_shader(name) -> String:
shader += " return "+gcis(points[0].c)+";\n"
var s = points.size()-1
for i in range(s):
var p0 = points[i].v
var c0 = points[i].c
var p1mp0 = points[i+1].v-p0
var c1mc0 = points[i+1].c-c0
if p1mp0 > 0:
if points[i+1].v-points[i].v > 0:
shader += " } else if (x < %.9f) {\n" % (0.5*(points[i].v + points[i+1].v))
shader += " return "+gcis(points[i].c)+";\n"
shader += " }\n"

View File

@ -11,7 +11,6 @@
[ext_resource path="res://addons/material_maker/widgets/about/itchio.png" type="Texture" id=9]
[node name="About" type="WindowDialog"]
visible = true
margin_right = 200.0
margin_bottom = 289.0
window_title = "About..."
@ -140,7 +139,7 @@ margin_left = 112.0
margin_right = 136.0
margin_bottom = 24.0
rect_min_size = Vector2( 24, 24 )
hint_tooltip = "Github"
hint_tooltip = "ItchIO"
texture_normal = ExtResource( 9 )
expand = true
stretch_mode = 4

View File

@ -4,7 +4,7 @@
[ext_resource path="res://addons/material_maker/widgets/float_edit.tscn" type="PackedScene" id=2]
[node name="float" type="HBoxContainer"]
margin_right = 547.0
margin_right = 400.0
margin_bottom = 24.0
script = ExtResource( 1 )

View File

@ -9,6 +9,11 @@
config_version=4
_global_script_classes=[ {
"base": "LineEdit",
"class": "MMFloatEdit",
"language": "GDScript",
"path": "res://addons/material_maker/widgets/float_edit.gd"
}, {
"base": "Node",
"class": "MMGenBase",
"language": "GDScript",
@ -140,6 +145,7 @@ _global_script_classes=[ {
"path": "res://addons/material_maker/widgets/size_option_button.gd"
} ]
_global_script_class_icons={
"MMFloatEdit": "",
"MMGenBase": "",
"MMGenBuffer": "",
"MMGenComment": "",
@ -180,6 +186,10 @@ boot_splash/bg_color=Color( 0.0901961, 0.0941176, 0.141176, 1 )
config/icon="res://icon.png"
config/release="0.7a1"
[autoload]
mm_renderer="*res://addons/material_maker/engine/renderer.tscn"
[debug]
gdscript/warnings/unsafe_property_access=true