stk-code_catmod/data/shaders/shadowgen.frag
2013-11-30 21:33:06 +00:00

45 lines
862 B
GLSL

uniform sampler2D halft; // half is a reserved word
uniform sampler2D quarter;
uniform sampler2D eighth;
void main()
{
vec3 val[3];
val[0] = texture2D(halft, gl_TexCoord[0].xy).xyz;
val[1] = texture2D(quarter, gl_TexCoord[0].xy).xyz;
val[2] = texture2D(eighth, gl_TexCoord[0].xy).xyz;
// Find the first level with a penumbra value
int i;
float q = 0.0;
float outval = 1.0;
float hasshadow = dot(vec3(1.0), vec3(val[0].z, val[1].z, val[2].z));
if (hasshadow > 0.9)
{
for (i = 0; i < 3; i++)
{
if (val[i].z > 0.9)
{
q = val[i].y;
break;
}
}
q *= 8.0;
q = max(1.0, q);
q = log2(q);
q = min(1.9, q);
// q is now between 0 and 1.9.
int down = int(floor(q));
int up = down + 1;
float interp = q - float(down);
outval = 1.0 - mix(val[down].x, val[up].x, interp);
}
gl_FragColor = vec4(vec3(outval), 1.0);
}