Added alternate 2D preview modes (clamp and repeat) and softened the background cherckerboard pattern
This commit is contained in:
parent
daca08cd21
commit
0bc7c62d3d
|
@ -6,16 +6,23 @@ export(String, MULTILINE) var shader_divide : String = ""
|
|||
var center : Vector2 = Vector2(0.5, 0.5)
|
||||
var scale : float = 1.2
|
||||
|
||||
var view_mode : int = 0
|
||||
|
||||
var temporal_aa : bool = false
|
||||
var temporal_aa_current : bool = false
|
||||
|
||||
|
||||
func _ready():
|
||||
update_shader_options()
|
||||
update_view_menu()
|
||||
update_axes_menu()
|
||||
update_export_menu()
|
||||
$ContextMenu.add_check_item("Temporal AA", MENU_TEMPORAL_AA)
|
||||
$ContextMenu.set_item_checked(MENU_TEMPORAL_AA, temporal_aa)
|
||||
|
||||
func update_view_menu() -> void:
|
||||
$ContextMenu.add_submenu_item("View", "View")
|
||||
|
||||
func update_axes_menu() -> void:
|
||||
$ContextMenu/Axes.clear()
|
||||
for s in $Axes.STYLES:
|
||||
|
@ -41,6 +48,9 @@ func update_material(source):
|
|||
start_accumulate()
|
||||
else:
|
||||
.update_material(source)
|
||||
material.set_shader_param("mode", view_mode)
|
||||
material.set_shader_param("background_color_1", Color(0.4, 0.4, 0.4))
|
||||
material.set_shader_param("background_color_2", Color(0.6, 0.6, 0.6))
|
||||
|
||||
var started : bool = false
|
||||
var divide : int = 0
|
||||
|
@ -191,6 +201,10 @@ func _on_ContextMenu_id_pressed(id) -> void:
|
|||
_:
|
||||
print("unsupported id "+str(id))
|
||||
|
||||
func _on_View_id_pressed(id):
|
||||
view_mode = id
|
||||
material.set_shader_param("mode", view_mode)
|
||||
|
||||
func _on_Axes_id_pressed(id):
|
||||
if id == 1000:
|
||||
var color_picker_popup = preload("res://material_maker/widgets/color_picker_popup/color_picker_popup.tscn").instance()
|
||||
|
|
|
@ -45,14 +45,24 @@ script = ExtResource( 4 )
|
|||
shader = "uniform vec2 preview_2d_size = vec2(100.0);
|
||||
uniform float preview_2d_scale = 1.2;
|
||||
uniform vec2 preview_2d_center = vec2(0.5);
|
||||
uniform int mode = 0;
|
||||
uniform vec4 background_color_1 = vec4(0.0);
|
||||
uniform vec4 background_color_2 = vec4(1.0);
|
||||
|
||||
void fragment() {
|
||||
vec2 ratio = preview_2d_size;
|
||||
vec2 uv = preview_2d_center+(UV-0.5)*preview_2d_scale*ratio/min(ratio.x, ratio.y);
|
||||
vec4 image = preview_2d(uv);
|
||||
float checkerboard = mod(floor(uv.x*32.0)+floor(uv.y*32.0), 2.0);
|
||||
vec3 image_with_background = mix(vec3(checkerboard), image.xyz, image.a);
|
||||
COLOR = vec4(image_with_background, 1.0);
|
||||
if (mode == 2 && (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0)) {
|
||||
COLOR = vec4(0.5);
|
||||
} else {
|
||||
if (mode == 1) {
|
||||
uv = fract(uv);
|
||||
}
|
||||
vec4 image = preview_2d(uv);
|
||||
float checkerboard = mod(floor(uv.x*32.0)+floor(uv.y*32.0), 2.0);
|
||||
vec3 image_with_background = mix(mix(background_color_1, background_color_2, checkerboard).rgb, image.rgb, image.a);
|
||||
COLOR = vec4(image_with_background, 1.0);
|
||||
}
|
||||
}
|
||||
"
|
||||
shader_accumulate = "uniform sampler2D sum;
|
||||
|
@ -193,15 +203,20 @@ margin_right = 109.0
|
|||
margin_bottom = 52.0
|
||||
items = [ "Reset view", null, 0, false, false, 0, 0, null, "", false ]
|
||||
|
||||
[node name="Axes" type="PopupMenu" parent="ContextMenu" index="1"]
|
||||
[node name="View" type="PopupMenu" parent="ContextMenu" index="0"]
|
||||
margin_right = 91.0
|
||||
margin_bottom = 88.0
|
||||
items = [ "Extend", null, 0, false, false, 0, 0, null, "", false, "Repeat", null, 0, false, false, 1, 0, null, "", false, "Clamp", null, 0, false, false, 2, 0, null, "", false ]
|
||||
|
||||
[node name="Axes" type="PopupMenu" parent="ContextMenu" index="2"]
|
||||
margin_right = 91.0
|
||||
margin_bottom = 88.0
|
||||
|
||||
[node name="Export" type="PopupMenu" parent="ContextMenu" index="2"]
|
||||
[node name="Export" type="PopupMenu" parent="ContextMenu" index="3"]
|
||||
margin_right = 91.0
|
||||
margin_bottom = 88.0
|
||||
|
||||
[node name="Reference" type="PopupMenu" parent="ContextMenu" index="3"]
|
||||
[node name="Reference" type="PopupMenu" parent="ContextMenu" index="4"]
|
||||
margin_right = 91.0
|
||||
margin_bottom = 88.0
|
||||
|
||||
|
@ -222,6 +237,7 @@ margin_bottom = 40.0
|
|||
|
||||
[connection signal="gui_input" from="." to="." method="_on_gui_input"]
|
||||
[connection signal="id_pressed" from="ContextMenu" to="." method="_on_ContextMenu_id_pressed"]
|
||||
[connection signal="id_pressed" from="ContextMenu/View" to="." method="_on_View_id_pressed"]
|
||||
[connection signal="id_pressed" from="ContextMenu/Axes" to="." method="_on_Axes_id_pressed"]
|
||||
[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"]
|
||||
|
|
Loading…
Reference in New Issue