Browse Source

Extract shader code from 2D shader demos

Roberto Proença 6 years ago
parent
commit
36c9ecdfa8

+ 61 - 222
2d/screen_space_shaders/screen_shaders.tscn

@@ -5,232 +5,71 @@
 [ext_resource path="res://art/platformer.jpg" type="Texture" id=3]
 [ext_resource path="res://art/mountains.jpg" type="Texture" id=4]
 [ext_resource path="res://art/forest.jpg" type="Texture" id=5]
-[ext_resource path="res://art/vignette.png" type="Texture" id=6]
-[ext_resource path="res://art/white.png" type="Texture" id=7]
-[ext_resource path="res://art/filmgrain.png" type="Texture" id=8]
-
-[sub_resource type="Shader" id=1]
-code = "shader_type canvas_item;
-
-uniform sampler2D vignette;
-
-void fragment() {
-	vec3 vignette_color = texture(vignette, UV).rgb;
-	// 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;
-}"
+[ext_resource path="res://shaders/vignette.shader" type="Shader" id=6]
+[ext_resource path="res://art/vignette.png" type="Texture" id=7]
+[ext_resource path="res://art/white.png" type="Texture" id=8]
+[ext_resource path="res://shaders/blur.shader" type="Shader" id=9]
+[ext_resource path="res://shaders/pixelize.shader" type="Shader" id=10]
+[ext_resource path="res://shaders/whirl.shader" type="Shader" id=11]
+[ext_resource path="res://shaders/sepia.shader" type="Shader" id=12]
+[ext_resource path="res://shaders/negative.shader" type="Shader" id=13]
+[ext_resource path="res://shaders/contrasted.shader" type="Shader" id=14]
+[ext_resource path="res://shaders/normalized.shader" type="Shader" id=15]
+[ext_resource path="res://shaders/BCS.shader" type="Shader" id=16]
+[ext_resource path="res://shaders/mirage.shader" type="Shader" id=17]
+[ext_resource path="res://shaders/old_film.shader" type="Shader" id=18]
+[ext_resource path="res://art/filmgrain.png" type="Texture" id=19]
+
+[sub_resource type="ShaderMaterial" id=1]
+shader = ExtResource( 6 )
+shader_param/vignette = ExtResource( 7 )
 
 [sub_resource type="ShaderMaterial" id=2]
-shader = SubResource( 1 )
-shader_param/vignette = ExtResource( 6 )
-
-[sub_resource type="Shader" id=3]
-code = "shader_type canvas_item;
-
-uniform float amount : hint_range(0.0, 5.0);
-
-void fragment() {
-
-	COLOR.rgb = textureLod(SCREEN_TEXTURE, SCREEN_UV, amount).rgb;
-}"
-
-[sub_resource type="ShaderMaterial" id=4]
-shader = SubResource( 3 )
+shader = ExtResource( 9 )
 shader_param/amount = 4.0
 
-[sub_resource type="Shader" id=5]
-code = "shader_type canvas_item;
-
-uniform float size_x = 0.008;
-uniform float size_y = 0.008;
-
-void fragment() {
-	vec2 uv = SCREEN_UV;
-	uv -= mod(uv, vec2(size_x, size_y));
-	
-	COLOR.rgb = textureLod(SCREEN_TEXTURE, uv, 0.0).rgb;
-}
-"
-
-[sub_resource type="ShaderMaterial" id=6]
-shader = SubResource( 5 )
+[sub_resource type="ShaderMaterial" id=3]
+shader = ExtResource( 10 )
 shader_param/size_x = 0.008
 shader_param/size_y = 0.008
 
-[sub_resource type="Shader" id=7]
-code = "shader_type canvas_item;
-
-uniform float rotation = 3.0;
-
-void fragment() {
-	vec2 uv = SCREEN_UV;
-	vec2 rel = uv - vec2(0.5, 0.5);
-	float angle = length(rel) * rotation;
-	mat2 rot = mat2(vec2(cos(angle), -sin(angle)), vec2(sin(angle), cos(angle)));
-	rel = rot * rel;
-	uv = clamp(rel + vec2(0.5,0.5), vec2(0.0, 0.0), vec2(1.0, 1.0));
-	COLOR.rgb = textureLod(SCREEN_TEXTURE, uv, 0.0).rgb;
-}
-"
-
-[sub_resource type="ShaderMaterial" id=8]
-shader = SubResource( 7 )
+[sub_resource type="ShaderMaterial" id=4]
+shader = ExtResource( 11 )
 shader_param/rotation = 3.0
 
-[sub_resource type="Shader" id=9]
-code = "shader_type canvas_item;
-
-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;
-
-}"
-
-[sub_resource type="ShaderMaterial" id=10]
-shader = SubResource( 9 )
+[sub_resource type="ShaderMaterial" id=5]
+shader = ExtResource( 12 )
 shader_param/base = Color( 0.54451, 0.408353, 0.403137, 1 )
 
