volumetriclight.frag 1008 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifdef Use_Bindless_Texture
  2. layout(bindless_sampler) uniform sampler2D tex;
  3. #else
  4. uniform sampler2D tex;
  5. #endif
  6. uniform float fogmax;
  7. uniform float startH;
  8. uniform float endH;
  9. uniform float start;
  10. uniform float end;
  11. uniform vec3 col;
  12. in vec2 uv;
  13. in vec4 color;
  14. out vec4 FragColor;
  15. void main()
  16. {
  17. vec4 diffusecolor = texture(tex, uv);
  18. #ifdef Use_Bindless_Texture
  19. diffusecolor.xyz = pow(diffusecolor.xyz, vec3(2.2));
  20. #endif
  21. diffusecolor.xyz *= pow(color.xyz, vec3(2.2));
  22. diffusecolor.a *= color.a;
  23. vec3 tmp = vec3(gl_FragCoord.xy / screen, gl_FragCoord.z);
  24. tmp = 2. * tmp - 1.;
  25. vec4 xpos = vec4(tmp, 1.0);
  26. xpos = InverseProjectionMatrix * xpos;
  27. xpos.xyz /= xpos.w;
  28. float dist = length(xpos.xyz);
  29. float fog = smoothstep(start, end, dist);
  30. fog = min(fog, fogmax);
  31. vec4 finalcolor = vec4(col, 0.) * fog + diffusecolor *(1. - fog);
  32. FragColor = vec4(finalcolor.rgb * finalcolor.a, finalcolor.a);
  33. //FragColor = vec4(1.0, 0.0, 0.0, finalcolor.a);
  34. }