stk-code_catmod/data/shaders/sunlight.frag

56 lines
1.1 KiB
GLSL
Raw Normal View History

#version 130
uniform sampler2D ntex;
2014-01-27 14:08:59 -05:00
uniform sampler2D dtex;
2014-01-21 17:44:23 -05:00
//uniform sampler2D cloudtex;
2014-01-21 17:44:23 -05:00
uniform vec3 direction;
uniform vec3 col;
uniform mat4 invproj;
2014-01-21 17:44:23 -05:00
//uniform int hasclouds;
//uniform vec2 wind;
2014-01-21 17:44:23 -05:00
in vec2 uv;
out vec4 Diff;
out vec4 Spec;
out vec4 SpecularMap;
void main() {
2014-01-27 14:08:59 -05:00
float z = texture(dtex, uv).x;
2014-01-21 17:44:23 -05:00
vec4 xpos = 2.0 * vec4(uv, z, 1.0) - 1.0;
xpos = invproj * xpos;
xpos.xyz /= xpos.w;
if (z < 0.03)
{
// Skyboxes are fully lit
Diff = vec4(1.0);
Spec = vec4(1.0);
return;
}
vec3 norm = normalize(2. * texture(ntex, uv).xyz - 1.);
// Normalized on the cpu
2014-01-21 17:44:23 -05:00
vec3 L = direction;
float NdotL = max(0.0, dot(norm, L));
vec3 R = reflect(L, norm);
float RdotE = max(0.0, dot(R, normalize(xpos.xyz)));
float Specular = pow(RdotE, 200);
vec3 outcol = NdotL * col;
2014-01-21 17:44:23 -05:00
/* if (hasclouds == 1)
{
vec2 cloudcoord = (xpos.xz * 0.00833333) + wind;
float cloud = texture(cloudtex, cloudcoord).x;
//float cloud = step(0.5, cloudcoord.x) * step(0.5, cloudcoord.y);
outcol *= cloud;
2014-01-21 17:44:23 -05:00
}*/
Diff = vec4(NdotL * col, 1.);
Spec = vec4(Specular * col, 1.);
SpecularMap = vec4(1.0);
}