gl shaders: unify frag coord handling

This commit is contained in:
Timm Bäder 2020-05-10 09:20:53 +02:00
parent b98ad549c2
commit 52ae384bfd
6 changed files with 32 additions and 38 deletions

View File

@ -32,12 +32,10 @@ _IN_ _ROUNDED_RECT_UNIFORM_ transformed_outside_outline;
_IN_ _ROUNDED_RECT_UNIFORM_ transformed_inside_outline; _IN_ _ROUNDED_RECT_UNIFORM_ transformed_inside_outline;
void main() { void main() {
vec4 f = gl_FragCoord; vec2 frag = get_frag_coord();
f.x += u_viewport.x;
f.y = (u_viewport.y + u_viewport.w) - f.y;
float alpha = clamp(rounded_rect_coverage(decode_rect(transformed_outside_outline), f.xy) - float alpha = clamp(rounded_rect_coverage(decode_rect(transformed_outside_outline), frag) -
rounded_rect_coverage(decode_rect(transformed_inside_outline), f.xy), rounded_rect_coverage(decode_rect(transformed_inside_outline), frag),
0.0, 1.0); 0.0, 1.0);
setOutputColor(final_color * alpha); setOutputColor(final_color * alpha);

View File

@ -33,13 +33,10 @@ _IN_ _ROUNDED_RECT_UNIFORM_ transformed_outside_outline;
_IN_ _ROUNDED_RECT_UNIFORM_ transformed_inside_outline; _IN_ _ROUNDED_RECT_UNIFORM_ transformed_inside_outline;
void main() { void main() {
vec4 f = gl_FragCoord; vec2 frag = get_frag_coord();
f.x += u_viewport.x; float alpha = clamp (rounded_rect_coverage(decode_rect(transformed_outside_outline), frag) -
f.y = (u_viewport.y + u_viewport.w) - f.y; rounded_rect_coverage(decode_rect(transformed_inside_outline), frag),
float alpha = clamp (rounded_rect_coverage(decode_rect(transformed_outside_outline), f.xy) -
rounded_rect_coverage(decode_rect(transformed_inside_outline), f.xy),
0.0, 1.0); 0.0, 1.0);
setOutputColor(final_color * alpha); setOutputColor(final_color * alpha);

View File

@ -47,17 +47,9 @@ _IN_ float gradientLength;
_IN_ vec4 color_stops[8]; _IN_ vec4 color_stops[8];
_IN_ float color_offsets[8]; _IN_ float color_offsets[8];
vec4 fragCoord() {
vec4 f = gl_FragCoord;
f.x += u_viewport.x;
f.y = (u_viewport.y + u_viewport.w) - f.y;
return f;
}
void main() { void main() {
// Position relative to startPoint // Position relative to startPoint
vec2 pos = fragCoord().xy - startPoint; vec2 pos = get_frag_coord() - startPoint;
// Current pixel, projected onto the line between the start point and the end point // Current pixel, projected onto the line between the start point and the end point
// The projection will be relative to the start point! // The projection will be relative to the start point!

View File

@ -25,13 +25,10 @@ _IN_ vec4 final_color;
_IN_ _ROUNDED_RECT_UNIFORM_ transformed_outline; _IN_ _ROUNDED_RECT_UNIFORM_ transformed_outline;
void main() { void main() {
vec4 f = gl_FragCoord; vec2 frag = get_frag_coord();
f.x += u_viewport.x;
f.y = (u_viewport.y + u_viewport.w) - f.y;
float alpha = Texture(u_source, vUv).a; float alpha = Texture(u_source, vUv).a;
alpha *= (1.0 - clamp(rounded_rect_coverage(decode_rect(transformed_outline), f.xy), 0.0, 1.0)); alpha *= (1.0 - clamp(rounded_rect_coverage(decode_rect(transformed_outline), frag), 0.0, 1.0));
vec4 color = final_color * alpha; vec4 color = final_color * alpha;

View File

@ -84,19 +84,32 @@ vec4 Texture(sampler2D sampler, vec2 texCoords) {
#endif #endif
} }
#ifdef GSK_GL3
layout(origin_upper_left) in vec4 gl_FragCoord;
#endif
vec2 get_frag_coord() {
vec2 fc = gl_FragCoord.xy;
#ifdef GSK_GL3
fc += u_viewport.xy;
#else
fc.x += u_viewport.x;
fc.y = (u_viewport.y + u_viewport.w) - fc.y;
#endif
return fc;
}
void setOutputColor(vec4 color) { void setOutputColor(vec4 color) {
vec4 f = gl_FragCoord; vec2 f = get_frag_coord();
f.x += u_viewport.x;
f.y = (u_viewport.y + u_viewport.w) - f.y;
// We do *NOT* transform the clip rect here since we already // We do *NOT* transform the clip rect here since we already
// need to do that on the CPU. // need to do that on the CPU.
#if defined(GSK_GLES) || defined(GSK_LEGACY) #if defined(GSK_GLES) || defined(GSK_LEGACY)
gl_FragColor = color * rounded_rect_coverage(create_rect(u_clip_rect), f.xy); gl_FragColor = color * rounded_rect_coverage(create_rect(u_clip_rect), f);
#else #else
outputColor = color * rounded_rect_coverage(create_rect(u_clip_rect), f.xy); outputColor = color * rounded_rect_coverage(create_rect(u_clip_rect), f);
#endif #endif
/*outputColor = color;*/ /*outputColor = color;*/
} }

View File

@ -33,13 +33,10 @@ _IN_ _ROUNDED_RECT_UNIFORM_ transformed_outside_outline;
_IN_ _ROUNDED_RECT_UNIFORM_ transformed_inside_outline; _IN_ _ROUNDED_RECT_UNIFORM_ transformed_inside_outline;
void main() { void main() {
vec4 f = gl_FragCoord; vec2 frag = get_frag_coord();
f.x += u_viewport.x; float alpha = clamp(rounded_rect_coverage(decode_rect(transformed_outside_outline), frag) -
f.y = (u_viewport.y + u_viewport.w) - f.y; rounded_rect_coverage(decode_rect(transformed_inside_outline), frag),
float alpha = clamp(rounded_rect_coverage(decode_rect(transformed_outside_outline), f.xy) -
rounded_rect_coverage(decode_rect(transformed_inside_outline), f.xy),
0.0, 1.0); 0.0, 1.0);
setOutputColor(final_color * alpha); setOutputColor(final_color * alpha);