-[sub_resource type="Shader" id=11]
-code = "shader_type canvas_item;
-
-void fragment() {
-
-	vec3 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;
-	c = vec3(1.0) - c;
-	COLOR.rgb = c;
-}
-"
-
-[sub_resource type="ShaderMaterial" id=12]
-shader = SubResource( 11 )
-
-[sub_resource type="Shader" id=13]
-code = "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;
-}
-"
-
-[sub_resource type="ShaderMaterial" id=14]
-shader = SubResource( 13 )
-
-[sub_resource type="Shader" id=15]
-code = "shader_type canvas_item;
-
-void fragment() {
-	vec3 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;
-	COLOR.rgb = normalize(c);
-}
-"
-
-[sub_resource type="ShaderMaterial" id=16]
-shader = SubResource( 15 )
-
-[sub_resource type="Shader" id=17]
-code = "shader_type canvas_item;
-
-uniform float brightness = 0.8;
-uniform float contrast = 1.5;
-uniform float saturation = 1.8;
+[sub_resource type="ShaderMaterial" id=6]
+shader = ExtResource( 13 )
 
-void fragment() {
+[sub_resource type="ShaderMaterial" id=7]
+shader = ExtResource( 14 )
 
-	vec3 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;
-	
-	c.rgb = mix(vec3(0.0), c.rgb, brightness);
-	c.rgb = mix(vec3(0.5), c.rgb, contrast);
-	c.rgb = mix(vec3(dot(vec3(1.0), c.rgb) * 0.33333), c.rgb, saturation);
-	
-	COLOR.rgb = c;
-}
-"
+[sub_resource type="ShaderMaterial" id=8]
+shader = ExtResource( 15 )
 
-[sub_resource type="ShaderMaterial" id=18]
-shader = SubResource( 17 )
+[sub_resource type="ShaderMaterial" id=9]
+shader = ExtResource( 16 )
 shader_param/brightness = 0.8
 shader_param/contrast = 1.5
 shader_param/saturation = 1.8
 
-[sub_resource type="Shader" id=19]
-code = "shader_type canvas_item;
-
-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);
-	vec3 c = textureLod(SCREEN_TEXTURE, uv, 0.0).rgb;
-	
-	COLOR.rgb = c;
-}
-"
-
-[sub_resource type="ShaderMaterial" id=20]
-shader = SubResource( 19 )
+[sub_resource type="ShaderMaterial" id=10]
+shader = ExtResource( 17 )
 shader_param/frequency = 60.0
 shader_param/depth = 0.005
 
-[sub_resource type="Shader" id=21]
-code = "shader_type canvas_item;
-
-uniform vec4 base : hint_color;
-uniform sampler2D grain;
-uniform float grain_strength = 0.3;
-uniform sampler2D vignette;
-uniform float fps = 12.0;
-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;
-}
-
-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;
-	
-	float f = 1.0 / fps;
-	float g = make_grain(TIME - mod(TIME, f), UV);
-	g = max(g, make_grain(TIME - mod(TIME, f) + f, UV) * 0.5);
-	g = max(g, make_grain(TIME - mod(TIME, f) + f * 2.0, UV) * 0.25);
-	
-	COLOR.rgb = base.rgb * v - vec3(g) * grain_strength;
-	COLOR.rgb *= texture(vignette, UV).r;
-	float ft = TIME * 0.002;
-	COLOR.rgb += vec3(sin(75.0 * ft * sin(ft * 123.0))) * flashing;
-}
-"
-
-[sub_resource type="ShaderMaterial" id=22]
-shader = SubResource( 21 )
+[sub_resource type="ShaderMaterial" id=11]
+shader = ExtResource( 18 )
 shader_param/base = Color( 0.450274, 0.361255, 0.335059, 1 )
 shader_param/grain_strength = 0.3
 shader_param/fps = 12
 shader_param/stretch = 0.5
 shader_param/flashing = 0.01
-shader_param/grain = ExtResource( 8 )
-shader_param/vignette = ExtResource( 6 )
+shader_param/grain = ExtResource( 19 )
+shader_param/vignette = ExtResource( 7 )
 
 [node name="Control" type="Control"]
 anchor_right = 1.0
@@ -291,118 +130,118 @@ size_flags_vertical = 2
 
 [node name="vignette" type="TextureRect" parent="effects"]
 visible = false
-material = SubResource( 2 )
+material = SubResource( 1 )
 anchor_right = 1.0
 anchor_bottom = 1.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
-texture = ExtResource( 7 )
+texture = ExtResource( 8 )
 expand = true
 
 [node name="blur" type="TextureRect" parent="effects"]
 visible = false
-material = SubResource( 4 )
+material = SubResource( 2 )
 anchor_right = 1.0
 anchor_bottom = 1.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
-texture = ExtResource( 7 )
+texture = ExtResource( 8 )
 expand = true
 
 [node name="pixelize" type="TextureRect" parent="effects"]
 visible = false
-material = SubResource( 6 )
+material = SubResource( 3 )
 anchor_right = 1.0
 anchor_bottom = 1.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
