From d809968635375f2ddd0a5a3e69791ea1138dbaf3 Mon Sep 17 00:00:00 2001 From: 20kdc Date: Fri, 28 Aug 2020 00:04:44 +0100 Subject: [PATCH] GLES2: Content shader stuff (possibly unfinished) --- Resources/Textures/Shaders/circle_mask.swsl | 20 ++++++------- Resources/Textures/Shaders/cooldown.swsl | 26 ++++++++-------- .../Textures/Shaders/flashed_effect.swsl | 14 ++++----- .../Shaders/gradient_circle_mask.swsl | 24 +++++++-------- Resources/Textures/Shaders/outline.swsl | 30 +++++++++---------- Resources/Textures/Shaders/stencil_clear.swsl | 2 +- Resources/Textures/Shaders/stencil_mask.swsl | 4 +-- 7 files changed, 60 insertions(+), 60 deletions(-) diff --git a/Resources/Textures/Shaders/circle_mask.swsl b/Resources/Textures/Shaders/circle_mask.swsl index c8471ec2d0..dc38b360cc 100644 --- a/Resources/Textures/Shaders/circle_mask.swsl +++ b/Resources/Textures/Shaders/circle_mask.swsl @@ -1,17 +1,17 @@ -vec4 circle(in vec2 uv, in vec2 pos, float rad, in vec3 color) { - float d = length(pos - uv) - rad; - float t = clamp(d, 0.0, 1.0); +highp vec4 circle(in highp vec2 uv, in highp vec2 pos, highp float rad, in highp vec3 color) { + highp float d = length(pos - uv) - rad; + highp float t = clamp(d, 0.0, 1.0); return vec4(color, t); } void fragment(){ - vec2 uv = FRAGCOORD.xy; - vec2 res_xy = vec2(1.0/SCREEN_PIXEL_SIZE.x, 1.0/SCREEN_PIXEL_SIZE.y); - vec2 center = res_xy*0.5; - float radius = 0.05 * res_xy.y; + highp vec2 uv = FRAGCOORD.xy; + highp vec2 res_xy = vec2(1.0/SCREEN_PIXEL_SIZE.x, 1.0/SCREEN_PIXEL_SIZE.y); + highp vec2 center = res_xy*0.5; + highp float radius = 0.05 * res_xy.y; - vec4 layer1 = vec4(vec3(0), 0.0); + highp vec4 layer1 = vec4(vec3(0.0), 0.0); - vec4 layer2 = circle(uv, center, radius, vec3(0)); + highp vec4 layer2 = circle(uv, center, radius, vec3(0.0)); COLOR = mix(layer1, layer2, layer2.a); -} \ No newline at end of file +} diff --git a/Resources/Textures/Shaders/cooldown.swsl b/Resources/Textures/Shaders/cooldown.swsl index 90b215a1c3..9622b26968 100644 --- a/Resources/Textures/Shaders/cooldown.swsl +++ b/Resources/Textures/Shaders/cooldown.swsl @@ -1,25 +1,25 @@ light_mode unshaded; -const float PI = 3.14159265; +const highp float PI = 3.14159265; -uniform float progress = 0.0; +uniform highp float progress; void fragment() { - vec4 col = texture(TEXTURE, UV); - vec2 center = vec2(0.5,0.5); - vec2 delta = UV.xy - center; + highp vec4 col = texture2D(TEXTURE, UV); + highp vec2 center = vec2(0.5,0.5); + highp vec2 delta = UV.xy - center; - float angle = atan(delta.x, -delta.y) + PI; + highp float angle = atan(delta.x, -delta.y) + PI; - float dist = length(delta); - float dist_fwidth = fwidth(dist) * 0.67; + highp float dist = length(delta); + highp float dist_fwidth = fwidth(dist) * 0.67; - float dist_alpha = smoothstep(0.1-dist_fwidth, 0.1, abs(dist-0.35)); + highp float dist_alpha = smoothstep(0.1-dist_fwidth, 0.1, abs(dist-0.35)); - float angle_delta = (progress * PI * 2) - angle; - float arc_length = angle_delta * dist; + highp float angle_delta = (progress * PI * 2.0) - angle; + highp float arc_length = angle_delta * dist; - float angle_alpha = progress > 0 ? smoothstep(dist_fwidth, 0.0, arc_length) : 0.0; + highp float angle_alpha = progress > 0 ? smoothstep(dist_fwidth, 0.0, arc_length) : 0.0; COLOR = vec4(col.xyz, 1-max(dist_alpha, angle_alpha)); -} \ No newline at end of file +} diff --git a/Resources/Textures/Shaders/flashed_effect.swsl b/Resources/Textures/Shaders/flashed_effect.swsl index fdbe860cb7..ca57300aba 100644 --- a/Resources/Textures/Shaders/flashed_effect.swsl +++ b/Resources/Textures/Shaders/flashed_effect.swsl @@ -1,18 +1,18 @@ -uniform float percentComplete; -uniform float fadeFalloffExp = 8; +uniform highp float percentComplete; +uniform highp float fadeFalloffExp = 8.0; void fragment() { // Higher exponent -> stronger blinding effect - float remaining = -pow(percentComplete, fadeFalloffExp) + 1; + highp float remaining = -pow(percentComplete, fadeFalloffExp) + 1.0; // Two ghost textures that spin around the character - vec4 tex1 = texture(TEXTURE, vec2(UV.x + (0.02) * sin(TIME * 3), UV.y + (0.02) * cos(TIME * 3))); - vec4 tex2 = texture(TEXTURE, vec2(UV.x + (0.01) * sin(TIME * 2), UV.y + (0.01) * cos(TIME * 2))); + highp vec4 tex1 = texture2D(TEXTURE, vec2(UV.x + (0.02) * sin(TIME * 3.0), UV.y + (0.02) * cos(TIME * 3.0))); + highp vec4 tex2 = texture2D(TEXTURE, vec2(UV.x + (0.01) * sin(TIME * 2.0), UV.y + (0.01) * cos(TIME * 2.0))); - vec4 textureMix = mix(tex1, tex2, 0.5); + highp vec4 textureMix = mix(tex1, tex2, 0.5); // Gradually mixes between the texture mix and a full-white texture, causing the "blinding" effect - vec4 mixed = mix(vec4(1, 1, 1, 1), textureMix, percentComplete); + highp vec4 mixed = mix(vec4(1.0, 1.0, 1.0, 1.0), textureMix, percentComplete); COLOR = vec4(mixed.rgb, remaining); } diff --git a/Resources/Textures/Shaders/gradient_circle_mask.swsl b/Resources/Textures/Shaders/gradient_circle_mask.swsl index 8eee20fd4c..7772fec725 100644 --- a/Resources/Textures/Shaders/gradient_circle_mask.swsl +++ b/Resources/Textures/Shaders/gradient_circle_mask.swsl @@ -1,23 +1,23 @@ -uniform float percentagedistanceshow = 0.05; -uniform float gradientfalloffwidth = 3.0; +uniform highp float percentagedistanceshow = 0.05; +uniform highp float gradientfalloffwidth = 3.0; -vec4 circle(in vec2 uv, in vec2 pos, float rad, in vec3 color) { - float d = length(pos - uv) - rad; - float t = clamp(d, 0.0, 1.0); +highp vec4 circle(in highp vec2 uv, in highp vec2 pos, highp float rad, in highp vec3 color) { + highp float d = length(pos - uv) - rad; + highp float t = clamp(d, 0.0, 1.0); return vec4(color, t); } void fragment() { - vec2 uv = FRAGCOORD.xy; - vec2 res_xy = vec2(1.0/SCREEN_PIXEL_SIZE.x, 1.0/SCREEN_PIXEL_SIZE.y); - vec2 center = res_xy*0.5; - float radius = percentagedistanceshow * res_xy.y; + highp vec2 uv = FRAGCOORD.xy; + highp vec2 res_xy = vec2(1.0/SCREEN_PIXEL_SIZE.x, 1.0/SCREEN_PIXEL_SIZE.y); + highp vec2 center = res_xy*0.5; + highp float radius = percentagedistanceshow * res_xy.y; - vec4 grad = vec4(0.8 - length( uv - center )/res_xy.y * gradientfalloffwidth); + highp vec4 grad = vec4(0.8 - length( uv - center )/res_xy.y * gradientfalloffwidth); - vec4 layer1 = vec4(vec3(255.0),0.0); + highp vec4 layer1 = vec4(vec3(255.0),0.0); - vec4 layer2 = circle(uv, center, radius, grad.rgb); + highp vec4 layer2 = circle(uv, center, radius, grad.rgb); COLOR = mix(layer1, layer2, layer2.a); } diff --git a/Resources/Textures/Shaders/outline.swsl b/Resources/Textures/Shaders/outline.swsl index 0c3ffc701b..514669da88 100644 --- a/Resources/Textures/Shaders/outline.swsl +++ b/Resources/Textures/Shaders/outline.swsl @@ -29,47 +29,47 @@ light_mode unshaded; //shader_type canvas_item; -uniform float outline_width = 2.0; +uniform highp float outline_width = 2.0; // TODO: implement that hint_color thingy. //uniform vec4 outline_color: hint_color; -uniform vec4 outline_color=vec4(1,0,0,0.33); +uniform highp vec4 outline_color=vec4(1.0,0.0,0.0,0.33); void fragment() { - vec4 col = texture(TEXTURE, UV); - vec2 ps = TEXTURE_PIXEL_SIZE; - float a; - float maxa = col.a; - float mina = col.a; + highp vec4 col = texture2D(TEXTURE, UV); + highp vec2 ps = TEXTURE_PIXEL_SIZE; + highp float a; + highp float maxa = col.a; + highp float mina = col.a; - a = texture(TEXTURE, UV + vec2(0, -outline_width)*ps).a; + a = texture2D(TEXTURE, UV + vec2(0.0, -outline_width)*ps).a; maxa = max(a, maxa); mina = min(a, mina); - a = texture(TEXTURE, UV + vec2(-outline_width, -outline_width)*ps).a; + a = texture2D(TEXTURE, UV + vec2(-outline_width, -outline_width)*ps).a; maxa = max(a, maxa); mina = min(a, mina); - a = texture(TEXTURE, UV + vec2(0, outline_width)*ps).a; + a = texture2D(TEXTURE, UV + vec2(0.0, outline_width)*ps).a; maxa = max(a, maxa); mina = min(a, mina); - a = texture(TEXTURE, UV + vec2(outline_width, -outline_width)*ps).a; + a = texture2D(TEXTURE, UV + vec2(outline_width, -outline_width)*ps).a; maxa = max(a, maxa); mina = min(a, mina); - a = texture(TEXTURE, UV + vec2(-outline_width,0)*ps).a; + a = texture2D(TEXTURE, UV + vec2(-outline_width,0.0)*ps).a; maxa = max(a, maxa); mina = min(a, mina); - a = texture(TEXTURE, UV + vec2(-outline_width, outline_width)*ps).a; + a = texture2D(TEXTURE, UV + vec2(-outline_width, outline_width)*ps).a; maxa = max(a, maxa); mina = min(a, mina); - a = texture(TEXTURE, UV + vec2(outline_width, 0)*ps).a; + a = texture2D(TEXTURE, UV + vec2(outline_width, 0.0)*ps).a; maxa = max(a, maxa); mina = min(a, mina); - a = texture(TEXTURE, UV + vec2(outline_width, outline_width)*ps).a; + a = texture2D(TEXTURE, UV + vec2(outline_width, outline_width)*ps).a; maxa = max(a, maxa); mina = min(a, mina); diff --git a/Resources/Textures/Shaders/stencil_clear.swsl b/Resources/Textures/Shaders/stencil_clear.swsl index b0ec17e0f9..c1a28ab0aa 100644 --- a/Resources/Textures/Shaders/stencil_clear.swsl +++ b/Resources/Textures/Shaders/stencil_clear.swsl @@ -1,3 +1,3 @@ void fragment() { - COLOR = vec4(0); + COLOR = vec4(0.0); } diff --git a/Resources/Textures/Shaders/stencil_mask.swsl b/Resources/Textures/Shaders/stencil_mask.swsl index 0e50894995..8668d60c7d 100644 --- a/Resources/Textures/Shaders/stencil_mask.swsl +++ b/Resources/Textures/Shaders/stencil_mask.swsl @@ -1,7 +1,7 @@ void fragment() { - if (texture(TEXTURE, UV).a == 0) { + if (texture2D(TEXTURE, UV).a == 0.0) { discard; // Discard if no alpha so that there's a hole in the stencil buffer. } - COLOR = vec4(0); + COLOR = vec4(0.0); }