Continuous distribution
[clouds.git] / billboardfrag.glsl
index 840ec895609039c2989a77f69b2d56c12448e910..046b7bd3bca6e335cd847e6e6dc4151f4edf03fa 100644 (file)
@@ -3,7 +3,31 @@ uniform vec4 color;
 uniform sampler2D tex;
 in vec2 texCoord;
 out vec4 FragColor;
+uniform bool modulate;
+uniform bool debugContDist;
+uniform float density;
 void main() {
-  FragColor = texture(tex, texCoord).r * color;
+  if (debugContDist) {
+    FragColor = mix(vec4(1, 1, 1, 1), vec4(1, 0, 0, 1), density);
+    return;
+  }
+       // Cf = color from fragment, Ct = color from texture
+       // Cc = color from texture environment -- not set, defaults to (0,0,0,0)
+       // Af = alpha from fragment, At = alpha from texture
+       // C = output color, A = output alpha
+       float f = texture(tex, texCoord).r;
+       if (modulate) { 
+               // GL_MODULATE: C
+               // C = Cf * Ct
+               // A = Af * At                          
+               FragColor = color * f;
+       } else {
+               // GL_BLEND:
+               // C = Cf * (1-Ct) + Cc * Ct
+               // A = Af * At
+               vec3 C = color.rgb * (1 - f);
+               float A = color.a * f;
+               FragColor = vec4(C, A);
+       }
 }