-texture = ExtResource( 7 )
+texture = ExtResource( 8 )
 expand = true
 
 [node name="whirl" type="TextureRect" parent="effects"]
 visible = false
-material = SubResource( 8 )
+material = SubResource( 4 )
 anchor_right = 1.0
 anchor_bottom = 1.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
-texture = ExtResource( 7 )
+texture = ExtResource( 8 )
 expand = true
 
 [node name="sepia" type="TextureRect" parent="effects"]
 visible = false
-material = SubResource( 10 )
+material = SubResource( 5 )
 anchor_right = 1.0
 anchor_bottom = 1.0
 margin_right = 14.0
 margin_bottom = -2.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
-texture = ExtResource( 7 )
+texture = ExtResource( 8 )
 expand = true
 
 [node name="negative" type="TextureRect" parent="effects"]
 visible = false
-material = SubResource( 12 )
+material = SubResource( 6 )
 anchor_right = 1.0
 anchor_bottom = 1.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
-texture = ExtResource( 7 )
+texture = ExtResource( 8 )
 expand = true
 
 [node name="contrasted" type="TextureRect" parent="effects"]
 visible = false
-material = SubResource( 14 )
+material = SubResource( 7 )
 anchor_right = 1.0
 anchor_bottom = 1.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
-texture = ExtResource( 7 )
+texture = ExtResource( 8 )
 expand = true
 
 [node name="normalized" type="TextureRect" parent="effects"]
 visible = false
-material = SubResource( 16 )
+material = SubResource( 8 )
 anchor_right = 1.0
 anchor_bottom = 1.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
-texture = ExtResource( 7 )
+texture = ExtResource( 8 )
 expand = true
 
 [node name="BCS" type="TextureRect" parent="effects"]
 visible = false
-material = SubResource( 18 )
+material = SubResource( 9 )
 anchor_right = 1.0
 anchor_bottom = 1.0
 margin_top = 3.0
 margin_bottom = -3.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
-texture = ExtResource( 7 )
+texture = ExtResource( 8 )
 expand = true
 
 [node name="mirage" type="TextureRect" parent="effects"]
 visible = false
-material = SubResource( 20 )
+material = SubResource( 10 )
 anchor_right = 1.0
 anchor_bottom = 1.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
-texture = ExtResource( 7 )
+texture = ExtResource( 8 )
 expand = true
 
 [node name="old_film" type="TextureRect" parent="effects"]
 visible = false
-material = SubResource( 22 )
+material = SubResource( 11 )
 anchor_right = 1.0
 anchor_bottom = 1.0
 margin_left = -3.0
 margin_right = 3.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
-texture = ExtResource( 7 )
+texture = ExtResource( 8 )
 expand = true
 
 [node name="picture" type="OptionButton" parent="."]

+ 16 - 0
2d/screen_space_shaders/shaders/BCS.shader

@@ -0,0 +1,16 @@
+shader_type canvas_item;
+
+uniform float brightness = 0.8;
+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);
+	c.rgb = mix(vec3(0.5), c.rgb, contrast);
+	c.rgb = mix(vec3(dot(vec3(1.0), c.rgb) * 0.33333), c.rgb, saturation);
+	
+	COLOR.rgb = c;
+}

+ 8 - 0
2d/screen_space_shaders/shaders/blur.shader

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

+ 8 - 0
2d/screen_space_shaders/shaders/contrasted.shader

@@ -0,0 +1,8 @@
+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;
+}

+ 14 - 0
2d/screen_space_shaders/shaders/mirage.shader

@@ -0,0 +1,14 @@
+shader_type canvas_item;
+
+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);
+	vec3 c = textureLod(SCREEN_TEXTURE, uv, 0.0).rgb;
+	
+	COLOR.rgb = c;
+}

+ 8 - 0
2d/screen_space_shaders/shaders/negative.shader

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

+ 6 - 0
2d/screen_space_shaders/shaders/normalized.shader

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

+ 34 - 0
2d/screen_space_shaders/shaders/old_film.shader

@@ -0,0 +1,34 @@
+shader_type canvas_item;
+
+uniform vec4 base : hint_color;
+uniform sampler2D grain;
+uniform float grain_strength = 0.3;
+uniform sampler2D vignette;
+uniform float fps = 12.0;
+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;
+}
+
+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;
+	
+	float f = 1.0 / fps;
+	float g = make_grain(TIME - mod(TIME, f), UV);
+	g = max(g, make_grain(TIME - mod(TIME, f) + f, UV) * 0.5);
+	g = max(g, make_grain(TIME - mod(TIME, f) + f * 2.0, UV) * 0.25);
+	
+	COLOR.rgb = base.rgb * v - vec3(g) * grain_strength;
+	COLOR.rgb *= texture(vignette, UV).r;
+	float ft = TIME * 0.002;
+	COLOR.rgb += vec3(sin(75.0 * ft * sin(ft * 123.0))) * flashing;
+}

+ 11 - 0
2d/screen_space_shaders/shaders/pixelize.shader

