stk-code_catmod/data/shaders/sunlight.frag

39 lines
1.1 KiB
GLSL
Raw Normal View History

uniform sampler2D ntex;
2014-01-27 14:08:59 -05:00
uniform sampler2D dtex;
uniform vec3 sundirection;
uniform vec3 sun_color;
2016-09-12 15:39:52 -04:00
#ifdef GL_ES
layout (location = 0) out vec4 Diff;
layout (location = 1) out vec4 Spec;
#else
out vec4 Diff;
out vec4 Spec;
2016-09-12 15:39:52 -04:00
#endif
#stk_include "utils/decodeNormal.frag"
#stk_include "utils/SpecularBRDF.frag"
#stk_include "utils/DiffuseBRDF.frag"
#stk_include "utils/getPosFromUVDepth.frag"
#stk_include "utils/SunMRP.frag"
2014-11-20 20:44:27 -05:00
void main() {
vec2 uv = gl_FragCoord.xy / u_screen;
float z = texture(dtex, uv).x;
vec4 xpos = getPosFromUVDepth(vec3(uv, z), u_inverse_projection_matrix);
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
2014-04-06 16:19:10 -04:00
float roughness = texture(ntex, uv).z;
2014-04-06 15:23:09 -04:00
vec3 eyedir = -normalize(xpos.xyz);
2014-12-21 15:05:41 -05:00
vec3 Lightdir = SunMRP(norm, eyedir);
float NdotL = clamp(dot(norm, Lightdir), 0., 1.);
vec3 Specular = SpecularBRDF(norm, eyedir, Lightdir, vec3(1.), roughness);
vec3 Diffuse = DiffuseBRDF(norm, eyedir, Lightdir, vec3(1.), roughness);
Diff = vec4(NdotL * Diffuse * sun_color, 1.);
Spec = vec4(NdotL * Specular * sun_color, 1.);
}