Size parameter fix and better preview UI

This commit is contained in:
RodZill4 2019-10-14 20:42:11 +02:00
parent 477eec692b
commit 74959637bd
13 changed files with 120 additions and 237 deletions

View File

@ -42,6 +42,8 @@ func init_parameters():
if !parameters.has(p.name): if !parameters.has(p.name):
if p.has("default"): if p.has("default"):
parameters[p.name] = MMType.deserialize_value(p.default) parameters[p.name] = MMType.deserialize_value(p.default)
if p.type == "size":
parameters[p.name] -= p.first
else: else:
print("No default value for parameter "+p.name) print("No default value for parameter "+p.name)

View File

@ -35,7 +35,8 @@ func get_parameter_defs():
{ name="emission_energy", label="Emission", type="float", min=0.0, max=8.0, step=0.05, default=1.0 }, { name="emission_energy", label="Emission", type="float", min=0.0, max=8.0, step=0.05, default=1.0 },
{ name="normal_scale", label="Normal", type="float", min=0.0, max=8.0, step=0.05, default=1.0 }, { 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="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="depth_scale", label="Depth", type="float", min=0.0, max=1.0, step=0.05, default=1.0 },
{ name="size", label="Size", type="size", first=7, last=11, default=9 }
] ]
func get_input_defs(): func get_input_defs():
@ -49,6 +50,14 @@ func get_input_defs():
{ name="depth_texture", label="", type="f" } { name="depth_texture", label="", type="f" }
] ]
func get_image_size():
var rv : int
if parameters.has("size"):
rv = int(pow(2, parameters.size+7))
else:
rv = 512
return rv
func update_preview(): func update_preview():
var graph_edit = self var graph_edit = self
while graph_edit is MMGenBase: while graph_edit is MMGenBase:
@ -69,7 +78,7 @@ func render_textures(renderer : MMGenRenderer):
if t.has("port"): if t.has("port"):
var source = get_source(t.port) var source = get_source(t.port)
if source != null: if source != null:
var result = source.generator.render(source.output_index, renderer, 1024) var result = source.generator.render(source.output_index, renderer, get_image_size())
while result is GDScriptFunctionState: while result is GDScriptFunctionState:
result = yield(result, "completed") result = yield(result, "completed")
texture = ImageTexture.new() texture = ImageTexture.new()
@ -91,7 +100,7 @@ func render_textures(renderer : MMGenRenderer):
else: else:
code.push_back({ defs="", code="", f=t.default_values[i] }) code.push_back({ defs="", code="", f=t.default_values[i] })
var shader : String = renderer.generate_combined_shader(code[0], code[1], code[2]) var shader : String = renderer.generate_combined_shader(code[0], code[1], code[2])
var result = renderer.render_shader(shader, shader_textures, 1024) var result = renderer.render_shader(shader, shader_textures, get_image_size())
while result is GDScriptFunctionState: while result is GDScriptFunctionState:
result = yield(result, "completed") result = yield(result, "completed")
texture = ImageTexture.new() texture = ImageTexture.new()

View File

@ -96,6 +96,7 @@ func render_shader(shader, textures, render_size):
func copy_to_texture(t : ImageTexture): func copy_to_texture(t : ImageTexture):
var image : Image = get_texture().get_data() var image : Image = get_texture().get_data()
if image != null:
image.lock() image.lock()
t.create_from_image(get_texture().get_data()) t.create_from_image(get_texture().get_data())
image.unlock() image.unlock()

View File