@@ -0,0 +1,11 @@
+shader_type canvas_item;
+
+uniform float size_x = 0.008;
+uniform float size_y = 0.008;
+
+void fragment() {
+	vec2 uv = SCREEN_UV;
+	uv -= mod(uv, vec2(size_x, size_y));
+	
+	COLOR.rgb = textureLod(SCREEN_TEXTURE, uv, 0.0).rgb;
+}

+ 14 - 0
2d/screen_space_shaders/shaders/sepia.shader

@@ -0,0 +1,14 @@
+shader_type canvas_item;
+
+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;
+
+}

+ 10 - 0
2d/screen_space_shaders/shaders/vignette.shader

@@ -0,0 +1,10 @@
+shader_type canvas_item;
+
+uniform sampler2D vignette;
+
+void fragment() {
+	vec3 vignette_color = texture(vignette, UV).rgb;
+	// 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;
+}

+ 13 - 0
2d/screen_space_shaders/shaders/whirl.shader

@@ -0,0 +1,13 @@
+shader_type canvas_item;
+
+uniform float rotation = 3.0;
+
+void fragment() {
+	vec2 uv = SCREEN_UV;
+	vec2 rel = uv - vec2(0.5, 0.5);
+	float angle = length(rel) * rotation;
+	mat2 rot = mat2(vec2(cos(angle), -sin(angle)), vec2(sin(angle), cos(angle)));
+	rel = rot * rel;
+	uv = clamp(rel + vec2(0.5,0.5), vec2(0.0, 0.0), vec2(1.0, 1.0));
+	COLOR.rgb = textureLod(SCREEN_TEXTURE, uv, 0.0).rgb;
+}

+ 35 - 0
2d/sprite_shaders/shaders/aura.shader

@@ -0,0 +1,35 @@
+shader_type canvas_item;
+render_mode blend_premul_alpha;
+
+// This shader only works properly with premultiplied alpha blend mode
+uniform float aura_width = 2.0;
+uniform vec4 aura_color : hint_color;
+
+void fragment() {
+	vec4 col = texture(TEXTURE, UV);
+	vec2 ps = TEXTURE_PIXEL_SIZE;
+	float a;
+	float maxa = col.a;
+	float mina = col.a;
+
+	a = texture(TEXTURE, UV + vec2(0.0, -aura_width) * ps).a;
+	maxa = max(a, maxa);
+	mina = min(a, mina);
+
+	a = texture(TEXTURE, UV + vec2(0.0, aura_width) * ps).a;
+	maxa = max(a, maxa);
+	mina = min(a, mina);
+
+	a = texture(TEXTURE, UV + vec2(-aura_width, 0.0) * ps).a;
+	maxa = max(a, maxa);
+	mina = min(a, mina);
+
+	a = texture(TEXTURE, UV + vec2(aura_width, 0.0) * ps).a;
+	maxa = max(a, maxa);
+	mina = min(a, mina);
+
+	col.rgb *= col.a;
+
+	COLOR = col;
+	COLOR.rgb += aura_color.rgb * (maxa - mina);
+}

+ 17 - 0
2d/sprite_shaders/shaders/blur.shader

@@ -0,0 +1,17 @@
+shader_type canvas_item;
+render_mode blend_mix;
+
+uniform float radius = 4.0;
+
+void fragment() {
+	vec4 col = texture(TEXTURE, UV);
+	vec2 ps = TEXTURE_PIXEL_SIZE;
+
+	col += texture(TEXTURE, UV + vec2(0.0, -radius) * ps);
+	col += texture(TEXTURE, UV + vec2(0.0, radius) * ps);
+	col += texture(TEXTURE, UV + vec2(-radius, 0.0) * ps);
+	col += texture(TEXTURE, UV + vec2(radius, 0.0) * ps);
+	col /= 5.0;
+
+	COLOR = col;
+}

+ 14 - 0
2d/sprite_shaders/shaders/dissintegrate.shader

@@ -0,0 +1,14 @@
+shader_type canvas_item;
+render_mode blend_mix;
+
+uniform float amount = 20.0;
+
+void fragment() {
+	vec2 uv = UV * 0.05;
+	float a = fract(sin(dot(UV, vec2(12.9898, 78.233))) * 438.5453);
+	vec4 col = texture(TEXTURE, UV);
+
+	col.a *= pow(a, amount);
+
+	COLOR = col;
+}

+ 24 - 0
2d/sprite_shaders/shaders/dropshadow.shader

@@ -0,0 +1,24 @@
+shader_type canvas_item;
+render_mode blend_mix;
+
+uniform float radius = 5.0;
+uniform vec4  modulate : hint_color;
+
+void fragment() {
+	vec2 ps = TEXTURE_PIXEL_SIZE;
+
+	vec4 shadow = texture(TEXTURE, UV + vec2(-radius, -radius) * ps);
+
+	shadow += texture(TEXTURE, UV + vec2(-radius, 0.0) * ps);
+	shadow += texture(TEXTURE, UV + vec2(-radius, radius) * ps);
+	shadow += texture(TEXTURE, UV + vec2(0.0, -radius) * ps);
+	shadow += texture(TEXTURE, UV + vec2(0.0, radius) * ps);
+	shadow += texture(TEXTURE, UV + vec2(radius, -radius) * ps);
+	shadow += texture(TEXTURE, UV + vec2(radius, 0.0) * ps);
+	shadow += texture(TEXTURE, UV + vec2(radius, radius) * ps);
+	shadow /= 8.0;
+	shadow *= modulate;
+
+	vec4 col = texture(TEXTURE, UV);
+	COLOR = mix(shadow, col, col.a);
+}

