Draw the sun, debug the colour and variable size
[clouds.git] / billboardfrag.glsl
1 #version 400
2 uniform vec4 color;
3 uniform sampler2D tex;
4 in vec2 texCoord;
5 out vec4 FragColor;
6 uniform bool modulate;
7 uniform bool debug;
8 uniform bool debugColor;
9 uniform float debugVal;
10 void main() {
11   if (debugColor) {
12     FragColor = color;
13     return;
14   }
15   if (debug) {
16     FragColor = mix(vec4(1, 1, 1, 1), vec4(1, 0, 0, 1), debugVal);
17     return;
18   }
19         // Cf = color from fragment, Ct = color from texture
20         // Cc = color from texture environment -- not set, defaults to (0,0,0,0)
21         // Af = alpha from fragment, At = alpha from texture
22         // C = output color, A = output alpha
23         float f = texture(tex, texCoord).r;
24         if (modulate) { 
25                 // GL_MODULATE: C
26                 // C = Cf * Ct
27                 // A = Af * At                          
28                 FragColor = color * f;
29         } else {
30         // "That is, the colors in the frame buffer are multiplied by the
31         // attenuation ratio of the billboard texture and then the colors in
32         // the texture are added"
33                 // GL_BLEND:
34                 // C = Cf * (1-Ct) + Cc * Ct
35                 // A = Af * At
36                 vec3 C = color.rgb * (1 - f);
37                 float A = color.a * f;
38                 FragColor = vec4(C, A);
39         }
40 }
41