forked from AuroraMiddleware/gtk
ngl: Small shader improvements
Add a variant of gskSetOutputColor that saves a few multiplications, and use it where possible.
This commit is contained in:
parent
8aac574d63
commit
51074ca5df
@ -310,5 +310,5 @@ void main() {
|
||||
else
|
||||
discard;
|
||||
|
||||
gskSetOutputColor(result * u_alpha);
|
||||
gskSetScaledOutputColor(result, u_alpha);
|
||||
}
|
||||
|
@ -13,5 +13,5 @@ void main() {
|
||||
void main() {
|
||||
vec4 diffuse = GskTexture(u_source, vUv);
|
||||
|
||||
gskSetOutputColor(diffuse * u_alpha);
|
||||
gskSetScaledOutputColor(diffuse, u_alpha);
|
||||
}
|
||||
|
@ -39,5 +39,5 @@ void main() {
|
||||
gsk_rounded_rect_coverage(gsk_decode_rect(transformed_inside_outline), frag),
|
||||
0.0, 1.0);
|
||||
|
||||
gskSetOutputColor(final_color * alpha);
|
||||
gskSetScaledOutputColor(final_color, alpha);
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ void main() {
|
||||
vec4 curr_color = gsk_premultiply(get_color(i));
|
||||
vec4 next_color = gsk_premultiply(get_color(i + 1));
|
||||
vec4 color = mix(curr_color, next_color, f);
|
||||
gskSetOutputColor(color * u_alpha);
|
||||
gskSetScaledOutputColor(color, u_alpha);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -40,5 +40,5 @@ void main() {
|
||||
gsk_rounded_rect_coverage(gsk_decode_rect(transformed_inside_outline), frag),
|
||||
0.0, 1.0);
|
||||
|
||||
gskSetOutputColor(final_color * alpha);
|
||||
gskSetScaledOutputColor(final_color, alpha);
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ void main() {
|
||||
vec4 curr_color = gsk_premultiply(get_color(i));
|
||||
vec4 next_color = gsk_premultiply(get_color(i + 1));
|
||||
vec4 color = mix(curr_color, next_color, f);
|
||||
gskSetOutputColor(color * u_alpha);
|
||||
gskSetScaledOutputColor(color, u_alpha);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,5 @@ void main() {
|
||||
|
||||
alpha *= (1.0 - clamp(gsk_rounded_rect_coverage(gsk_decode_rect(transformed_outline), frag), 0.0, 1.0));
|
||||
|
||||
vec4 color = final_color * alpha;
|
||||
|
||||
gskSetOutputColor(color);
|
||||
gskSetScaledOutputColor(final_color, alpha);
|
||||
}
|
||||
|
@ -123,11 +123,35 @@ void gskSetOutputColor(vec4 color) {
|
||||
#if defined(NO_CLIP)
|
||||
result = color;
|
||||
#elif defined(RECT_CLIP)
|
||||
result = color * gsk_rect_coverage(gsk_get_bounds(u_clip_rect),
|
||||
float coverage = gsk_rect_coverage(gsk_get_bounds(u_clip_rect),
|
||||
gsk_get_frag_coord());
|
||||
result = color * coverage;
|
||||
#else
|
||||
result = color * gsk_rounded_rect_coverage(gsk_create_rect(u_clip_rect),
|
||||
float coverage = gsk_rounded_rect_coverage(gsk_create_rect(u_clip_rect),
|
||||
gsk_get_frag_coord());
|
||||
result = color * coverage;
|
||||
#endif
|
||||
|
||||
#if defined(GSK_GLES) || defined(GSK_LEGACY)
|
||||
gl_FragColor = result;
|
||||
#else
|
||||
outputColor = result;
|
||||
#endif
|
||||
}
|
||||
|
||||
void gskSetScaledOutputColor(vec4 color, float alpha) {
|
||||
vec4 result;
|
||||
|
||||
#if defined(NO_CLIP)
|
||||
result = color * alpha;
|
||||
#elif defined(RECT_CLIP)
|
||||
float coverage = gsk_rect_coverage(gsk_get_bounds(u_clip_rect),
|
||||
gsk_get_frag_coord());
|
||||
result = color * (alpha * coverage);
|
||||
#else
|
||||
float coverage = gsk_rounded_rect_coverage(gsk_create_rect(u_clip_rect),
|
||||
gsk_get_frag_coord());
|
||||
result = color * (alpha * coverage);
|
||||
#endif
|
||||
|
||||
#if defined(GSK_GLES) || defined(GSK_LEGACY)
|
||||
|
@ -77,7 +77,7 @@ void main() {
|
||||
vec4 curr_color = gsk_premultiply(get_color(i));
|
||||
vec4 next_color = gsk_premultiply(get_color(i + 1));
|
||||
vec4 color = mix(curr_color, next_color, f);
|
||||
gskSetOutputColor(color * u_alpha);
|
||||
gskSetScaledOutputColor(color, u_alpha);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -40,5 +40,5 @@ void main() {
|
||||
|
||||
vec4 diffuse = GskTexture(u_source, tp);
|
||||
|
||||
gskSetOutputColor(diffuse * u_alpha);
|
||||
gskSetScaledOutputColor(diffuse, u_alpha);
|
||||
}
|
||||
|
@ -39,6 +39,6 @@ void main() {
|
||||
gsk_rounded_rect_coverage(gsk_decode_rect(transformed_inside_outline), frag),
|
||||
0.0, 1.0);
|
||||
|
||||
gskSetOutputColor(final_color * alpha);
|
||||
gskSetScaledOutputColor(final_color, alpha);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user