+ 17 - 0
2d/sprite_shaders/shaders/fatty.shader

@@ -0,0 +1,17 @@
+shader_type canvas_item;
+
+render_mode blend_mix;
+uniform float fattyness = 2.0;
+
+void fragment() {
+	vec2 ruv = UV - vec2(0.5, 0.5);
+	vec2 dir = normalize(ruv);
+	float len = length(ruv);	
+
+	len = pow(len * 2.0, fattyness) * 0.5;
+	ruv = len * dir;
+
+	vec4 col = texture(TEXTURE, ruv + vec2(0.5, 0.5));
+
+	COLOR = col;
+}

+ 37 - 0
2d/sprite_shaders/shaders/glow.shader

@@ -0,0 +1,37 @@
+shader_type canvas_item;
+render_mode blend_premul_alpha;
+
+uniform float radius = 2.0;
+uniform float amount = 0.6;
+
+void fragment() {
+	float r = radius;
+	vec2 ps = TEXTURE_PIXEL_SIZE;
+	vec4 col = texture(TEXTURE, UV);
+	vec4 glow = col;
+
+	glow += texture(TEXTURE, UV + vec2(-r, -r) * ps);
+	glow += texture(TEXTURE, UV + vec2(-r, 0.0) * ps);
+	glow += texture(TEXTURE, UV + vec2(-r, r) * ps);
+	glow += texture(TEXTURE, UV + vec2(0.0, -r) * ps);
+	glow += texture(TEXTURE, UV + vec2(0.0, r) * ps);
+	glow += texture(TEXTURE, UV + vec2(r, -r) * ps);
+	glow += texture(TEXTURE, UV + vec2(r, 0.0) * ps);
+	glow += texture(TEXTURE, UV + vec2(r, r) * ps);
+
+	r *= 2.0;
+	glow += texture(TEXTURE, UV + vec2(-r, -r) * ps);
+	glow += texture(TEXTURE, UV + vec2(-r, 0.0) * ps);
+	glow += texture(TEXTURE, UV + vec2(-r, r) * ps);
+	glow += texture(TEXTURE, UV + vec2(0.0, -r) * ps);
+	glow += texture(TEXTURE, UV + vec2(0.0, r) * ps);
+	glow += texture(TEXTURE, UV + vec2(r, -r) * ps);
+	glow += texture(TEXTURE, UV + vec2(r, 0.0) * ps);
+	glow += texture(TEXTURE, UV + vec2(r, r) * ps);
+
+	glow /= 17.0;
+	glow *= amount;
+	col.rgb *= col.a;
+
+	COLOR = glow + col;
+}

+ 14 - 0
2d/sprite_shaders/shaders/offsetshadow.shader

@@ -0,0 +1,14 @@
+shader_type canvas_item;
+render_mode blend_mix;
+
+uniform vec2 offset = vec2(8.0, 8.0);
+uniform vec4 modulate : hint_color;
+
+void fragment() {
+	vec2 ps = TEXTURE_PIXEL_SIZE;
+
+	vec4 shadow = vec4(modulate.rgb, texture(TEXTURE, UV - offset * ps).a * modulate.a);
+	vec4 col = texture(TEXTURE, UV);
+
+	COLOR = mix(shadow, col, col.a);
+}

+ 30 - 0
2d/sprite_shaders/shaders/outline.shader

@@ -0,0 +1,30 @@
+shader_type canvas_item;
+
+uniform float outline_width = 2.0;
+uniform vec4 outline_color : hint_color;
+
+void fragment() {
+	vec4 col = texture(TEXTURE, UV);
+	vec2 ps = TEXTURE_PIXEL_SIZE;
+	float a;
+	float maxa = col.a;
+	float mina = col.a;
+
+	a = texture(TEXTURE, UV + vec2(0.0, -outline_width) * ps).a;
+	maxa = max(a, maxa);
+	mina = min(a, mina);
+
+	a = texture(TEXTURE, UV + vec2(0.0, outline_width) * ps).a;
+	maxa = max(a, maxa);
+	mina = min(a, mina);
+
+	a = texture(TEXTURE, UV + vec2(-outline_width, 0.0) * ps).a;
+	maxa = max(a, maxa);
+	mina = min(a, mina);
+
+	a = texture(TEXTURE, UV + vec2(outline_width, 0.0) * ps).a;
+	maxa = max(a, maxa);
+	mina = min(a, mina);
+
+	COLOR = mix(col, outline_color, maxa - mina);
+}

