Fixed 3d preview and added warp generator

This commit is contained in:
RodZill4 2019-09-13 08:07:46 +02:00
parent 9834571c4a
commit d643cecebb
6 changed files with 66 additions and 370 deletions

View File

@ -33,7 +33,7 @@ func _ready():
if Engine.editor_hint:
texture_list = ADDON_TEXTURE_LIST
for t in texture_list:
generated_textures[t.texture] = { shader=null, source=null, texture=null }
generated_textures[t.texture] = null
material = SpatialMaterial.new()
func generate_material(renderer : MMGenRenderer):
@ -42,14 +42,25 @@ func generate_material(renderer : MMGenRenderer):
var status = source.generator.render(source.output_index, renderer, 512)
while status is GDScriptFunctionState:
status = yield(status, "completed")
print("Render status: "+str(status))
renderer.get_texture().get_data().save_png("res://test.png")
material.albedo_texture = load("res://test.png")
return material
func initialize(data: Dictionary):
if data.has("name"):
name = data.name
func render_textures(renderer : MMGenRenderer):
for t in texture_list:
var source = get_source(t.port)
var texture = null
if source != null:
var status = source.generator.render(source.output_index, renderer, 512)
while status is GDScriptFunctionState:
status = yield(status, "completed")
texture = ImageTexture.new()
texture.create_from_image(renderer.get_texture().get_data())
generated_textures[t.texture] = texture
func update_materials(material_list):
for m in material_list:
update_spatial_material(m)
func get_generated_texture(slot, file_prefix = null):
if file_prefix != null:
@ -59,14 +70,14 @@ func get_generated_texture(slot, file_prefix = null):
else:
return null
else:
return generated_textures[slot].texture
return generated_textures[slot]
func update_spatial_material(m, file_prefix = null):
var texture
m.albedo_color = parameters.albedo_color
m.albedo_color = Color(1, 1, 1)#parameters.albedo_color
m.albedo_texture = get_generated_texture("albedo", file_prefix)
m.metallic = parameters.metallic
m.roughness = parameters.roughness
m.metallic = 1#parameters.metallic
m.roughness = 1#parameters.roughness
if Engine.editor_hint:
texture = get_generated_texture("mrao", file_prefix)
m.metallic_texture = texture
@ -79,7 +90,7 @@ func update_spatial_material(m, file_prefix = null):
texture = get_generated_texture("emission", file_prefix)
if texture != null:
m.emission_enabled = true
m.emission_energy = parameters.emission_energy
#m.emission_energy = parameters.emission_energy
m.emission_texture = texture
else:
m.emission_enabled = false
@ -92,7 +103,7 @@ func update_spatial_material(m, file_prefix = null):
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_light_affect = parameters.ao_light_affect
m.ao_texture = m.metallic_texture
m.ao_texture_channel = SpatialMaterial.TEXTURE_CHANNEL_BLUE
else:
@ -101,14 +112,14 @@ func update_spatial_material(m, file_prefix = null):
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_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_scale = parameters.depth_scale
m.depth_texture = texture
else:
m.depth_enabled = false

View File

@ -312,9 +312,12 @@ func _on_LoadRecent_id_pressed(id):
# Preview
func update_preview():
var material_node = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control().get_node("Material")
var material_node = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control().get_node("node_Material")
if material_node != null:
material_node.update_materials($VBoxContainer/HBoxContainer/VBoxContainer/Preview.get_materials())
var status = material_node.generator.render_textures(renderer)
while status is GDScriptFunctionState:
status = yield(status, "completed")
material_node.generator.update_materials($VBoxContainer/HBoxContainer/VBoxContainer/Preview.get_materials())
update_preview_2d()
func update_preview_2d(node = null):

View File

