Refactored 2D preview and updated its shader

This commit is contained in:
RodZill4 2020-02-12 08:15:40 +01:00
parent 93f6407c2f
commit 8d9a086ba2
2 changed files with 125 additions and 101 deletions

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=18 format=2]
[gd_scene load_steps=22 format=2]
[ext_resource path="res://material_maker/main_window.gd" type="Script" id=1]
[ext_resource path="res://material_maker/library.tscn" type="PackedScene" id=2]
@ -11,8 +11,19 @@
[ext_resource path="res://material_maker/node_factory.gd" type="Script" id=9]
[ext_resource path="res://material_maker/theme/default.tres" type="Theme" id=10]
[ext_resource path="res://material_maker/preview/preview_2d.gd" type="Script" id=11]
[ext_resource path="res://material_maker/preview/control_point.tscn" type="PackedScene" id=12]
[sub_resource type="Shader" id=1]
[sub_resource type="AtlasTexture" id=1]
flags = 4
atlas = ExtResource( 8 )
region = Rect2( 64, 48, 32, 32 )
[sub_resource type="AtlasTexture" id=2]
flags = 4
atlas = ExtResource( 8 )
region = Rect2( 16, 64, 16, 16 )
[sub_resource type="Shader" id=3]
code = "shader_type canvas_item;
uniform sampler2D tex;
@ -25,27 +36,31 @@ void fragment() {
vec4 image = texture(tex, uv);
vec3 image_with_background = mix(vec3(mod(floor(uv.x*32.0)+floor(uv.y*32.0), 2.0)), image.xyz, image.a);
float lines_color = 0.5*(cos(5.0*TIME+100.0*(UV.x+UV.y))+1.0);
COLOR = vec4(mix(image_with_background, vec3(lines_color), step(min(m2.x, m2.y), 1.0/min(size.x, size.y))), 1.0);
COLOR = vec4(mix(image_with_background, vec3(lines_color), step(min(m2.x*size.x, m2.y*size.y), 1.0)), 1.0);
}"
[sub_resource type="ShaderMaterial" id=2]
shader = SubResource( 1 )
[sub_resource type="ShaderMaterial" id=4]
shader = SubResource( 3 )
shader_param/size = Vector2( 947, 682 )
[sub_resource type="ShaderMaterial" id=5]
shader = SubResource( 3 )
shader_param/size = Vector2( 721, 546 )
[sub_resource type="AtlasTexture" id=3]
[sub_resource type="AtlasTexture" id=6]
flags = 4
atlas = ExtResource( 8 )
region = Rect2( 96, 96, 32, 32 )
[sub_resource type="AtlasTexture" id=4]
[sub_resource type="AtlasTexture" id=7]
flags = 4
atlas = ExtResource( 8 )
region = Rect2( 96, 32, 32, 32 )
[sub_resource type="StyleBoxFlat" id=5]
[sub_resource type="StyleBoxFlat" id=8]
bg_color = Color( 0, 0, 0, 0.772549 )
[sub_resource type="AtlasTexture" id=6]
[sub_resource type="AtlasTexture" id=9]
flags = 4
atlas = ExtResource( 8 )
region = Rect2( 96, 64, 32, 31 )
@ -148,6 +163,79 @@ margin_right = -5.0
margin_bottom = -5.0
rect_min_size = Vector2( 250, 250 )
[node name="P1" parent="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview2D" instance=ExtResource( 12 )]
visible = false
self_modulate = Color( 1, 0.466667, 0, 1 )
margin_right = 32.0
margin_bottom = 32.0
texture = SubResource( 1 )
[node name="P2" parent="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview2D" instance=ExtResource( 12 )]
visible = false
self_modulate = Color( 0, 0.505882, 1, 1 )
margin_right = 32.0
margin_bottom = 32.0
texture = SubResource( 1 )
[node name="Rect1" parent="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview2D" instance=ExtResource( 12 )]
visible = false
self_modulate = Color( 1, 0.631373, 0, 1 )
margin_right = 16.0
margin_bottom = 16.0
texture = SubResource( 2 )
parent_control = "P1"
control_type = 1
[node name="Radius1" parent="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview2D" instance=ExtResource( 12 )]
visible = false
self_modulate = Color( 1, 0.631373, 0, 1 )
margin_right = 16.0
margin_bottom = 16.0
mouse_default_cursor_shape = 10
texture = SubResource( 2 )
parent_control = "P1"
control_type = 2
[node name="Radius11" parent="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview2D" instance=ExtResource( 12 )]
visible = false
self_modulate = Color( 1, 0.631373, 0, 1 )
margin_right = 16.0
margin_bottom = 16.0
mouse_default_cursor_shape = 10
texture = SubResource( 2 )
parent_control = "Radius1"
control_type = 2
[node name="Scale1" parent="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview2D" instance=ExtResource( 12 )]
visible = false
self_modulate = Color( 1, 0.631373, 0, 1 )
margin_right = 16.0
margin_bottom = 16.0
mouse_default_cursor_shape = 10
texture = SubResource( 2 )
parent_control = "P1"
control_type = 3
[node name="Angle1" parent="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview2D" instance=ExtResource( 12 )]
visible = false
self_modulate = Color( 1, 0.631373, 0, 1 )
margin_right = 16.0
margin_bottom = 16.0
mouse_default_cursor_shape = 10
texture = SubResource( 2 )
parent_control = "P1"
control_type = 2
[node name="Angle2" parent="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview2D" instance=ExtResource( 12 )]
visible = false
self_modulate = Color( 1, 0.631373, 0, 1 )
margin_right = 16.0
margin_bottom = 16.0
mouse_default_cursor_shape = 10
texture = SubResource( 2 )
parent_control = "P1"
control_type = 2
[node name="Preview3D" parent="VBoxContainer/HBoxContainer/VBoxContainer/Preview" instance=ExtResource( 4 )]
margin_left = 5.0
margin_top = 29.0
@ -167,7 +255,22 @@ size_flags_stretch_ratio = 3.0
[node name="Preview2D" type="ColorRect" parent="VBoxContainer/HBoxContainer/ProjectsPane"]
visible = false
material = SubResource( 2 )
material = SubResource( 4 )
anchor_right = 1.0
anchor_bottom = 1.0
rect_min_size = Vector2( 64, 64 )
rect_clip_content = true
mouse_filter = 1
size_flags_horizontal = 0
size_flags_vertical = 8
script = ExtResource( 11 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Preview2D_old" type="ColorRect" parent="VBoxContainer/HBoxContainer/ProjectsPane"]
visible = false
material = SubResource( 5 )
anchor_right = 1.0
anchor_bottom = 1.0
rect_min_size = Vector2( 64, 64 )
@ -226,7 +329,7 @@ margin_right = 44.0
margin_bottom = 40.0
hint_tooltip = "Show 2D preview"
toggle_mode = true
icon = SubResource( 3 )
icon = SubResource( 6 )
[node name="Preview3DButton" type="Button" parent="VBoxContainer/HBoxContainer/ProjectsPane/PreviewUI"]
margin_left = 51.0
@ -234,7 +337,7 @@ margin_right = 95.0
margin_bottom = 40.0
hint_tooltip = "Show 3D preview"
toggle_mode = true
icon = SubResource( 4 )
icon = SubResource( 7 )
[node name="Panel" type="PanelContainer" parent="VBoxContainer/HBoxContainer/ProjectsPane/PreviewUI"]
visible = false
@ -242,7 +345,7 @@ self_modulate = Color( 1, 1, 1, 0.768627 )
margin_left = 102.0
margin_right = 399.0
margin_bottom = 40.0
custom_styles/panel = SubResource( 5 )
custom_styles/panel = SubResource( 8 )
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/HBoxContainer/ProjectsPane/PreviewUI/Panel"]
margin_right = 297.0
@ -261,7 +364,7 @@ margin_top = 4.0
margin_right = 37.0
margin_bottom = 35.0
size_flags_vertical = 4
texture = SubResource( 6 )
texture = SubResource( 9 )
[node name="Preview3DUI" parent="VBoxContainer/HBoxContainer/ProjectsPane/PreviewUI/Panel/HBoxContainer" instance=ExtResource( 5 )]
anchor_right = 0.0
@ -282,6 +385,7 @@ script = ExtResource( 9 )
[connection signal="environment_selected" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D/Preview3DUI" to="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D" method="_on_Environment_item_selected"]
[connection signal="model_selected" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D/Preview3DUI" to="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D" method="_on_Model_item_selected"]
[connection signal="rotate_toggled" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D/Preview3DUI" to="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D" method="_on_Rotate_toggled"]
[connection signal="resized" from="VBoxContainer/HBoxContainer/ProjectsPane/Preview2D" to="VBoxContainer/HBoxContainer/ProjectsPane/Preview2D" method="on_resized"]
[connection signal="need_update" from="VBoxContainer/HBoxContainer/ProjectsPane/Preview3D" to="." method="update_preview_3d"]
[connection signal="no_more_tabs" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects" to="." method="new_material"]
[connection signal="resized" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects" method="_on_Projects_resized"]

View File

@ -1,8 +1,6 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=4 format=2]
[ext_resource path="res://material_maker/preview/preview_2d.gd" type="Script" id=1]
[ext_resource path="res://material_maker/preview/control_point.tscn" type="PackedScene" id=2]
[ext_resource path="res://material_maker/icons/icons.svg" type="Texture" id=3]
[sub_resource type="Shader" id=1]
code = "shader_type canvas_item;
@ -13,33 +11,24 @@ uniform vec2 size;
void fragment() {
float ms = max(size.x, size.y);
vec2 uv = fract(0.5+1.2*(UV-vec2(0.5))*ms/size.yx);
float is = min(size.x, size.y)/1.2;
vec2 m2 = min(fract(uv), 1.0-fract(uv));
vec4 image = texture(tex, uv);
vec3 image_with_background = mix(vec3(mod(floor(uv.x*32.0)+floor(uv.y*32.0), 2.0)), image.xyz, image.a);
float lines_color = 0.5*(cos(5.0*TIME+100.0*(UV.x+UV.y))+1.0);
COLOR = vec4(mix(image_with_background, vec3(lines_color), step(min(m2.x, m2.y), 1.0/min(size.x, size.y))), 1.0);
float lines_color = 0.5*(cos(5.0*TIME+100.0*(uv.x+uv.y))+1.0);
COLOR = vec4(mix(image_with_background, vec3(lines_color), step(is*min(m2.x, m2.y), 1.0)), 1.0);
}"
[sub_resource type="ShaderMaterial" id=2]
shader = SubResource( 1 )
shader_param/size = Vector2( 721, 546 )
[sub_resource type="AtlasTexture" id=3]
flags = 4
atlas = ExtResource( 3 )
region = Rect2( 64, 48, 32, 32 )
[sub_resource type="AtlasTexture" id=4]
flags = 4
atlas = ExtResource( 3 )
region = Rect2( 16, 64, 16, 16 )
shader_param/size = Vector2( 585, 492 )
[node name="Preview2D" type="ColorRect"]
material = SubResource( 2 )
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = -559.0
margin_bottom = -174.0
margin_right = -695.0
margin_bottom = -228.0
rect_min_size = Vector2( 64, 64 )
rect_clip_content = true
mouse_filter = 1
@ -49,73 +38,4 @@ script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="P1" parent="." instance=ExtResource( 2 )]
visible = false
self_modulate = Color( 1, 0.466667, 0, 1 )
texture = SubResource( 3 )
[node name="P2" parent="." instance=ExtResource( 2 )]
visible = false
self_modulate = Color( 0, 0.505882, 1, 1 )
texture = SubResource( 3 )
[node name="Rect1" parent="." instance=ExtResource( 2 )]
visible = false
self_modulate = Color( 1, 0.631373, 0, 1 )
margin_right = 16.0
margin_bottom = 16.0
texture = SubResource( 4 )
parent_control = "P1"
control_type = 1
[node name="Radius1" parent="." instance=ExtResource( 2 )]
visible = false
self_modulate = Color( 1, 0.631373, 0, 1 )
margin_right = 16.0
margin_bottom = 16.0
mouse_default_cursor_shape = 10
texture = SubResource( 4 )
parent_control = "P1"
control_type = 2
[node name="Radius11" parent="." instance=ExtResource( 2 )]
visible = false
self_modulate = Color( 1, 0.631373, 0, 1 )
margin_right = 16.0
margin_bottom = 16.0
mouse_default_cursor_shape = 10
texture = SubResource( 4 )
parent_control = "Radius1"
control_type = 2
[node name="Scale1" parent="." instance=ExtResource( 2 )]
visible = false
self_modulate = Color( 1, 0.631373, 0, 1 )
margin_right = 16.0
margin_bottom = 16.0
mouse_default_cursor_shape = 10
texture = SubResource( 4 )
parent_control = "P1"
control_type = 3
[node name="Angle1" parent="." instance=ExtResource( 2 )]
visible = false
self_modulate = Color( 1, 0.631373, 0, 1 )
margin_right = 16.0
margin_bottom = 16.0
mouse_default_cursor_shape = 10
texture = SubResource( 4 )
parent_control = "P1"
control_type = 2
[node name="Angle2" parent="." instance=ExtResource( 2 )]
visible = false
self_modulate = Color( 1, 0.631373, 0, 1 )
margin_right = 16.0
margin_bottom = 16.0
mouse_default_cursor_shape = 10
texture = SubResource( 4 )
parent_control = "P1"
control_type = 2
[connection signal="resized" from="." to="." method="on_resized"]