+ 8 - 0
2d/sprite_shaders/shaders/silouette.shader

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

+ 53 - 258
2d/sprite_shaders/sprite_shaders.tscn

@@ -1,322 +1,117 @@
 [gd_scene load_steps=22 format=2]
 
-[ext_resource path="res://godotea.png" type="Texture" id=1]
-
-[sub_resource type="Shader" id=1]
-code = "shader_type canvas_item;
-
-uniform float outline_width = 2.0;
-uniform vec4 outline_color : hint_color;
-
-void fragment() {
-	vec4 col = texture(TEXTURE, UV);
-	vec2 ps = TEXTURE_PIXEL_SIZE;
-	float a;
-	float maxa = col.a;
-	float mina = col.a;
-
-	a = texture(TEXTURE, UV + vec2(0.0, -outline_width) * ps).a;
-	maxa = max(a, maxa);
-	mina = min(a, mina);
-
-	a = texture(TEXTURE, UV + vec2(0.0, outline_width) * ps).a;
-	maxa = max(a, maxa);
-	mina = min(a, mina);
-
-	a = texture(TEXTURE, UV + vec2(-outline_width, 0.0) * ps).a;
-	maxa = max(a, maxa);
-	mina = min(a, mina);
-
-	a = texture(TEXTURE, UV + vec2(outline_width, 0.0) * ps).a;
-	maxa = max(a, maxa);
-	mina = min(a, mina);
-
-	COLOR = mix(col, outline_color, maxa - mina);
-}"
-
-[sub_resource type="ShaderMaterial" id=2]
-shader = SubResource( 1 )
+[ext_resource path="res://shaders/outline.shader" type="Shader" id=1]
+[ext_resource path="res://godotea.png" type="Texture" id=2]
+[ext_resource path="res://shaders/aura.shader" type="Shader" id=3]
+[ext_resource path="res://shaders/blur.shader" type="Shader" id=4]
+[ext_resource path="res://shaders/fatty.shader" type="Shader" id=5]
+[ext_resource path="res://shaders/dropshadow.shader" type="Shader" id=6]
+[ext_resource path="res://shaders/offsetshadow.shader" type="Shader" id=7]
+[ext_resource path="res://shaders/silouette.shader" type="Shader" id=8]
+[ext_resource path="res://shaders/glow.shader" type="Shader" id=9]
+[ext_resource path="res://shaders/dissintegrate.shader" type="Shader" id=10]
+
+[sub_resource type="ShaderMaterial" id=1]
+shader = ExtResource( 1 )
 shader_param/outline_width = 2.0
 shader_param/outline_color = Color( 0, 1, 0.109375, 1 )
 
-[sub_resource type="ShaderMaterial" id=3]
+[sub_resource type="ShaderMaterial" id=2]
 
-[sub_resource type="ShaderMaterial" id=4]
-shader = SubResource( 1 )
+[sub_resource type="ShaderMaterial" id=3]
+shader = ExtResource( 1 )
 shader_param/outline_width = 4.0
 shader_param/outline_color = Color( 0, 0, 0, 1 )
 
-[sub_resource type="Shader" id=5]
-code = "shader_type canvas_item;
-render_mode blend_premul_alpha;
-
-// This shader only works properly with premultiplied alpha blend mode
-uniform float aura_width = 2.0;
-uniform vec4 aura_color : hint_color;
-
-void fragment() {
-	vec4 col = texture(TEXTURE, UV);
-	vec2 ps = TEXTURE_PIXEL_SIZE;
-	float a;
-	float maxa = col.a;
-	float mina = col.a;
-
-	a = texture(TEXTURE, UV + vec2(0.0, -aura_width) * ps).a;
-	maxa = max(a, maxa);
-	mina = min(a, mina);
-
-	a = texture(TEXTURE, UV + vec2(0.0, aura_width) * ps).a;
-	maxa = max(a, maxa);
-	mina = min(a, mina);
-
-	a = texture(TEXTURE, UV + vec2(-aura_width, 0.0) * ps).a;
-	maxa = max(a, maxa);
-	mina = min(a, mina);
-
-	a = texture(TEXTURE, UV + vec2(aura_width, 0.0) * ps).a;
-	maxa = max(a, maxa);
-	mina = min(a, mina);
-
-	col.rgb *= col.a;
-
-	COLOR = col;
-	COLOR.rgb += aura_color.rgb * (maxa - mina);
-}"
-
-[sub_resource type="ShaderMaterial" id=6]
-shader = SubResource( 5 )
+[sub_resource type="ShaderMaterial" id=4]
+shader = ExtResource( 3 )
 shader_param/aura_width = 6.0
 shader_param/aura_color = Color( 0.143326, 0.33235, 0.677765, 0.442 )
 
