summaryrefslogtreecommitdiff
path: root/render/fx_renderer/gles2
diff options
context:
space:
mode:
Diffstat (limited to 'render/fx_renderer/gles2')
-rw-r--r--render/fx_renderer/gles2/shaders/gradient.frag47
-rw-r--r--render/fx_renderer/gles2/shaders/meson.build1
-rw-r--r--render/fx_renderer/gles2/shaders/quad_grad.frag44
-rw-r--r--render/fx_renderer/gles2/shaders/quad_grad_round.frag45
-rw-r--r--render/fx_renderer/gles2/shaders/rounded_grad_border_corner.frag44
5 files changed, 52 insertions, 129 deletions
diff --git a/render/fx_renderer/gles2/shaders/gradient.frag b/render/fx_renderer/gles2/shaders/gradient.frag
new file mode 100644
index 0000000..0ab6712
--- /dev/null
+++ b/render/fx_renderer/gles2/shaders/gradient.frag
@@ -0,0 +1,47 @@
+#ifdef GL_FRAGMENT_PRECISION_HIGH
+precision highp float;
+#else
+precision mediump float;
+#endif
+
+vec4 gradient(vec4 colors[LEN], int count, vec2 size, vec2 grad_box, vec2 origin, float degree, bool linear, bool blend){
+ float step;
+
+ vec2 normal = (gl_FragCoord.xy - grad_box)/size;
+ vec2 uv = normal - origin;
+
+ float rad = radians(degree);
+
+ if(linear){
+ uv *= vec2(1.0)/vec2(abs(cos(rad)) + abs(sin(rad)));
+
+ vec2 rotated = vec2(uv.x * cos(rad) - uv.y * sin(rad) + origin.x,
+ uv.x * sin(rad) + uv.y * cos(rad) + origin.y);
+
+ step = rotated.x;
+ } else {
+ vec2 uv = normal - origin;
+ uv = vec2(uv.x * cos(rad) - uv.y * sin(rad),
+ uv.x * sin(rad) + uv.y * cos(rad));
+
+ uv = vec2(-atan(uv.y, uv.x)/3.14159265 * 0.5 + 0.5, 0.0);
+ step = uv.x;
+ }
+
+ if(!blend){
+ float smooth = 1.0/float(count);
+ int ind = int(step/smooth);
+
+ return colors[ind];
+ }
+
+ float smooth = 1.0/float(count - 1);
+ int ind = int(step/smooth);
+ float at = float(ind)*smooth;
+
+ vec4 color = colors[ind];
+ if(ind > 0) color = mix(colors[ind - 1], color, smoothstep(at - smooth, at, step));
+ if(ind <= count - 1) color = mix(color, colors[ind + 1], smoothstep(at, at + smooth, step));
+
+ return color;
+}
diff --git a/render/fx_renderer/gles2/shaders/meson.build b/render/fx_renderer/gles2/shaders/meson.build
index ce08097..12e4427 100644
--- a/render/fx_renderer/gles2/shaders/meson.build
+++ b/render/fx_renderer/gles2/shaders/meson.build
@@ -2,6 +2,7 @@ embed = find_program('./embed.sh', native: true)
shaders = [
'common.vert',
+ 'gradient.frag',
'quad.frag',
'quad_grad.frag',
'quad_round.frag',
diff --git a/render/fx_renderer/gles2/shaders/quad_grad.frag b/render/fx_renderer/gles2/shaders/quad_grad.frag
index 6f611ca..465da81 100644
--- a/render/fx_renderer/gles2/shaders/quad_grad.frag
+++ b/render/fx_renderer/gles2/shaders/quad_grad.frag
@@ -16,48 +16,6 @@ uniform bool linear;
uniform bool blend;
uniform int count;
-vec4 gradient(){
- float step;
-
- vec2 normal = (gl_FragCoord.xy - grad_box)/size;
- vec2 uv = normal - origin;
-
- float rad = radians(degree);
-
- if(linear){
- uv *= vec2(1.0)/vec2(abs(cos(rad)) + abs(sin(rad)));
-
- vec2 rotated = vec2(uv.x * cos(rad) - uv.y * sin(rad) + origin.x,
- uv.x * sin(rad) + uv.y * cos(rad) + origin.y);
-
- step = rotated.x;
- } else {
- vec2 uv = normal - origin;
- uv = vec2(uv.x * cos(rad) - uv.y * sin(rad),
- uv.x * sin(rad) + uv.y * cos(rad));
-
- uv = vec2(-atan(uv.y, uv.x)/3.14159265 * 0.5 + 0.5, 0.0);
- step = uv.x;
- }
-
- if(!blend){
- float smooth = 1.0/float(count);
- int ind = int(step/smooth);
-
- return colors[ind];
- }
-
- float smooth = 1.0/float(count - 1);
- int ind = int(step/smooth);
- float at = float(ind)*smooth;
-
- vec4 color = colors[ind];
- if(ind > 0) color = mix(colors[ind - 1], color, smoothstep(at - smooth, at, step));
- if(ind <= count - 1) color = mix(color, colors[ind + 1], smoothstep(at, at + smooth, step));
-
- return color;
-}
-
void main(){
- gl_FragColor = gradient();
+ gl_FragColor = gradient(colors, count, size, grad_box, origin, degree, linear, blend);
}
diff --git a/render/fx_renderer/gles2/shaders/quad_grad_round.frag b/render/fx_renderer/gles2/shaders/quad_grad_round.frag
index 516573e..60e5fcf 100644
--- a/render/fx_renderer/gles2/shaders/quad_grad_round.frag
+++ b/render/fx_renderer/gles2/shaders/quad_grad_round.frag
@@ -25,48 +25,6 @@ uniform bool linear;
uniform bool blend;
uniform int count;
-vec4 gradient(){
- float step;
-
- vec2 normal = (gl_FragCoord.xy - grad_box)/size;
- vec2 uv = normal - origin;
-
- float rad = radians(degree);
-
- if(linear){
- uv *= vec2(1.0)/vec2(abs(cos(rad)) + abs(sin(rad)));
-
- vec2 rotated = vec2(uv.x * cos(rad) - uv.y * sin(rad) + origin.x,
- uv.x * sin(rad) + uv.y * cos(rad) + origin.y);
-
- step = rotated.x;
- } else {
- vec2 uv = normal - origin;
- uv = vec2(uv.x * cos(rad) - uv.y * sin(rad),
- uv.x * sin(rad) + uv.y * cos(rad));
-
- uv = vec2(-atan(uv.y, uv.x)/3.14159265 * 0.5 + 0.5, 0.0);
- step = uv.x;
- }
-
- if(!blend){
- float smooth = 1.0/float(count);
- int ind = int(step/smooth);
-
- return colors[ind];
- }
-
- float smooth = 1.0/float(count - 1);
- int ind = int(step/smooth);
- float at = float(ind)*smooth;
-
- vec4 color = colors[ind];
- if(ind > 0) color = mix(colors[ind - 1], color, smoothstep(at - smooth, at, step));
- if(ind <= count - 1) color = mix(color, colors[ind + 1], smoothstep(at, at + smooth, step));
-
- return color;
-}
-
vec2 getCornerDist() {
#if SOURCE == SOURCE_QUAD_ROUND
vec2 half_size = size * 0.5;
@@ -86,5 +44,6 @@ void main() {
vec2 q = getCornerDist();
float dist = min(max(q.x,q.y), 0.0) + length(max(q, 0.0)) - radius;
float smoothedAlpha = 1.0 - smoothstep(-1.0, 0.5, dist);
- gl_FragColor = mix(vec4(0), gradient(), smoothedAlpha);
+
+ gl_FragColor = mix(vec4(0), gradient(colors, count, size, grad_box, origin, degree, linear, blend), smoothedAlpha);
}
diff --git a/render/fx_renderer/gles2/shaders/rounded_grad_border_corner.frag b/render/fx_renderer/gles2/shaders/rounded_grad_border_corner.frag
index 2ce4f41..9e9aef0 100644
--- a/render/fx_renderer/gles2/shaders/rounded_grad_border_corner.frag
+++ b/render/fx_renderer/gles2/shaders/rounded_grad_border_corner.frag
@@ -21,48 +21,6 @@ uniform bool linear;
uniform bool blend;
uniform int count;
-vec4 gradient(){
- float step;
-
- vec2 normal = (gl_FragCoord.xy - grad_box)/size;
- vec2 uv = normal - origin;
-
- float rad = radians(degree);
-
- if(linear){
- uv *= vec2(1.0)/vec2(abs(cos(rad)) + abs(sin(rad)));
-
- vec2 rotated = vec2(uv.x * cos(rad) - uv.y * sin(rad) + origin.x,
- uv.x * sin(rad) + uv.y * cos(rad) + origin.y);
-
- step = rotated.x;
- } else {
- vec2 uv = normal - origin;
- uv = vec2(uv.x * cos(rad) - uv.y * sin(rad),
- uv.x * sin(rad) + uv.y * cos(rad));
-
- uv = vec2(-atan(uv.y, uv.x)/3.14159265 * 0.5 + 0.5, 0.0);
- step = uv.x;
- }
-
- if(!blend){
- float smooth = 1.0/float(count);
- int ind = int(step/smooth);
-
- return colors[ind];
- }
-
- float smooth = 1.0/float(count - 1);
- int ind = int(step/smooth);
- float at = float(ind)*smooth;
-
- vec4 color = colors[ind];
- if(ind > 0) color = mix(colors[ind - 1], color, smoothstep(at - smooth, at, step));
- if(ind <= count - 1) color = mix(color, colors[ind + 1], smoothstep(at, at + smooth, step));
-
- return color;
-}
-
float roundedBoxSDF(vec2 center, vec2 size, float radius) {
return length(max(abs(center) - size + radius, 0.0)) - radius;
}
@@ -84,5 +42,5 @@ void main() {
discard;
}
- gl_FragColor = mix(vec4(0), gradient(), smoothedAlphaOuter - smoothedAlphaInner);
+ gl_FragColor = mix(vec4(0), gradient(colors, count, size, grad_box, origin, degree, linear, blend), smoothedAlphaOuter - smoothedAlphaInner);
}