[gd_scene load_steps=5 format=2]

[ext_resource path="res://material_maker/panels/preview_2d/preview_2d.tscn" type="PackedScene" id=1]
[ext_resource path="res://material_maker/panels/preview_2d/preview_2d_node.gd" type="Script" id=2]

[sub_resource type="Shader" id=1]
resource_local_to_scene = true

[sub_resource type="ShaderMaterial" id=2]
resource_local_to_scene = true
shader = SubResource( 1 )

[node name="Preview2D" instance=ExtResource( 1 )]
material = SubResource( 2 )
mouse_filter = 0
script = ExtResource( 2 )
shader = "uniform vec2 size;

void fragment() {
	float ms = max(size.x, size.y);
	vec2 uv = 0.5+(UV-vec2(0.5))*ms/size.yx;
	float is = min(size.x, size.y);
	vec4 image = preview_2d(uv);
	vec3 image_with_background = mix(vec3(mod(floor(uv.x*32.0)+floor(uv.y*32.0), 2.0)), image.xyz, image.a);
	uv -= vec2(0.5);
	uv = abs(uv);
	COLOR = vec4(image_with_background, step(max(uv.x, uv.y), 0.5)*0.8+0.2);
}"

[node name="ContextMenu" type="PopupMenu" parent="." index="0"]
margin_right = 109.0
margin_bottom = 52.0

[node name="Export" type="PopupMenu" parent="ContextMenu" index="1"]
margin_right = 91.0
margin_bottom = 88.0

[node name="Reference" type="PopupMenu" parent="ContextMenu" index="2"]
margin_right = 91.0
margin_bottom = 88.0
[connection signal="gui_input" from="." to="." method="_on_gui_input"]
[connection signal="id_pressed" from="ContextMenu/Export" to="." method="_on_Export_id_pressed"]
[connection signal="id_pressed" from="ContextMenu/Reference" to="." method="_on_Reference_id_pressed"]