-[sub_resource type="Shader" id=7]
-code = "shader_type canvas_item;
-render_mode blend_mix;
-
-uniform float radius = 4.0;
-
-void fragment() {
-	vec4 col = texture(TEXTURE, UV);
-	vec2 ps = TEXTURE_PIXEL_SIZE;
-
-	col += texture(TEXTURE, UV + vec2(0.0, -radius) * ps);
-	col += texture(TEXTURE, UV + vec2(0.0, radius) * ps);
-	col += texture(TEXTURE, UV + vec2(-radius, 0.0) * ps);
-	col += texture(TEXTURE, UV + vec2(radius, 0.0) * ps);
-	col /= 5.0;
-
-	COLOR = col;
-}"
-
-[sub_resource type="ShaderMaterial" id=8]
-shader = SubResource( 7 )
+[sub_resource type="ShaderMaterial" id=5]
+shader = ExtResource( 4 )
 shader_param/radius = 4.0
 
-[sub_resource type="Shader" id=9]
-code = "shader_type canvas_item;
-
-render_mode blend_mix;
-uniform float fattyness = 2.0;
-
-void fragment() {
-	vec2 ruv = UV - vec2(0.5, 0.5);
-	vec2 dir = normalize(ruv);
-	float len = length(ruv);	
-
-	len = pow(len * 2.0, fattyness) * 0.5;
-	ruv = len * dir;
-
-	vec4 col = texture(TEXTURE, ruv + vec2(0.5, 0.5));
-
-	COLOR = col;
-}"
-
-[sub_resource type="ShaderMaterial" id=10]
-shader = SubResource( 9 )
+[sub_resource type="ShaderMaterial" id=6]
+shader = ExtResource( 5 )
 shader_param/fattyness = 3.0
 
-[sub_resource type="Shader" id=11]
-code = "shader_type canvas_item;
-render_mode blend_mix;
-
-uniform float radius = 5.0;
-uniform vec4  modulate : hint_color;
-
-void fragment() {
-	vec2 ps = TEXTURE_PIXEL_SIZE;
-
-	vec4 shadow = texture(TEXTURE, UV + vec2(-radius, -radius) * ps);
-
-	shadow += texture(TEXTURE, UV + vec2(-radius, 0.0) * ps);
-	shadow += texture(TEXTURE, UV + vec2(-radius, radius) * ps);
-	shadow += texture(TEXTURE, UV + vec2(0.0, -radius) * ps);
-	shadow += texture(TEXTURE, UV + vec2(0.0, radius) * ps);
-	shadow += texture(TEXTURE, UV + vec2(radius, -radius) * ps);
-	shadow += texture(TEXTURE, UV + vec2(radius, 0.0) * ps);
-	shadow += texture(TEXTURE, UV + vec2(radius, radius) * ps);
-	shadow /= 8.0;
-	shadow *= modulate;
-
-	vec4 col = texture(TEXTURE, UV);
-	COLOR = mix(shadow, col, col.a);
-}"
-
-[sub_resource type="ShaderMaterial" id=12]
-shader = SubResource( 11 )
+[sub_resource type="ShaderMaterial" id=7]
+shader = ExtResource( 6 )
 shader_param/radius = 8.0
 shader_param/modulate = Color( 0, 0, 0, 0.501961 )
 
-[sub_resource type="Shader" id=13]
-code = "shader_type canvas_item;
-render_mode blend_mix;
-
-uniform vec2 offset = vec2(8.0, 8.0);
-uniform vec4 modulate : hint_color;
-
-void fragment() {
-	vec2 ps = TEXTURE_PIXEL_SIZE;
-
-	vec4 shadow = vec4(modulate.rgb, texture(TEXTURE, UV - offset * ps).a * modulate.a);
-	vec4 col = texture(TEXTURE, UV);
-
-	COLOR = mix(shadow, col, col.a);
-}"
-
-[sub_resource type="ShaderMaterial" id=14]
-shader = SubResource( 13 )
+[sub_resource type="ShaderMaterial" id=8]
+shader = ExtResource( 7 )
 shader_param/offset = Vector2( 20, 20 )
 shader_param/modulate = Color( 0.90625, 0.269043, 0.746948, 1 )
 
-[sub_resource type="Shader" id=15]
-code = "shader_type canvas_item;
-
-render_mode blend_mix;
-uniform vec4 modulate : hint_color;
-
-void fragment() {
-	COLOR = vec4(modulate.rgb, texture(TEXTURE, UV).a * modulate.a);
-}"
-
-[sub_resource type="ShaderMaterial" id=16]
-shader = SubResource( 15 )
+[sub_resource type="ShaderMaterial" id=9]
+shader = ExtResource( 8 )
 shader_param/modulate = Color( 1, 0.0234375, 0.481201, 0.596706 )
 
