Finalize color at the vertex level, rather than the fragment level, for fill

This commit is contained in:
Grant Sanderson 2023-02-02 12:04:23 -08:00
parent a1b9eae301
commit acb4b1c6b3
2 changed files with 10 additions and 14 deletions

View file

@ -6,16 +6,12 @@ in vec4 color;
in float fill_all;
in float orientation;
in vec2 uv_coords;
in vec3 point;
in vec3 unit_normal;
out vec4 frag_color;
#INSERT finalize_color.glsl
void main() {
if (color.a == 0) discard;
frag_color = finalize_color(color, point, unit_normal);
frag_color = color;
/*
We want negatively oriented triangles to be canceled with positively
oriented ones. The easiest way to do this is to give them negative alpha,
@ -33,9 +29,11 @@ void main() {
cap is to make sure the original fragment color can be recovered even after
blending with an (alpha = 1) color.
*/
float a = 0.95 * frag_color.a;
if(winding && orientation < 0) a = -a / (1 - a);
frag_color.a = a;
if(winding){
float a = 0.95 * frag_color.a;
if(orientation < 0) a = -a / (1 - a);
frag_color.a = a;
}
if (bool(fill_all)) return;

View file

@ -14,8 +14,6 @@ in vec3 v_unit_normal[3];
out vec4 color;
out float fill_all;
out float orientation;
out vec3 point;
out vec3 unit_normal;
// uv space is where the curve coincides with y = x^2
out vec2 uv_coords;
@ -28,9 +26,12 @@ const vec2 SIMPLE_QUADRATIC[3] = vec2[3](
// Analog of import for manim only
#INSERT emit_gl_Position.glsl
#INSERT finalize_color.glsl
void emit_triangle(vec3 points[3], vec4 v_color[3]){
vec3 unit_normal = v_unit_normal[1];
orientation = sign(determinant(mat3(
unit_normal,
points[1] - points[0],
@ -39,8 +40,7 @@ void emit_triangle(vec3 points[3], vec4 v_color[3]){
for(int i = 0; i < 3; i++){
uv_coords = SIMPLE_QUADRATIC[i];
color = v_color[i];
point = points[i];
color = finalize_color(v_color[i], points[i], unit_normal);
emit_gl_Position(points[i]);
EmitVertex();
}
@ -61,8 +61,6 @@ void main(){
// the first anchor is set equal to that anchor
if (verts[0] == verts[1]) return;
unit_normal = v_unit_normal[1];
if(winding){
// Emit main triangle
fill_all = 1.0;