Update 2D shader and SDF demos

This commit is contained in:
Aaron Franke
2020-02-03 03:53:07 -05:00
parent b0e1cc0227
commit 87f42b77e0
18 changed files with 59 additions and 70 deletions

View File

@@ -1,24 +1,23 @@
extends Control
func _ready():
for c in $pictures.get_children():
$picture.add_item("PIC: " + c.get_name())
for c in get_node("effects").get_children():
$effect.add_item("FX: " + c.get_name())
for c in $Pictures.get_children():
$Picture.add_item("PIC: " + c.get_name())
for c in $Effects.get_children():
$Effect.add_item("FX: " + c.get_name())
func _on_picture_item_selected(ID):
for c in range($pictures.get_child_count()):
for c in range($Pictures.get_child_count()):
if ID == c:
$pictures.get_child(c).show()
$Pictures.get_child(c).show()
else:
$pictures.get_child(c).hide()
$Pictures.get_child(c).hide()
func _on_effect_item_selected(ID):
for c in range($effects.get_child_count()):
for c in range($Effects.get_child_count()):
if ID == c:
$effects.get_child(c).show()
$Effects.get_child(c).show()
else:
$effects.get_child(c).hide()
$Effects.get_child(c).hide()

View File

@@ -71,27 +71,27 @@ shader_param/flashing = 0.01
shader_param/grain = ExtResource( 19 )
shader_param/vignette = ExtResource( 7 )
[node name="Control" type="Control"]
[node name="ScreenShaders" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 2
size_flags_vertical = 2
script = ExtResource( 1 )
[node name="pictures" type="Control" parent="."]
[node name="Pictures" type="Control" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 2
size_flags_vertical = 2
[node name="burano" type="TextureRect" parent="pictures"]
[node name="Burano" type="TextureRect" parent="Pictures"]
margin_right = 40.0
margin_bottom = 40.0
size_flags_horizontal = 2
size_flags_vertical = 2
texture = ExtResource( 2 )
[node name="roby" type="TextureRect" parent="pictures"]
[node name="Roby" type="TextureRect" parent="Pictures"]
visible = false
margin_right = 40.0
margin_bottom = 40.0
@@ -99,7 +99,7 @@ size_flags_horizontal = 2
size_flags_vertical = 2
texture = ExtResource( 3 )
[node name="mountains" type="TextureRect" parent="pictures"]
[node name="Mountains" type="TextureRect" parent="Pictures"]
visible = false
margin_right = 40.0
margin_bottom = 40.0
@@ -107,7 +107,7 @@ size_flags_horizontal = 2
size_flags_vertical = 2
texture = ExtResource( 4 )
[node name="forest" type="TextureRect" parent="pictures"]
[node name="Forest" type="TextureRect" parent="Pictures"]
visible = false
margin_right = 40.0
margin_bottom = 40.0
@@ -115,20 +115,20 @@ size_flags_horizontal = 2
size_flags_vertical = 2
texture = ExtResource( 5 )
[node name="effects" type="Control" parent="."]
[node name="Effects" type="Control" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 2
size_flags_vertical = 2
[node name="disabled" type="Control" parent="effects"]
[node name="Disabled" type="Control" parent="Effects"]
visible = false
margin_right = 40.0
margin_bottom = 40.0
size_flags_horizontal = 2
size_flags_vertical = 2
[node name="vignette" type="TextureRect" parent="effects"]
[node name="Vignette" type="TextureRect" parent="Effects"]
visible = false
material = SubResource( 1 )
anchor_right = 1.0
@@ -138,7 +138,7 @@ size_flags_vertical = 2
texture = ExtResource( 8 )
expand = true
[node name="blur" type="TextureRect" parent="effects"]
[node name="Blur" type="TextureRect" parent="Effects"]
visible = false
material = SubResource( 2 )
anchor_right = 1.0
@@ -148,7 +148,7 @@ size_flags_vertical = 2
texture = ExtResource( 8 )
expand = true
[node name="pixelize" type="TextureRect" parent="effects"]
[node name="Pixelize" type="TextureRect" parent="Effects"]
visible = false
material = SubResource( 3 )
anchor_right = 1.0
@@ -158,7 +158,7 @@ size_flags_vertical = 2
texture = ExtResource( 8 )
expand = true
[node name="whirl" type="TextureRect" parent="effects"]
[node name="Whirl" type="TextureRect" parent="Effects"]
visible = false
material = SubResource( 4 )
anchor_right = 1.0
@@ -168,7 +168,7 @@ size_flags_vertical = 2
texture = ExtResource( 8 )
expand = true
[node name="sepia" type="TextureRect" parent="effects"]
[node name="Sepia" type="TextureRect" parent="Effects"]
visible = false
material = SubResource( 5 )
anchor_right = 1.0
@@ -180,7 +180,7 @@ size_flags_vertical = 2
texture = ExtResource( 8 )
expand = true
[node name="negative" type="TextureRect" parent="effects"]
[node name="Negative" type="TextureRect" parent="Effects"]
visible = false
material = SubResource( 6 )
anchor_right = 1.0
@@ -190,7 +190,7 @@ size_flags_vertical = 2
texture = ExtResource( 8 )
expand = true
[node name="contrasted" type="TextureRect" parent="effects"]
[node name="Contrasted" type="TextureRect" parent="Effects"]
visible = false
material = SubResource( 7 )
anchor_right = 1.0
@@ -200,7 +200,7 @@ size_flags_vertical = 2
texture = ExtResource( 8 )
expand = true
[node name="normalized" type="TextureRect" parent="effects"]
[node name="Normalized" type="TextureRect" parent="Effects"]
visible = false
material = SubResource( 8 )
anchor_right = 1.0
@@ -210,7 +210,7 @@ size_flags_vertical = 2
texture = ExtResource( 8 )
expand = true
[node name="BCS" type="TextureRect" parent="effects"]
[node name="BCS" type="TextureRect" parent="Effects"]
visible = false
material = SubResource( 9 )
anchor_right = 1.0
@@ -222,7 +222,7 @@ size_flags_vertical = 2
texture = ExtResource( 8 )
expand = true
[node name="mirage" type="TextureRect" parent="effects"]
[node name="Mirage" type="TextureRect" parent="Effects"]
visible = false
material = SubResource( 10 )
anchor_right = 1.0
@@ -232,7 +232,7 @@ size_flags_vertical = 2
texture = ExtResource( 8 )
expand = true
[node name="old_film" type="TextureRect" parent="effects"]
[node name="OldFilm" type="TextureRect" parent="Effects"]
visible = false
material = SubResource( 11 )
anchor_right = 1.0
@@ -244,7 +244,7 @@ size_flags_vertical = 2
texture = ExtResource( 8 )
expand = true
[node name="picture" type="OptionButton" parent="."]
[node name="Picture" type="OptionButton" parent="."]
margin_left = 8.0
margin_top = 7.0
margin_right = 131.0
@@ -252,12 +252,12 @@ margin_bottom = 28.0
size_flags_horizontal = 2
size_flags_vertical = 2
[node name="effect" type="OptionButton" parent="."]
[node name="Effect" type="OptionButton" parent="."]
margin_left = 137.0
margin_top = 7.0
margin_right = 260.0
margin_bottom = 28.0
size_flags_horizontal = 2
size_flags_vertical = 2
[connection signal="item_selected" from="picture" to="." method="_on_picture_item_selected"]
[connection signal="item_selected" from="effect" to="." method="_on_effect_item_selected"]
[connection signal="item_selected" from="Picture" to="." method="_on_picture_item_selected"]
[connection signal="item_selected" from="Effect" to="." method="_on_effect_item_selected"]

View File

@@ -5,7 +5,6 @@ uniform float contrast = 1.5;
uniform float saturation = 1.8;
void fragment() {
vec3 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;
c.rgb = mix(vec3(0.0), c.rgb, brightness);

View File

@@ -1,8 +1,7 @@
shader_type canvas_item;
uniform float amount : hint_range(0.0, 5.0);
uniform float amount: hint_range(0.0, 5.0);
void fragment() {
COLOR.rgb = textureLod(SCREEN_TEXTURE, SCREEN_UV, amount).rgb;
}

View File

@@ -1,7 +1,6 @@
shader_type canvas_item;
void fragment() {
vec3 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;
c = mod(c + vec3(0.5), vec3(1.0));
COLOR.rgb = c;

View File

@@ -4,7 +4,6 @@ uniform float frequency = 60;
uniform float depth = 0.005;
void fragment() {
vec2 uv = SCREEN_UV;
uv.x += sin(uv.y * frequency + TIME) * depth;
uv.x = clamp(uv.x, 0.0, 1.0);

View File

@@ -1,7 +1,6 @@
shader_type canvas_item;
void fragment() {
vec3 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;
c = vec3(1.0) - c;
COLOR.rgb = c;

View File

@@ -1,6 +1,6 @@
shader_type canvas_item;
uniform vec4 base : hint_color;
uniform vec4 base: hint_color;
uniform sampler2D grain;
uniform float grain_strength = 0.3;
uniform sampler2D vignette;
@@ -9,7 +9,6 @@ uniform float stretch = 0.5;
uniform float flashing = 0.01;
float make_grain(float time, vec2 uv) {
vec2 ofs = vec2(sin(41.0 * time * sin(time * 123.0)), sin(27.0 * time * sin(time * 312.0)));
return texture(grain, (uv + mod(ofs, vec2(1.0, 1.0))) * stretch).r;
}

View File

@@ -4,11 +4,7 @@ uniform vec4 base : hint_color;
void fragment() {
vec3 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;
//float v = max(c.r, max(c.g, c.b));
float v = dot(c, vec3(0.33333, 0.33333, 0.33333));
v = sqrt(v);
//v *= v;
COLOR.rgb = base.rgb * v;
}

View File

@@ -4,7 +4,7 @@ uniform sampler2D vignette;
void fragment() {
vec3 vignette_color = texture(vignette, UV).rgb;
// Screen texture stores gaussian blurred copies on mipmaps
// Screen texture stores gaussian blurred copies on mipmaps.
COLOR.rgb = textureLod(SCREEN_TEXTURE, SCREEN_UV, (1.0 - vignette_color.r) * 4.0).rgb;
COLOR.rgb *= texture(vignette, UV).rgb;
}

View File

@@ -16,7 +16,7 @@ _global_script_class_icons={
[application]
config/name="Signed Distance Field Font Demo"
run/main_scene="res://sdf.tscn"
run/main_scene="res://sdf_font_demo.tscn"
config/icon="res://icon.png"
[display]

View File

@@ -34,21 +34,21 @@ tracks/0/keys = {
"values": [ Vector2( 1, 1 ), Vector2( 7, 7 ) ]
}
[node name="Root Node" type="Node2D"]
[node name="SDFFontDemo" type="Node2D"]
[node name="base" type="Position2D" parent="."]
[node name="Base" type="Position2D" parent="."]
position = Vector2( 500, 300 )
[node name="rotate" type="AnimationPlayer" parent="base"]
[node name="Rotate" type="AnimationPlayer" parent="Base"]
autoplay = "rotate"
anims/rotate = SubResource( 1 )
anims/zoomin_zoomout = SubResource( 2 )
[node name="zoom" type="AnimationPlayer" parent="base"]
[node name="Zoom" type="AnimationPlayer" parent="Base"]
autoplay = "zoomin_zoomout"
anims/zoomin_zoomout = SubResource( 2 )
[node name="Label" type="Label" parent="base"]
[node name="Label" type="Label" parent="Base"]
margin_left = -169.0
margin_top = -49.0
margin_right = 172.0

View File

@@ -1,9 +1,9 @@
shader_type canvas_item;
render_mode blend_premul_alpha;
// This shader only works properly with premultiplied alpha blend mode
// This shader only works properly with premultiplied alpha blend mode.
uniform float aura_width = 2.0;
uniform vec4 aura_color : hint_color;
uniform vec4 aura_color: hint_color;
void fragment() {
vec4 col = texture(TEXTURE, UV);

View File

@@ -2,7 +2,7 @@ shader_type canvas_item;
render_mode blend_mix;
uniform float radius = 5.0;
uniform vec4 modulate : hint_color;
uniform vec4 modulate: hint_color;
void fragment() {
vec2 ps = TEXTURE_PIXEL_SIZE;

View File

@@ -6,7 +6,7 @@ uniform float fattyness = 2.0;
void fragment() {
vec2 ruv = UV - vec2(0.5, 0.5);
vec2 dir = normalize(ruv);
float len = length(ruv);
float len = length(ruv);
len = pow(len * 2.0, fattyness) * 0.5;
ruv = len * dir;

View File

@@ -1,7 +1,7 @@
shader_type canvas_item;
uniform float outline_width = 2.0;
uniform vec4 outline_color : hint_color;
uniform vec4 outline_color: hint_color;
void fragment() {
vec4 col = texture(TEXTURE, UV);

View File

@@ -1,7 +1,7 @@
shader_type canvas_item;
render_mode blend_mix;
uniform vec4 modulate : hint_color;
uniform vec4 modulate: hint_color;
void fragment() {
COLOR = vec4(modulate.rgb, texture(TEXTURE, UV).a * modulate.a);

View File

@@ -59,57 +59,57 @@ shader_param/amount = 0.5
shader = ExtResource( 10 )
shader_param/amount = 4.0
[node name="shaders" type="Node2D"]
[node name="SpriteShaders" type="Node2D"]
material = SubResource( 1 )
position = Vector2( 263.737, 179.444 )
scale = Vector2( 0.3, 0.3 )
[node name="normal" type="Sprite" parent="."]
[node name="Normal" type="Sprite" parent="."]
material = SubResource( 2 )
position = Vector2( -2.16144, 0 )
texture = ExtResource( 2 )
[node name="outline" type="Sprite" parent="."]
[node name="Outline" type="Sprite" parent="."]
material = SubResource( 3 )
position = Vector2( 400, 0 )
texture = ExtResource( 2 )
[node name="aura" type="Sprite" parent="."]
[node name="Aura" type="Sprite" parent="."]
material = SubResource( 4 )
position = Vector2( 800, 0 )
texture = ExtResource( 2 )
[node name="blur" type="Sprite" parent="."]
[node name="Blur" type="Sprite" parent="."]
material = SubResource( 5 )
position = Vector2( 1200, 0 )
texture = ExtResource( 2 )
[node name="fatty" type="Sprite" parent="."]
[node name="Fatty" type="Sprite" parent="."]
material = SubResource( 6 )
position = Vector2( 1600, 0 )
texture = ExtResource( 2 )
[node name="dropshadow" type="Sprite" parent="."]
[node name="DropShadow" type="Sprite" parent="."]
material = SubResource( 7 )
position = Vector2( 0, 800 )
texture = ExtResource( 2 )
[node name="offsetshadow" type="Sprite" parent="."]
[node name="OffsetShadow" type="Sprite" parent="."]
material = SubResource( 8 )
position = Vector2( 400, 800 )
texture = ExtResource( 2 )
[node name="silouette" type="Sprite" parent="."]
[node name="Silouette" type="Sprite" parent="."]
material = SubResource( 9 )
position = Vector2( 800, 800 )
texture = ExtResource( 2 )
[node name="glow" type="Sprite" parent="."]
[node name="Glow" type="Sprite" parent="."]
material = SubResource( 10 )
position = Vector2( 1200, 800 )
texture = ExtResource( 2 )
[node name="dissintegrate" type="Sprite" parent="."]
[node name="Disintegrate" type="Sprite" parent="."]
material = SubResource( 11 )
position = Vector2( 1600, 800 )
texture = ExtResource( 2 )