-[sub_resource type="Shader" id=17]
-code = "shader_type canvas_item;
-render_mode blend_premul_alpha;
-
-uniform float radius = 2.0;
-uniform float amount = 0.6;
-
-void fragment() {
-	float r = radius;
-	vec2 ps = TEXTURE_PIXEL_SIZE;
-	vec4 col = texture(TEXTURE, UV);
-	vec4 glow = col;
-
-	glow += texture(TEXTURE, UV + vec2(-r, -r) * ps);
-	glow += texture(TEXTURE, UV + vec2(-r, 0.0) * ps);
-	glow += texture(TEXTURE, UV + vec2(-r, r) * ps);
-	glow += texture(TEXTURE, UV + vec2(0.0, -r) * ps);
-	glow += texture(TEXTURE, UV + vec2(0.0, r) * ps);
-	glow += texture(TEXTURE, UV + vec2(r, -r) * ps);
-	glow += texture(TEXTURE, UV + vec2(r, 0.0) * ps);
-	glow += texture(TEXTURE, UV + vec2(r, r) * ps);
-
-	r *= 2.0;
-	glow += texture(TEXTURE, UV + vec2(-r, -r) * ps);
-	glow += texture(TEXTURE, UV + vec2(-r, 0.0) * ps);
-	glow += texture(TEXTURE, UV + vec2(-r, r) * ps);
-	glow += texture(TEXTURE, UV + vec2(0.0, -r) * ps);
-	glow += texture(TEXTURE, UV + vec2(0.0, r) * ps);
-	glow += texture(TEXTURE, UV + vec2(r, -r) * ps);
-	glow += texture(TEXTURE, UV + vec2(r, 0.0) * ps);
-	glow += texture(TEXTURE, UV + vec2(r, r) * ps);
-
-	glow /= 17.0;
-	glow *= amount;
-	col.rgb *= col.a;
-
-	COLOR = glow + col;
-}"
-
-[sub_resource type="ShaderMaterial" id=18]
-shader = SubResource( 17 )
+[sub_resource type="ShaderMaterial" id=10]
+shader = ExtResource( 9 )
 shader_param/radius = 12.0
 shader_param/amount = 0.5
 
-[sub_resource type="Shader" id=19]
-code = "shader_type canvas_item;
-render_mode blend_mix;
-
-uniform float amount = 20.0;
-
-void fragment() {
-	vec2 uv = UV * 0.05;
-	float a = fract(sin(dot(UV, vec2(12.9898, 78.233))) * 438.5453);
-	vec4 col = texture(TEXTURE, UV);
-
-	col.a *= pow(a, amount);
-
-	COLOR = col;
-}"
-
-[sub_resource type="ShaderMaterial" id=20]
-shader = SubResource( 19 )
+[sub_resource type="ShaderMaterial" id=11]
+shader = ExtResource( 10 )
 shader_param/amount = 4.0
 
 [node name="shaders" type="Node2D"]
-material = SubResource( 2 )
+material = SubResource( 1 )
 position = Vector2( 263.737, 179.444 )
 scale = Vector2( 0.3, 0.3 )
 
 [node name="normal" type="Sprite" parent="."]
-material = SubResource( 3 )
+material = SubResource( 2 )
 position = Vector2( -2.16144, 0 )
-texture = ExtResource( 1 )
+texture = ExtResource( 2 )
 
 [node name="outline" type="Sprite" parent="."]
-material = SubResource( 4 )
+material = SubResource( 3 )
 position = Vector2( 400, 0 )
-texture = ExtResource( 1 )
+texture = ExtResource( 2 )
 
 [node name="aura" type="Sprite" parent="."]
-material = SubResource( 6 )
+material = SubResource( 4 )
 position = Vector2( 800, 0 )
-texture = ExtResource( 1 )
+texture = ExtResource( 2 )
 
 [node name="blur" type="Sprite" parent="."]
-material = SubResource( 8 )
+material = SubResource( 5 )
 position = Vector2( 1200, 0 )
-texture = ExtResource( 1 )
+texture = ExtResource( 2 )
 
 [node name="fatty" type="Sprite" parent="."]
-material = SubResource( 10 )
+material = SubResource( 6 )
 position = Vector2( 1600, 0 )
-texture = ExtResource( 1 )
+texture = ExtResource( 2 )
 
 [node name="dropshadow" type="Sprite" parent="."]
-material = SubResource( 12 )
+material = SubResource( 7 )
 position = Vector2( 0, 800 )
-texture = ExtResource( 1 )
+texture = ExtResource( 2 )
 
 [node name="offsetshadow" type="Sprite" parent="."]
-material = SubResource( 14 )
+material = SubResource( 8 )
 position = Vector2( 400, 800 )
-texture = ExtResource( 1 )
+texture = ExtResource( 2 )
 
 [node name="silouette" type="Sprite" parent="."]
-material = SubResource( 16 )
+material = SubResource( 9 )
 position = Vector2( 800, 800 )
-texture = ExtResource( 1 )
+texture = ExtResource( 2 )
 
 [node name="glow" type="Sprite" parent="."]
-material = SubResource( 18 )
+material = SubResource( 10 )
 position = Vector2( 1200, 800 )
-texture = ExtResource( 1 )
+texture = ExtResource( 2 )
 
 [node name="dissintegrate" type="Sprite" parent="."]
-material = SubResource( 20 )
+material = SubResource( 11 )
 position = Vector2( 1600, 800 )
-texture = ExtResource( 1 )
+texture = ExtResource( 2 )
 region_rect = Rect2( 141, 115, 39, 6 )