stk-code_catmod/data/shaders/IBL.frag
Vincent Lejeune 2667791621 Tweak IBL
2014-12-08 19:36:23 +01:00

27 lines
703 B
GLSL

uniform sampler2D ntex;
uniform sampler2D dtex;
out vec4 Diff;
out vec4 Spec;
vec3 DecodeNormal(vec2 n);
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
vec3 DiffuseIBL(vec3 normal);
vec3 SpecularIBL(vec3 normal, vec3 V, float roughness);
void main(void)
{
vec2 uv = gl_FragCoord.xy / screen;
vec3 normal = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
Diff = vec4(0.25 * DiffuseIBL(normal), 1.);
float z = texture(dtex, uv).x;
vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix);
vec3 eyedir = -normalize(xpos.xyz);
float specval = texture(ntex, uv).z;
Spec = vec4(.25 * SpecularIBL(normal, eyedir, specval), 1.);
}