diff options
author | ame <[email protected]> | 2024-10-09 17:04:13 -0500 |
---|---|---|
committer | ame <[email protected]> | 2024-10-09 17:04:13 -0500 |
commit | b2dd727499800306b89dad2275e600781ef3739f (patch) | |
tree | 57dc10dbe85f46ccc573f4eee2497be5ebc4ef6c /render/fx_renderer/gles2/shaders/quad_grad.frag | |
parent | f05626176636c49ba27c3ba2b69658f50c9b5730 (diff) |
add gradient rect support
Diffstat (limited to 'render/fx_renderer/gles2/shaders/quad_grad.frag')
-rw-r--r-- | render/fx_renderer/gles2/shaders/quad_grad.frag | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/render/fx_renderer/gles2/shaders/quad_grad.frag b/render/fx_renderer/gles2/shaders/quad_grad.frag new file mode 100644 index 0000000..d259942 --- /dev/null +++ b/render/fx_renderer/gles2/shaders/quad_grad.frag @@ -0,0 +1,57 @@ +#ifdef GL_FRAGMENT_PRECISION_HIGH +precision highp float; +#else +precision mediump float; +#endif + +varying vec4 v_color; +varying vec2 v_texcoord; + +uniform vec4 colors[LEN]; +uniform vec2 size; +uniform float degree; +uniform vec2 grad_box; +uniform vec2 origin; +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){ + float angle = rad + atan(uv.x, uv.y); + + float len = length(uv); + uv = vec2(cos(angle) * len, sin(angle) * len) + origin; + step = uv.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; + } + + float smooth = 1.0/float(count - 1); + int ind = int(step/smooth); + float at = float(ind)*smooth; + + if(!blend) return colors[ind]; + + 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(); +} |