diff --git a/addons/material_maker/main_window.tscn b/addons/material_maker/main_window.tscn index d3ad15d..356b3b6 100644 --- a/addons/material_maker/main_window.tscn +++ b/addons/material_maker/main_window.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=13 format=2] +[gd_scene load_steps=11 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] @@ -9,18 +9,6 @@ [ext_resource path="res://addons/material_maker/icons/icons.svg" type="Texture" id=7] [ext_resource path="res://addons/material_maker/node_factory.gd" type="Script" id=8] -[sub_resource type="Shader" id=1] -code = "shader_type canvas_item; - -uniform sampler2D tex; - -void fragment() { - COLOR = texture(tex, UV); -}" - -[sub_resource type="ShaderMaterial" id=2] -shader = SubResource( 1 ) - [sub_resource type="AtlasTexture" id=3] flags = 4 atlas = ExtResource( 7 ) @@ -111,7 +99,10 @@ margin_bottom = 684.0 tab_align = 0 [node name="Preview2D" parent="VBoxContainer/HBoxContainer/VBoxContainer/Preview" instance=ExtResource( 3 )] -material = SubResource( 2 ) +margin_left = 4.0 +margin_top = 32.0 +margin_right = -4.0 +margin_bottom = -4.0 rect_min_size = Vector2( 250, 250 ) [node name="Preview3D" parent="VBoxContainer/HBoxContainer/VBoxContainer/Preview" instance=ExtResource( 4 )] diff --git a/addons/material_maker/preview/preview_2d.gd b/addons/material_maker/preview/preview_2d.gd index 1cba73f..f687363 100644 --- a/addons/material_maker/preview/preview_2d.gd +++ b/addons/material_maker/preview/preview_2d.gd @@ -1,7 +1,8 @@ +tool extends ColorRect -func _ready() -> void: - material = material.duplicate(true) - func set_preview_texture(tex: Texture) -> void: material.set_shader_param("tex", tex) + +func on_resized() -> void: + material.set_shader_param("size", rect_size) diff --git a/addons/material_maker/preview/preview_2d.tscn b/addons/material_maker/preview/preview_2d.tscn index 3073c0f..3302b2e 100644 --- a/addons/material_maker/preview/preview_2d.tscn +++ b/addons/material_maker/preview/preview_2d.tscn @@ -6,24 +6,30 @@ code = "shader_type canvas_item; uniform sampler2D tex; +uniform vec2 size; void fragment() { - COLOR = texture(tex, UV); + float ms = max(size.x, size.y); + vec2 uv = fract(0.5+1.2*(UV-vec2(0.5))*ms/size.yx); + vec2 m2 = min(fract(uv), 1.0-fract(uv)); + COLOR = mix(texture(tex, uv), vec4(0.0, 1.0, 0.0, 1.0), step(min(m2.x, m2.y), 1.0/min(size.x, size.y))); }" [sub_resource type="ShaderMaterial" id=2] shader = SubResource( 1 ) +shader_param/size = Vector2( 371, 198 ) [node name="Preview2D" type="ColorRect"] material = SubResource( 2 ) anchor_right = 1.0 anchor_bottom = 1.0 -margin_left = 4.0 -margin_top = 32.0 -margin_right = -4.0 -margin_bottom = -4.0 +margin_left = 17.0 +margin_top = 17.0 +margin_right = -892.0 +margin_bottom = -505.0 rect_min_size = Vector2( 64, 64 ) mouse_filter = 1 size_flags_horizontal = 0 size_flags_vertical = 8 script = ExtResource( 1 ) +[connection signal="resized" from="." to="." method="on_resized"]