IBL.frag 703 B

123456789101112131415161718192021222324252627
  1. uniform sampler2D ntex;
  2. uniform sampler2D dtex;
  3. out vec4 Diff;
  4. out vec4 Spec;
  5. vec3 DecodeNormal(vec2 n);
  6. vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
  7. vec3 DiffuseIBL(vec3 normal);
  8. vec3 SpecularIBL(vec3 normal, vec3 V, float roughness);
  9. void main(void)
  10. {
  11. vec2 uv = gl_FragCoord.xy / screen;
  12. vec3 normal = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
  13. Diff = vec4(0.25 * DiffuseIBL(normal), 1.);
  14. float z = texture(dtex, uv).x;
  15. vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix);
  16. vec3 eyedir = -normalize(xpos.xyz);
  17. float specval = texture(ntex, uv).z;
  18. Spec = vec4(.25 * SpecularIBL(normal, eyedir, specval), 1.);
  19. }