GLES2: Content shader stuff (possibly unfinished)

This commit is contained in:
20kdc
2020-08-28 00:04:44 +01:00
parent acfb452aa7
commit d809968635
7 changed files with 60 additions and 60 deletions

View File

@@ -1,17 +1,17 @@
vec4 circle(in vec2 uv, in vec2 pos, float rad, in vec3 color) { highp vec4 circle(in highp vec2 uv, in highp vec2 pos, highp float rad, in highp vec3 color) {
float d = length(pos - uv) - rad; highp float d = length(pos - uv) - rad;
float t = clamp(d, 0.0, 1.0); highp float t = clamp(d, 0.0, 1.0);
return vec4(color, t); return vec4(color, t);
} }
void fragment(){ void fragment(){
vec2 uv = FRAGCOORD.xy; highp vec2 uv = FRAGCOORD.xy;
vec2 res_xy = vec2(1.0/SCREEN_PIXEL_SIZE.x, 1.0/SCREEN_PIXEL_SIZE.y); highp vec2 res_xy = vec2(1.0/SCREEN_PIXEL_SIZE.x, 1.0/SCREEN_PIXEL_SIZE.y);
vec2 center = res_xy*0.5; highp vec2 center = res_xy*0.5;
float radius = 0.05 * res_xy.y; 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); COLOR = mix(layer1, layer2, layer2.a);
} }

View File

@@ -1,25 +1,25 @@
light_mode unshaded; 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() { void fragment() {
vec4 col = texture(TEXTURE, UV); highp vec4 col = texture2D(TEXTURE, UV);
vec2 center = vec2(0.5,0.5); highp vec2 center = vec2(0.5,0.5);
vec2 delta = UV.xy - center; 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); highp float dist = length(delta);
float dist_fwidth = fwidth(dist) * 0.67; 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; highp float angle_delta = (progress * PI * 2.0) - angle;
float arc_length = angle_delta * dist; 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)); COLOR = vec4(col.xyz, 1-max(dist_alpha, angle_alpha));
} }

View File

@@ -1,18 +1,18 @@
uniform float percentComplete; uniform highp float percentComplete;
uniform float fadeFalloffExp = 8; uniform highp float fadeFalloffExp = 8.0;
void fragment() { void fragment() {
// Higher exponent -> stronger blinding effect // 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 // 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))); highp vec4 tex1 = texture2D(TEXTURE, vec2(UV.x + (0.02) * sin(TIME * 3.0), UV.y + (0.02) * cos(TIME * 3.0)));
vec4 tex2 = texture(TEXTURE, vec2(UV.x + (0.01) * sin(TIME * 2), UV.y + (0.01) * cos(TIME * 2))); 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 // 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); COLOR = vec4(mixed.rgb, remaining);
} }

View File

@@ -1,23 +1,23 @@
uniform float percentagedistanceshow = 0.05; uniform highp float percentagedistanceshow = 0.05;
uniform float gradientfalloffwidth = 3.0; uniform highp float gradientfalloffwidth = 3.0;
vec4 circle(in vec2 uv, in vec2 pos, float rad, in vec3 color) { highp vec4 circle(in highp vec2 uv, in highp vec2 pos, highp float rad, in highp vec3 color) {
float d = length(pos - uv) - rad; highp float d = length(pos - uv) - rad;
float t = clamp(d, 0.0, 1.0); highp float t = clamp(d, 0.0, 1.0);
return vec4(color, t); return vec4(color, t);
} }
void fragment() { void fragment() {
vec2 uv = FRAGCOORD.xy; highp vec2 uv = FRAGCOORD.xy;
vec2 res_xy = vec2(1.0/SCREEN_PIXEL_SIZE.x, 1.0/SCREEN_PIXEL_SIZE.y); highp vec2 res_xy = vec2(1.0/SCREEN_PIXEL_SIZE.x, 1.0/SCREEN_PIXEL_SIZE.y);
vec2 center = res_xy*0.5; highp vec2 center = res_xy*0.5;
float radius = percentagedistanceshow * res_xy.y; 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); COLOR = mix(layer1, layer2, layer2.a);
} }

View File

@@ -29,47 +29,47 @@
light_mode unshaded; light_mode unshaded;
//shader_type canvas_item; //shader_type canvas_item;
uniform float outline_width = 2.0; uniform highp float outline_width = 2.0;
// TODO: implement that hint_color thingy. // TODO: implement that hint_color thingy.
//uniform vec4 outline_color: hint_color; //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() { void fragment() {
vec4 col = texture(TEXTURE, UV); highp vec4 col = texture2D(TEXTURE, UV);
vec2 ps = TEXTURE_PIXEL_SIZE; highp vec2 ps = TEXTURE_PIXEL_SIZE;
float a; highp float a;
float maxa = col.a; highp float maxa = col.a;
float mina = 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); maxa = max(a, maxa);
mina = min(a, mina); 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); maxa = max(a, maxa);
mina = min(a, mina); 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); maxa = max(a, maxa);
mina = min(a, mina); 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); maxa = max(a, maxa);
mina = min(a, mina); 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); maxa = max(a, maxa);
mina = min(a, mina); 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); maxa = max(a, maxa);
mina = min(a, mina); 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); maxa = max(a, maxa);
mina = min(a, mina); 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); maxa = max(a, maxa);
mina = min(a, mina); mina = min(a, mina);

View File

@@ -1,3 +1,3 @@
void fragment() { void fragment() {
COLOR = vec4(0); COLOR = vec4(0.0);
} }

View File

@@ -1,7 +1,7 @@
void fragment() { 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. discard; // Discard if no alpha so that there's a hole in the stencil buffer.
} }
COLOR = vec4(0); COLOR = vec4(0.0);
} }