2020-02-03 10:52:39 -08:00
|
|
|
#version 330
|
|
|
|
|
2023-01-24 20:03:23 -08:00
|
|
|
uniform bool winding;
|
|
|
|
|
2020-02-03 10:52:39 -08:00
|
|
|
in vec4 color;
|
2023-01-24 13:49:43 -08:00
|
|
|
in float fill_all;
|
2023-01-24 20:03:23 -08:00
|
|
|
in float orientation;
|
2020-02-03 10:52:39 -08:00
|
|
|
in vec2 uv_coords;
|
2023-01-26 15:50:27 -08:00
|
|
|
in vec3 point;
|
2023-01-27 12:35:43 -08:00
|
|
|
in vec3 unit_normal;
|
2020-02-03 10:52:39 -08:00
|
|
|
|
|
|
|
out vec4 frag_color;
|
|
|
|
|
2023-01-26 15:50:27 -08:00
|
|
|
#INSERT finalize_color.glsl
|
|
|
|
|
2023-01-24 13:29:34 -08:00
|
|
|
void main() {
|
|
|
|
if (color.a == 0) discard;
|
2023-01-27 12:35:43 -08:00
|
|
|
frag_color = finalize_color(color, point, unit_normal);
|
2023-01-26 15:27:48 -08:00
|
|
|
/*
|
|
|
|
We want negatively oriented triangles to be canceled with positively
|
|
|
|
oriented ones. The easiest way to do this is to give them negative alpha,
|
|
|
|
and change the blend function to just add them. However, this messes with
|
|
|
|
usual blending, so instead the following line is meant to let this canceling
|
|
|
|
work even for the normal blending equation:
|
|
|
|
|
|
|
|
(1 - alpha) * dst + alpha * src
|
|
|
|
|
|
|
|
We want the effect of blending with a positively oriented triangle followed
|
|
|
|
by a negatively oriented one to return to whatever the original frag value
|
|
|
|
was. You can work out this will work if the alpha for negative orientations
|
|
|
|
is changed to -alpha / (1 - alpha). This has a singularity at alpha = 1,
|
|
|
|
so we cap it at a value very close to 1. Effectively, the purpose of this
|
|
|
|
cap is to make sure the original fragment color can be recovered even after
|
2023-01-26 20:14:22 -08:00
|
|
|
blending with an (alpha = 1) color.
|
2023-01-26 15:27:48 -08:00
|
|
|
*/
|
2023-01-27 08:26:54 -08:00
|
|
|
float a = 0.99 * frag_color.a;
|
2023-01-26 15:27:48 -08:00
|
|
|
if(winding && orientation < 0) a = -a / (1 - a);
|
|
|
|
frag_color.a = a;
|
2023-01-24 20:03:23 -08:00
|
|
|
|
2023-01-24 13:49:43 -08:00
|
|
|
if (bool(fill_all)) return;
|
2023-01-10 08:54:02 -08:00
|
|
|
|
2023-01-24 13:49:43 -08:00
|
|
|
float x = uv_coords.x;
|
|
|
|
float y = uv_coords.y;
|
2023-01-24 20:03:23 -08:00
|
|
|
float Fxy = (y - x * x);
|
2023-01-26 12:17:21 -08:00
|
|
|
if(!winding && orientation < 0) Fxy *= -1;
|
2023-01-24 20:03:23 -08:00
|
|
|
if(Fxy < 0) discard;
|
2020-03-30 20:26:06 +02:00
|
|
|
}
|