sunlight.frag 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. uniform sampler2D ntex;
  2. uniform sampler2D dtex;
  3. out vec4 Diff;
  4. out vec4 Spec;
  5. vec3 DecodeNormal(vec2 n);
  6. vec3 SpecularBRDF(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness);
  7. vec3 DiffuseBRDF(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness);
  8. vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
  9. vec3 SunMRP(vec3 normal, vec3 eyedir);
  10. void main() {
  11. vec2 uv = gl_FragCoord.xy / screen;
  12. float z = texture(dtex, uv).x;
  13. vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix);
  14. vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
  15. float roughness = texture(ntex, uv).z;
  16. vec3 eyedir = -normalize(xpos.xyz);
  17. vec3 Lightdir = SunMRP(norm, eyedir);
  18. float NdotL = clamp(dot(norm, Lightdir), 0., 1.);
  19. vec3 Specular = SpecularBRDF(norm, eyedir, Lightdir, vec3(1.), roughness);
  20. vec3 Diffuse = DiffuseBRDF(norm, eyedir, Lightdir, vec3(1.), roughness);
  21. Diff = vec4(NdotL * Diffuse * sun_col, 1.);
  22. Spec = vec4(NdotL * Specular * sun_col, 1.);
  23. /* if (hasclouds == 1)
  24. {
  25. vec2 cloudcoord = (xpos.xz * 0.00833333) + wind;
  26. float cloud = texture(cloudtex, cloudcoord).x;
  27. //float cloud = step(0.5, cloudcoord.x) * step(0.5, cloudcoord.y);
  28. outcol *= cloud;
  29. }*/
  30. }