@ -4,27 +4,12 @@
[sub_resource type="Theme" id=1]
[node name="Material" type="GraphNode" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
[node name="Material" type="GraphNode"]
margin_right = 230.0
margin_bottom = 199.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
theme = SubResource( 1 )
title = "Material"
offset = Vector2( 0, 0 )
show_close = false
resizable = false
selected = false
comment = false
overlay = 0
slot/0/left_enabled = false
slot/0/left_type = 0
slot/0/left_color = Color( 0.411765, 1, 0.388235, 0.352941 )
@ -74,478 +59,165 @@ slot/7/right_enabled = false
slot/7/right_type = 0
slot/7/right_color = Color( 0.494118, 0.494118, 1, 1 )
script = ExtResource( 1 )
_sections_unfolded = [ "Theme", "slot", "slot/0", "slot/1", "slot/2", "slot/5", "slot/7" ]
[node name="resolution" type="OptionButton" parent="." index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
[node name="resolution" type="OptionButton" parent="."]
margin_left = 16.0
margin_top = 24.0
margin_right = 214.0
margin_bottom = 44.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
toggle_mode = false
action_mode = 0
enabled_focus_mode = 2
shortcut = null
group = null
text = "512x512"
flat = false
align = 0
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="." index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
[node name="Albedo" type="HBoxContainer" parent="."]
margin_left = 16.0
margin_top = 44.0
margin_right = 214.0
margin_bottom = 64.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 0
[node name="Label" type="Label" parent="Albedo" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
[node name="Label" type="Label" parent="Albedo"]
margin_top = 3.0
margin_right = 114.0
margin_bottom = 17.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 4
text = "Albedo"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Size Flags" ]
[node name="albedo_color" type="ColorPickerButton" parent="Albedo" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
[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 )
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
group = null
flat = false
align = 1
color = Color( 1, 1, 1, 1 )
edit_alpha = false
_sections_unfolded = [ "Rect", "Size Flags" ]
[node name="Metallic" type="HBoxContainer" parent="." index="2"]
[node name="Metallic" type="HBoxContainer" parent="."]
editor/display_folded = true
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 16.0
margin_top = 65.0
margin_right = 214.0
margin_bottom = 89.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 0
[node name="Label" type="Label" parent="Metallic" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
[node name="Label" type="Label" parent="Metallic"]
margin_top = 5.0
margin_right = 120.0
margin_bottom = 19.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 4
text = "Metallic"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Size Flags" ]
[node name="metallic" type="SpinBox" parent="Metallic" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
[node name="metallic" type="SpinBox" parent="Metallic"]
margin_left = 124.0
margin_right = 198.0
margin_bottom = 24.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
min_value = 0.0
max_value = 1.0
step = 0.05
page = 0.0
value = 1.0
exp_edit = false
rounded = false
editable = true
prefix = ""
suffix = ""
_sections_unfolded = [ "Rect" ]
[node name="Roughness" type="HBoxContainer" parent="." index="3"]
[node name="Roughness" type="HBoxContainer" parent="."]
editor/display_folded = true
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 16.0
margin_top = 90.0
margin_right = 214.0
margin_bottom = 114.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 0
[node name="Label" type="Label" parent="Roughness" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
[node name="Label" type="Label" parent="Roughness"]
margin_top = 5.0
margin_right = 120.0
margin_bottom = 19.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 4
text = "Roughness"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Size Flags" ]
[node name="roughness" type="SpinBox" parent="Roughness" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
[node name="roughness" type="SpinBox" parent="Roughness"]
margin_left = 124.0
margin_right = 198.0
margin_bottom = 24.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
min_value = 0.0
max_value = 1.0
step = 0.05
page = 0.0
value = 1.0
exp_edit = false
rounded = false
editable = true
prefix = ""
suffix = ""
_sections_unfolded = [ "Rect" ]
[node name="Emission" type="HBoxContainer" parent="." index="4"]
[node name="Emission" type="HBoxContainer" parent="."]
editor/display_folded = true
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 16.0
margin_top = 115.0
margin_right = 214.0
margin_bottom = 139.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 0
[node name="Label" type="Label" parent="Emission" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
[node name="Label" type="Label" parent="Emission"]
margin_top = 5.0
margin_right = 120.0
margin_bottom = 19.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 4
text = "Emission"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Size Flags" ]
[node name="emission_energy" type="SpinBox" parent="Emission" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
[node name="emission_energy" type="SpinBox" parent="Emission"]
margin_left = 124.0
margin_right = 198.0
margin_bottom = 24.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
min_value = 0.0
max_value = 5.0
step = 0.05
page = 0.0
value = 1.0
exp_edit = false
rounded = false
editable = true
prefix = ""
suffix = ""
_sections_unfolded = [ "Rect" ]
[node name="NormalMap" type="HBoxContainer" parent="." index="5"]
[node name="NormalMap" type="HBoxContainer" parent="."]
editor/display_folded = true
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 16.0
margin_top = 140.0
margin_right = 214.0
margin_bottom = 164.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 0
[node name="Label" type="Label" parent="NormalMap" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
[node name="Label" type="Label" parent="NormalMap"]
margin_top = 5.0
margin_right = 120.0
margin_bottom = 19.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 4
text = "Normal map"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Size Flags" ]
[node name="normal_scale" type="SpinBox" parent="NormalMap" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
[node name="normal_scale" type="SpinBox" parent="NormalMap"]
margin_left = 124.0
margin_right = 198.0
margin_bottom = 24.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
min_value = 0.0
max_value = 5.0
step = 0.05
page = 0.0
value = 1.0
exp_edit = false
rounded = false
editable = true
prefix = ""
suffix = ""
_sections_unfolded = [ "Rect" ]
[node name="AmbientOcclusion" type="HBoxContainer" parent="." index="6"]
[node name="AmbientOcclusion" type="HBoxContainer" parent="."]
editor/display_folded = true
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 16.0
margin_top = 165.0
margin_right = 214.0
margin_bottom = 189.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 0
[node name="Label" type="Label" parent="AmbientOcclusion" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
[node name="Label" type="Label" parent="AmbientOcclusion"]
margin_top = 5.0
margin_right = 120.0
margin_bottom = 19.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 4
text = "Ambient occlusion"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Size Flags" ]
[node name="ao_light_affect" type="SpinBox" parent="AmbientOcclusion" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
[node name="ao_light_affect" type="SpinBox" parent="AmbientOcclusion"]
margin_left = 124.0
margin_right = 198.0
margin_bottom = 24.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
min_value = 0.0
max_value = 5.0
step = 0.05
page = 0.0
value = 1.0
exp_edit = false
rounded = false
editable = true
prefix = ""
suffix = ""
_sections_unfolded = [ "Rect" ]
[node name="DepthMap" type="HBoxContainer" parent="." index="7"]
[node name="DepthMap" type="HBoxContainer" parent="."]
editor/display_folded = true
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 16.0
margin_top = 190.0
margin_right = 214.0
margin_bottom = 214.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 0
[node name="Label" type="Label" parent="DepthMap" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
[node name="Label" type="Label" parent="DepthMap"]
margin_top = 5.0
margin_right = 120.0
margin_bottom = 19.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 4
text = "Depth map"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Size Flags" ]
[node name="depth_scale" type="SpinBox" parent="DepthMap" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
[node name="depth_scale" type="SpinBox" parent="DepthMap"]
margin_left = 124.0
margin_right = 198.0
margin_bottom = 24.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
min_value = 0.0
max_value = 5.0
step = 0.05
page = 0.0
value = 1.0
exp_edit = false
rounded = false
editable = true
prefix = ""
suffix = ""
_sections_unfolded = [ "Rect" ]

View File

@ -1,8 +1,14 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=6 format=2]
[ext_resource path="res://addons/material_maker/nodes/transform/transform.gd" type="Script" id=1]
[sub_resource type="Theme" id=1]
[sub_resource type="StyleBoxEmpty" id=1]
[sub_resource type="StyleBoxEmpty" id=2]
[sub_resource type="StyleBoxEmpty" id=3]
[sub_resource type="StyleBoxEmpty" id=4]
[node name="Transform" type="GraphNode"]
margin_left = 1.0
@ -10,7 +16,10 @@ margin_top = 1.0
margin_right = 185.0
margin_bottom = 179.0
mouse_filter = 1
theme = SubResource( 1 )
custom_styles/position = SubResource( 1 )
custom_styles/defaultfocus = SubResource( 2 )
custom_styles/breakpoint = SubResource( 3 )
custom_styles/defaultframe = SubResource( 4 )
title = "Transform"
show_close = true
slot/0/left_enabled = true

View File

@ -0,0 +1 @@
{"name":"warp","node_position":{"x":0,"y":0},"parameters":{"amount":0.2,"eps":0.045,"epsilon":0},"shader_model":{"global":"","inputs":[{"default":"vec4(sin($uv.x*20.0)*0.5+0.5, sin($uv.y*20.0)*0.5+0.5, 0, 1)","label":"","name":"in","type":"rgba"},{"default":"0.0","label":"","name":"d","type":"f"}],"instance":"","name":"Warp","outputs":[{"rgba":"$in($uv+$amount*vec2($d(fract($uv+vec2($eps, 0.0)))-$d(fract($uv-vec2($eps, 0.0))), $d(fract($uv+vec2(0.0, $eps)))-$d(fract($uv-vec2(0.0, $eps)))))","type":"rgba"}],"parameters":[{"default":0,"label":"","max":1,"min":0,"name":"amount","step":0.005,"type":"float","widget":"spinbox"},{"default":0,"label":"","max":0.2,"min":0.005,"name":"eps","step":0.005,"type":"float","widget":"spinbox"}]}}

View File

@ -43,7 +43,7 @@ func _on_Preview_resized():
$Preview2D.rect_size = Vector2(64, 64)
func _on_Preview2D_gui_input(ev : InputEvent):
if ev is InputEventMouseButton && ev.button_index == 1 && ev.pressed:
if ev is InputEventMouseButton and ev.button_index == 1 and ev.pressed:
preview_maximized = !preview_maximized
_on_Preview_resized()