ngl: Small shader improvements

Add a variant of gskSetOutputColor that saves a
few multiplications, and use it where possible.
This commit is contained in:
Matthias Clasen 2021-03-13 18:21:45 -05:00
parent 8aac574d63
commit 51074ca5df
11 changed files with 36 additions and 14 deletions

View File

@ -310,5 +310,5 @@ void main() {
else
discard;
gskSetOutputColor(result * u_alpha);
gskSetScaledOutputColor(result, u_alpha);
}

View File

@ -13,5 +13,5 @@ void main() {
void main() {
vec4 diffuse = GskTexture(u_source, vUv);
gskSetOutputColor(diffuse * u_alpha);
gskSetScaledOutputColor(diffuse, u_alpha);
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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)

View File

@ -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;
}
}

View File

@ -40,5 +40,5 @@ void main() {
vec4 diffuse = GskTexture(u_source, tp);
gskSetOutputColor(diffuse * u_alpha);
gskSetScaledOutputColor(diffuse, u_alpha);
}

View File

@ -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);
}