webgl: Clamp alpha in shaders (fix #6954)

This commit is contained in:
Mike Welsh 2022-05-12 12:02:21 -07:00
parent 121c2577b4
commit edad1569fb
4 changed files with 13 additions and 9 deletions

View File

@ -23,7 +23,8 @@ void main() {
if( color.a > 0.0 ) {
color.rgb /= color.a;
color = mult_color * color + add_color;
color.rgb *= color.a;
float alpha = saturate(color.a);
color = vec4(color.rgb * alpha, alpha);
}
gl_FragColor = color;

View File

@ -14,5 +14,5 @@ uniform vec4 add_color;
varying vec4 frag_color;
void main() {
gl_FragColor = vec4(frag_color.rgb * frag_color.a, frag_color.a);
gl_FragColor = frag_color;
}

View File

@ -17,5 +17,7 @@ varying vec4 frag_color;
void main() {
frag_color = color * mult_color + add_color;
float alpha = saturate(frag_color.a);
frag_color = vec4(frag_color.rgb * alpha, alpha);
gl_Position = view_matrix * world_matrix * vec4(position, 0.0, 1.0);
}

View File

@ -79,22 +79,22 @@ void main() {
float a;
if( t <= u_ratios[0] ) {
color = u_colors[0];
} else if( t <= u_ratios[1] ) {
} else if( t <= u_ratios[1] ) {
a = (t - u_ratios[0]) / (u_ratios[1] - u_ratios[0]);
color = mix(u_colors[0], u_colors[1], a);
} else if( t <= u_ratios[2] ) {
} else if( t <= u_ratios[2] ) {
a = (t - u_ratios[1]) / (u_ratios[2] - u_ratios[1]);
color = mix(u_colors[1], u_colors[2], a);
} else if( t <= u_ratios[3] ) {
} else if( t <= u_ratios[3] ) {
a = (t - u_ratios[2]) / (u_ratios[3] - u_ratios[2]);
color = mix(u_colors[2], u_colors[3], a);
} else if( t <= u_ratios[4] ) {
} else if( t <= u_ratios[4] ) {
a = (t - u_ratios[3]) / (u_ratios[4] - u_ratios[3]);
color = mix(u_colors[3], u_colors[4], a);
} else if( t <= u_ratios[5] ) {
} else if( t <= u_ratios[5] ) {
a = (t - u_ratios[4]) / (u_ratios[5] - u_ratios[4]);
color = mix(u_colors[4], u_colors[5], a);
} else if( t <= u_ratios[6] ) {
} else if( t <= u_ratios[6] ) {
a = (t - u_ratios[5]) / (u_ratios[6] - u_ratios[5]);
color = mix(u_colors[5], u_colors[6], a);
} else if( t <= u_ratios[7] ) {
@ -130,6 +130,7 @@ void main() {
}
color = mult_color * color + add_color;
gl_FragColor = vec4(color.rgb * color.a, color.a);
float alpha = saturate(color.a);
gl_FragColor = vec4(color.rgb * alpha, alpha);
}