stk-code_catmod/data/shaders/IBL.frag

27 lines
703 B
GLSL
Raw Normal View History

2014-03-01 14:08:17 -05:00
uniform sampler2D ntex;
2014-10-05 20:19:21 -04:00
uniform sampler2D dtex;
2014-03-01 14:08:17 -05:00
out vec4 Diff;
2014-10-05 20:19:21 -04:00
out vec4 Spec;
2014-03-01 14:08:17 -05:00
vec3 DecodeNormal(vec2 n);
2014-10-05 20:19:21 -04:00
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
2014-12-07 13:10:22 -05:00
vec3 DiffuseIBL(vec3 normal);
vec3 SpecularIBL(vec3 normal, vec3 V, float roughness);
2014-03-01 14:08:17 -05:00
void main(void)
{
2014-06-03 14:28:42 -04:00
vec2 uv = gl_FragCoord.xy / screen;
2014-03-01 14:08:17 -05:00
vec3 normal = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
2014-10-05 20:19:21 -04:00
2014-12-07 13:10:22 -05:00
Diff = vec4(0.25 * DiffuseIBL(normal), 1.);
2014-10-05 20:19:21 -04:00
float z = texture(dtex, uv).x;
vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix);
vec3 eyedir = -normalize(xpos.xyz);
2014-11-20 20:44:27 -05:00
float specval = texture(ntex, uv).z;
2014-12-07 13:10:22 -05:00
2014-12-08 13:36:23 -05:00
Spec = vec4(.25 * SpecularIBL(normal, eyedir, specval), 1.);
2014-03-01 14:08:17 -05:00
}