X-Git-Url: http://git.lukelau.me/?a=blobdiff_plain;f=billboardfrag.glsl;h=b4cfd511464569ea23c577cda41a5b261c7ba288;hb=c8b0a84bbafd306103b005e7e238b11a656dcba3;hp=840ec895609039c2989a77f69b2d56c12448e910;hpb=69b74f1d5e67236a5396b75628a6e1be0e501631;p=clouds.git diff --git a/billboardfrag.glsl b/billboardfrag.glsl index 840ec89..b4cfd51 100644 --- a/billboardfrag.glsl +++ b/billboardfrag.glsl @@ -3,7 +3,41 @@ uniform vec4 color; uniform sampler2D tex; in vec2 texCoord; out vec4 FragColor; +uniform bool modulate; +uniform bool debug; +uniform bool debugColor; +uniform float debugVal; void main() { - FragColor = texture(tex, texCoord).r * color; + if (debugColor) { + FragColor = color; + return; + } + if (debug) { + FragColor = mix(vec4(1, 1, 1, 0), vec4(1, 0, 0, 1), debugVal); + 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 + // the +0.06 is a hack to get lighter clouds! + // can be thought of as ambient light + FragColor = color * (f + 0.02); + } else { + // "That is, the colors in the frame buffer are multiplied by the + // attenuation ratio of the billboard texture and then the colors in + // the texture are added" + // 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); + } }