LightShadingApplyFog.ankiprog 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. ANKI_SPECIALIZATION_CONSTANT_U32(Z_SPLIT_COUNT, 0u);
  6. ANKI_SPECIALIZATION_CONSTANT_U32(FINAL_Z_SPLIT, 1u);
  7. #pragma anki start vert
  8. #include <AnKi/Shaders/QuadVert.glsl>
  9. #pragma anki end
  10. #pragma anki start frag
  11. #include <AnKi/Shaders/Functions.glsl>
  12. layout(location = 0) in Vec2 in_uv;
  13. layout(location = 0) out Vec4 out_color;
  14. layout(set = 0, binding = 0) uniform sampler u_nearestAnyClampSampler;
  15. layout(set = 0, binding = 1) uniform sampler u_linearAnyClampSampler;
  16. layout(set = 0, binding = 2) uniform texture2D u_depthRt;
  17. layout(set = 0, binding = 3) uniform texture3D u_fogVolume;
  18. layout(push_constant, std140, row_major) uniform b_pc
  19. {
  20. Vec2 u_padding;
  21. F32 u_near;
  22. F32 u_far;
  23. };
  24. void main()
  25. {
  26. Vec3 uvw;
  27. // Compute W coordinate
  28. const F32 depth = textureLod(u_depthRt, u_nearestAnyClampSampler, in_uv, 0.0).r;
  29. const F32 linearDepth = linearizeDepth(depth, u_near, u_far);
  30. uvw.z = linearDepth * (F32(Z_SPLIT_COUNT) / F32(FINAL_Z_SPLIT + 1u));
  31. // Compute UV coordinates
  32. uvw.xy = in_uv;
  33. // Read the volume
  34. const Vec4 fogVals = textureLod(u_fogVolume, u_linearAnyClampSampler, uvw, 0.0);
  35. const Vec3 inScattering = fogVals.rgb;
  36. const F32 transmittance = fogVals.a;
  37. // Apply the fog
  38. out_color = Vec4(inScattering, transmittance);
  39. }
  40. #pragma anki end