aboutsummaryrefslogtreecommitdiff
path: root/data/shaders/buffer-wireframe.frag
blob: 866c28168057401612352fc8a6e8d9d64fbedee8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
varying vec4 dist;

const vec4 LINE_COLOR = vec4(1.0);
const vec4 TRIANGLE_COLOR = vec4(0.0, 0.5, 0.8, 0.8);

void main(void)
{
    // Get the minimum distance of this fragment from a triangle edge.
    // We need to multiply with dist.w to undo the workaround we had
    // to perform to get linear interpolation (instead of perspective correct).
    float d = min(dist.x * dist.w, min(dist.y * dist.w, dist.z * dist.w));

    // Get the intensity of the wireframe line
    float I = exp2(-2.0 * d * d);

    gl_FragColor = mix(TRIANGLE_COLOR, LINE_COLOR, I);
}