@ -1,11 +1,20 @@
[gd_scene load_steps=7 format=2] [gd_scene load_steps=10 format=2]
[ext_resource path="res://addons/material_maker/main_window.gd" type="Script" id=1] [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/library.tscn" type="PackedScene" id=2]
[ext_resource path="res://addons/material_maker/preview.tscn" type="PackedScene" id=3] [ext_resource path="res://addons/material_maker/preview.tscn" type="PackedScene" id=3]
[ext_resource path="res://addons/material_maker/widgets/tabs.gd" type="Script" id=4] [ext_resource path="res://addons/material_maker/panoramas/epping_forest_01.hdr" type="Texture" id=4]
[ext_resource path="res://addons/material_maker/engine/renderer.tscn" type="PackedScene" id=5] [ext_resource path="res://addons/material_maker/widgets/tabs.gd" type="Script" id=5]
[ext_resource path="res://addons/material_maker/node_factory.gd" type="Script" id=6] [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]
[sub_resource type="PanoramaSky" id=6]
resource_local_to_scene = true
panorama = ExtResource( 4 )
[sub_resource type="Environment" id=7]
background_mode = 2
background_sky = SubResource( 6 )
[node name="MainWindow" type="Panel"] [node name="MainWindow" type="Panel"]
anchor_right = 1.0 anchor_right = 1.0
@ -98,6 +107,7 @@ render_target_update_mode = 0
[node name="Camera" type="Camera" parent="VBoxContainer/HBoxContainer/ProjectsPane/BackgroundPreview/Viewport"] [node name="Camera" type="Camera" parent="VBoxContainer/HBoxContainer/ProjectsPane/BackgroundPreview/Viewport"]
transform = Transform( 1, 0, 0, 0, 0.766044, 0.642788, 0, -0.642788, 0.766044, 0, 2.24976, 2.68115 ) transform = Transform( 1, 0, 0, 0, 0.766044, 0.642788, 0, -0.642788, 0.766044, 0, 2.24976, 2.68115 )
environment = SubResource( 7 )
current = true current = true
[node name="Projects" type="Panel" parent="VBoxContainer/HBoxContainer/ProjectsPane"] [node name="Projects" type="Panel" parent="VBoxContainer/HBoxContainer/ProjectsPane"]
@ -106,7 +116,7 @@ anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
script = ExtResource( 4 ) script = ExtResource( 5 )
[node name="Tabs" type="Tabs" parent="VBoxContainer/HBoxContainer/ProjectsPane/Projects"] [node name="Tabs" type="Tabs" parent="VBoxContainer/HBoxContainer/ProjectsPane/Projects"]
margin_right = 954.0 margin_right = 954.0
@ -114,12 +124,12 @@ margin_bottom = 24.0
tab_align = 0 tab_align = 0
tab_close_display_policy = 1 tab_close_display_policy = 1
[node name="Renderer" parent="." instance=ExtResource( 5 )] [node name="Renderer" parent="." instance=ExtResource( 6 )]
size = Vector2( 1024, 1024 ) size = Vector2( 512, 512 )
debug_path = null debug_path = null
[node name="NodeFactory" type="Node" parent="."] [node name="NodeFactory" type="Node" parent="."]
script = ExtResource( 6 ) script = ExtResource( 7 )
[connection signal="need_update" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview" to="." method="update_preview_3d"] [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="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"] [connection signal="no_more_tabs" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects" to="." method="new_material"]

View File

@ -20,7 +20,7 @@ slot/0/left_type = 0
slot/0/left_color = Color( 0.5, 0.5, 1, 1 ) slot/0/left_color = Color( 0.5, 0.5, 1, 1 )
slot/0/right_enabled = true slot/0/right_enabled = true
slot/0/right_type = 0 slot/0/right_type = 0
slot/0/right_color = Color( 0, 1, 0, 0.501961 ) slot/0/right_color = Color( 0.5, 0.5, 1, 1 )
script = ExtResource( 1 ) script = ExtResource( 1 )
[node name="TextureButton" type="TextureButton" parent="."] [node name="TextureButton" type="TextureButton" parent="."]

View File

@ -13,6 +13,9 @@ onready var current_object = objects.get_child(0)
onready var environments = $MaterialPreview/Preview3d/Environments onready var environments = $MaterialPreview/Preview3d/Environments
onready var current_environment = environments.get_child(0) onready var current_environment = environments.get_child(0)
onready var camera_stand = $MaterialPreview/Preview3d/CameraPivot
onready var camera = $MaterialPreview/Preview3d/CameraPivot/Camera
signal need_update signal need_update
signal show_background_preview signal show_background_preview
@ -72,10 +75,23 @@ func _on_Button_toggled(button_pressed):
func on_gui_input(event): func on_gui_input(event):
if event is InputEventMouseButton: if event is InputEventMouseButton:
$MaterialPreview/Preview3d/ObjectRotate.stop() $MaterialPreview/Preview3d/ObjectRotate.stop()
match event.button_index:
BUTTON_WHEEL_UP:
camera.translation.z *= 1.01 if event.shift else 1.1
BUTTON_WHEEL_DOWN:
camera.translation.z /= 1.01 if event.shift else 1.1
elif event is InputEventMouseMotion: elif event is InputEventMouseMotion:
var motion = 0.01*event.relative
var camera_basis = camera.global_transform.basis
if event.shift:
if event.button_mask & BUTTON_MASK_LEFT: if event.button_mask & BUTTON_MASK_LEFT:
$MaterialPreview/Preview3d/Objects.rotation.y += 0.01*event.relative.x objects.rotate(camera_basis.x.normalized(), motion.y)
$MaterialPreview/Preview3d/Objects.rotation.x += 0.01*event.relative.y objects.rotate(camera_basis.y.normalized(), motion.x)
elif event.button_mask & BUTTON_MASK_RIGHT: elif event.button_mask & BUTTON_MASK_RIGHT:
$MaterialPreview/Preview3d/CameraPivot.rotation.y += 0.01*event.relative.x objects.rotate(camera_basis.z.normalized(), motion.x)
$MaterialPreview/Preview3d/CameraPivot.rotation.x -= 0.01*event.relative.y else:
if event.button_mask & BUTTON_MASK_LEFT:
camera_stand.rotate(camera_basis.x.normalized(), -motion.y)
camera_stand.rotate(camera_basis.y.normalized(), -motion.x)
elif event.button_mask & BUTTON_MASK_RIGHT:
camera_stand.rotate(camera_basis.z.normalized(), -motion.x)

View File

@ -25,6 +25,7 @@ margin_top = 3.0
margin_right = -3.0 margin_right = -3.0
margin_bottom = 373.0 margin_bottom = 373.0
rect_min_size = Vector2( 200, 200 ) rect_min_size = Vector2( 200, 200 )
mouse_filter = 1
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
stretch = true stretch = true
@ -37,6 +38,7 @@ world = SubResource( 1 )
handle_input_locally = false handle_input_locally = false
render_target_clear_mode = 1 render_target_clear_mode = 1
render_target_update_mode = 3 render_target_update_mode = 3
physics_object_picking = true
[node name="Preview3d" parent="MaterialPreview" instance=ExtResource( 2 )] [node name="Preview3d" parent="MaterialPreview" instance=ExtResource( 2 )]

View File

@ -1,19 +1,20 @@
[gd_scene load_steps=14 format=2] [gd_scene load_steps=13 format=2]
[ext_resource path="res://addons/material_maker/preview_objects.tscn" type="PackedScene" id=1] [ext_resource path="res://addons/material_maker/preview_objects.tscn" type="PackedScene" id=1]
[ext_resource path="res://addons/material_maker/environment.gd" type="Script" id=2] [ext_resource path="res://addons/material_maker/environment.gd" type="Script" id=2]
[ext_resource path="res://addons/material_maker/panoramas/epping_forest_01.hdr" type="Texture" id=3] [ext_resource path="res://addons/material_maker/panoramas/epping_forest_01.hdr" type="Texture" id=3]
[ext_resource path="res://addons/material_maker/panoramas/moonless_golf.hdr" type="Texture" id=4] [ext_resource path="res://addons/material_maker/preview_light.tscn" type="PackedScene" id=4]
[ext_resource path="res://addons/material_maker/panoramas/moonless_golf.hdr" type="Texture" id=5]
[sub_resource type="PanoramaSky" id=1] [sub_resource type="PanoramaSky" id=3]
[sub_resource type="Environment" id=2] [sub_resource type="Environment" id=4]
background_mode = 2 background_mode = 2
background_sky = SubResource( 1 ) background_sky = SubResource( 3 )
ambient_light_color = Color( 0.992157, 1, 0.709804, 1 ) ambient_light_color = Color( 0.992157, 1, 0.709804, 1 )
ambient_light_energy = 0.3 ambient_light_energy = 0.3
[sub_resource type="Animation" id=3] [sub_resource type="Animation" id=5]
loop = true loop = true
tracks/0/type = "value" tracks/0/type = "value"
tracks/0/path = NodePath("Objects:rotation_degrees") tracks/0/path = NodePath("Objects:rotation_degrees")
@ -28,25 +29,17 @@ tracks/0/keys = {
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 360, 0 ) ] "values": [ Vector3( 0, 0, 0 ), Vector3( 0, 360, 0 ) ]
} }
[sub_resource type="PanoramaSky" id=4] [sub_resource type="PanoramaSky" id=6]
resource_local_to_scene = true resource_local_to_scene = true
panorama = ExtResource( 3 ) panorama = ExtResource( 3 )
[sub_resource type="Environment" id=5] [sub_resource type="Environment" id=7]
background_mode = 2 background_mode = 2
background_sky = SubResource( 4 ) background_sky = SubResource( 6 )
[sub_resource type="SpatialMaterial" id=6]
flags_unshaded = true
[sub_resource type="SphereMesh" id=7]
material = SubResource( 6 )
radius = 0.25
height = 0.5
[sub_resource type="PanoramaSky" id=8] [sub_resource type="PanoramaSky" id=8]
resource_local_to_scene = true resource_local_to_scene = true
panorama = ExtResource( 4 ) panorama = ExtResource( 5 )
[sub_resource type="Environment" id=9] [sub_resource type="Environment" id=9]
resource_local_to_scene = true resource_local_to_scene = true
@ -63,7 +56,7 @@ transform = Transform( 1, 0, 0, 0, 0.766044, 0.642788, 0, -0.642788, 0.766044, 0
[node name="Camera" type="Camera" parent="CameraPivot"] [node name="Camera" type="Camera" parent="CameraPivot"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3.5 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3.5 )
environment = SubResource( 2 ) environment = SubResource( 4 )
current = true current = true
[node name="RemoteTransform" type="RemoteTransform" parent="CameraPivot/Camera"] [node name="RemoteTransform" type="RemoteTransform" parent="CameraPivot/Camera"]
@ -72,48 +65,24 @@ remote_path = NodePath("../../../../../../ProjectsPane/BackgroundPreview/Viewpor
[node name="ObjectRotate" type="AnimationPlayer" parent="."] [node name="ObjectRotate" type="AnimationPlayer" parent="."]
autoplay = "rotate" autoplay = "rotate"
playback_speed = 0.1 playback_speed = 0.1
anims/rotate = SubResource( 3 ) anims/rotate = SubResource( 5 )
[node name="Environments" type="Spatial" parent="."] [node name="Environments" type="Spatial" parent="."]
[node name="Epping Forest" type="Spatial" parent="Environments"] [node name="Epping Forest" type="Spatial" parent="Environments"]
visible = false
script = ExtResource( 2 ) script = ExtResource( 2 )
environment = SubResource( 5 ) environment = SubResource( 7 )
[node name="Light" type="OmniLight" parent="Environments/Epping Forest"] [node name="Light" parent="Environments/Epping Forest" instance=ExtResource( 4 )]
transform = Transform( 0.999755, 0.0162074, -0.0150931, 0, 0.681502, 0.731816, 0.0221468, -0.731637, 0.681335, -0.0821358, 3.98251, -2.64581 ) transform = Transform( 0.999755, 0.0162074, -0.0150931, 0, 0.681502, 0.731816, 0.0221468, -0.731637, 0.681335, 0.0511079, 4.03913, -2.64581 )
light_energy = 4.9
omni_range = 12.9508
[node name="Mesh" type="MeshInstance" parent="Environments/Epping Forest/Light"]
transform = Transform( 1, 1.11759e-008, -1.30385e-008, -1.86265e-009, 1, -4.17233e-007, 0, 0, 1, 0, 0, 0 )
cast_shadow = 0
mesh = SubResource( 7 )
material/0 = null
[node name="Moonless Golf" type="Spatial" parent="Environments"] [node name="Moonless Golf" type="Spatial" parent="Environments"]
visible = false visible = false
script = ExtResource( 2 ) script = ExtResource( 2 )
environment = SubResource( 9 ) environment = SubResource( 9 )
[node name="Light1" type="OmniLight" parent="Environments/Moonless Golf"] [node name="Light1" parent="Environments/Moonless Golf" instance=ExtResource( 4 )]
transform = Transform( 0.999755, 0.0162074, -0.0150931, 0, 0.681502, 0.731816, 0.0221468, -0.731637, 0.681335, -2.22238, 3.98251, -2.64581 )
light_energy = 4.9
omni_range = 12.9508
[node name="Mesh" type="MeshInstance" parent="Environments/Moonless Golf/Light1"] [node name="Light2" parent="Environments/Moonless Golf" instance=ExtResource( 4 )]
transform = Transform( 1, 1.11759e-008, -1.39698e-008, -1.86265e-009, 1, -4.17233e-007, 0, 0, 1, 0, 0, 0 ) transform = Transform( 0.999755, 0.0162074, -0.0150931, 0, 0.681502, 0.731816, 0.0221468, -0.731637, 0.681335, 2.3608, 3.98251, -2.64581 )
cast_shadow = 0
mesh = SubResource( 7 )
material/0 = null
[node name="Light2" type="OmniLight" parent="Environments/Moonless Golf"]
transform = Transform( 0.999755, 0.0162074, -0.0150931, 0, 0.681502, 0.731816, 0.0221468, -0.731637, 0.681335, 2.34329, 3.98251, -2.64581 )
light_energy = 4.9
omni_range = 12.9508
[node name="Mesh" type="MeshInstance" parent="Environments/Moonless Golf/Light2"]
transform = Transform( 1, 1.11759e-008, -1.39698e-008, -1.86265e-009, 1, -4.17233e-007, 0, 0, 1, 0, 0, 0 )
cast_shadow = 0
mesh = SubResource( 7 )
material/0 = null

View File

@ -0,0 +1,5 @@
tool
extends Area
func _on_Light_input_event(camera, event, click_position, click_normal, shape_idx):
print(event)

View File

@ -0,0 +1,34 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://addons/material_maker/preview_light.gd" type="Script" id=1]
[sub_resource type="SphereShape" id=3]
radius = 0.332384
[sub_resource type="SpatialMaterial" id=1]
flags_unshaded = true
[sub_resource type="SphereMesh" id=2]
material = SubResource( 1 )
radius = 0.25
height = 0.5
[node name="Light" type="Area"]
transform = Transform( 0.999755, 0.0162074, -0.0150931, 0, 0.681502, 0.731816, 0.0221468, -0.731637, 0.681335, -2.22238, 3.98251, -2.64581 )
script = ExtResource( 1 )
[node name="CollisionShape" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 9.31323e-010, -1.86265e-009, 1, 2.98023e-008, 9.31323e-010, 2.98023e-008, 1, 0, 0, 0 )
shape = SubResource( 3 )
[node name="Light" type="OmniLight" parent="."]
transform = Transform( 1, -1.86265e-009, 9.31323e-010, -1.86265e-009, 1, 0, 0, 2.98023e-008, 1, 0, 0, 0 )
light_energy = 4.9
omni_range = 12.9508
[node name="Mesh" type="MeshInstance" parent="."]
transform = Transform( 1, 1.11759e-008, -1.21072e-008, -5.58794e-009, 1, -4.17233e-007, 9.31323e-010, 0, 1, 0, 0, 0 )
cast_shadow = 0
mesh = SubResource( 2 )
material/0 = null
[connection signal="input_event" from="." to="." method="_on_Light_input_event"]

View File

@ -1,3 +0,0 @@
[gd_resource type="World" format=2]
[resource]

View File

@ -1,128 +0,0 @@
tool
extends Viewport
export(String) var debug_path = null
var debug_file_index = 0
var render_queue = []
func _ready():
$ColorRect.material = $ColorRect.material.duplicate(true)
# Save shader to image, create image texture
static func generate_shader(src_code):
var code
code = "shader_type canvas_item;\n"
code += "render_mode blend_disabled;\n"
var file = File.new()
file.open("res://addons/material_maker/common.shader", File.READ)
code += file.get_as_text()
code += "\n"
if src_code.has("globals"):
for g in src_code.globals:
code += g
var shader_code = src_code.defs
shader_code += "void fragment() {\n"
shader_code += src_code.code
shader_code += "COLOR = "+src_code.rgba+";\n"
shader_code += "}\n"
#print("GENERATED SHADER:\n"+shader_code)
code += shader_code
return code
static func generate_combined_shader(red_code, green_code, blue_code):
var code
code = "shader_type canvas_item;\n"
code += "render_mode blend_disabled;\n"
var file = File.new()
file.open("res://addons/material_maker/common.shader", File.READ)
code += file.get_as_text()
code += "\n"
if red_code.has("globals"):
for g in red_code.globals:
code += g
if green_code.has("globals"):
for g in green_code.globals:
code += g
if blue_code.has("globals"):
for g in blue_code.globals:
code += g
var shader_code = ""
shader_code += red_code.defs
shader_code += green_code.defs
shader_code += blue_code.defs
shader_code += "void fragment() {\n"
shader_code += red_code.code
shader_code += green_code.code
shader_code += blue_code.code
shader_code += "COLOR = vec4("+red_code.f+", "+green_code.f+", "+blue_code.f+", 1.0);\n"
shader_code += "}\n"
#print("GENERATED COMBINED SHADER:\n"+shader_code)
code += shader_code
return code
func setup_material(shader_material, textures, shader_code):
for k in textures.keys():
shader_material.set_shader_param(k+"_tex", textures[k])
shader_material.shader.code = shader_code
func render_shader_to_viewport(shader, textures, render_size, method, args):
if debug_path != null and debug_path != "":
var f = File.new()
f.open(debug_path+str(debug_file_index)+".shader", File.WRITE)
f.store_string(shader)
f.close()
debug_file_index += 1
render_queue.append( { shader=shader, textures=textures, size=render_size, method=method, args=args } )
if render_queue.size() == 1:
while !render_queue.empty():
var job = render_queue.front()
size = Vector2(job.size, job.size)
$ColorRect.rect_position = Vector2(0, 0)
$ColorRect.rect_size = Vector2(job.size, job.size)
var shader_material = $ColorRect.material
shader_material.shader.code = job.shader
if job.textures != null:
for k in job.textures.keys():
shader_material.set_shader_param(k+"_tex", job.textures[k])
render_target_update_mode = Viewport.UPDATE_ALWAYS
update_worlds()
yield(get_tree(), "idle_frame")
yield(get_tree(), "idle_frame")
render_target_update_mode = Viewport.UPDATE_DISABLED
callv(job.method, job.args)
render_queue.pop_front()
func render_to_viewport(node, render_size, method, args):
render_shader_to_viewport(node.generate_shader(), node.get_textures(), render_size, method, args)
func export_texture(node, filename, render_size = 256):
if node == null:
return null
render_to_viewport(node, render_size, "do_export_texture", [ filename ])
func do_export_texture(filename):
var viewport_texture = get_texture()
var x = ImageTexture.new()
x.create_from_image(viewport_texture.get_data())
var viewport_image = x.get_data()
var f = File.new()
f.open(filename+".raw", File.WRITE)
f.store_buffer(viewport_image.get_data())
f.close()
viewport_image.save_png(filename)
func precalculate_node(node, render_size, target_texture, object, method, args):
if node == null:
return null
render_to_viewport(node, render_size, "do_precalculate_texture", [ object, method, args ])
func precalculate_shader(shader, textures, render_size, target_texture, object, method, args):
render_shader_to_viewport(shader, textures, render_size, "do_precalculate_texture", [ target_texture, object, method, args ])
func do_precalculate_texture(target_texture, object, method, args):
var viewport_texture = get_texture()
target_texture.create_from_image(viewport_texture.get_data())
object.callv(method, args)

View File

@ -1,34 +0,0 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://addons/material_maker/renderer.gd" type="Script" id=1]
[sub_resource type="Shader" id=1]
code = "shader_type canvas_item;
void fragment() {
COLOR = vec4(1.0);
}
"
[sub_resource type="ShaderMaterial" id=2]
shader = SubResource( 1 )
[node name="Renderer" type="Viewport"]
own_world = true
transparent_bg = true
msaa = 2
hdr = false
render_target_v_flip = true
render_target_update_mode = 1
gui_disable_input = true
script = ExtResource( 1 )
debug_path = null
[node name="ColorRect" type="ColorRect" parent="."]
material = SubResource( 2 )
margin_right = 40.0
margin_bottom = 40.0
[node name="Timer" type="Timer" parent="."]
wait_time = 0.1
one_shot = true