LightShadingApplyIndirect.ankiprog 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #pragma anki start vert
  6. #include <AnKi/Shaders/QuadVert.glsl>
  7. #pragma anki end
  8. #pragma anki start frag
  9. #include <AnKi/Shaders/BilateralFilter.glsl>
  10. layout(set = 0, binding = 0) uniform sampler u_nearestAnyClampSampler;
  11. layout(set = 0, binding = 1) uniform sampler u_linearAnyClampSampler;
  12. layout(set = 0, binding = 2) uniform texture2D u_quarterDiffuseIndirectTex;
  13. layout(set = 0, binding = 3) uniform texture2D u_quarterDepthTex;
  14. layout(set = 0, binding = 4) uniform texture2D u_fullDepthTex;
  15. layout(set = 0, binding = 5) uniform texture2D u_gbuffer0Tex;
  16. layout(push_constant, std430) uniform b_pc
  17. {
  18. Vec2 u_quadTexelSize;
  19. Vec2 u_padding;
  20. };
  21. layout(location = 0) in Vec2 in_uv;
  22. layout(location = 0) out Vec3 out_color;
  23. void main()
  24. {
  25. // Reference
  26. const F32 depthCenter = textureLod(u_fullDepthTex, u_linearAnyClampSampler, in_uv, 0.0).x;
  27. // Do a bilateral upscale
  28. out_color = Vec3(0.0);
  29. const F32 radius = 1.0;
  30. F32 sumWeight = EPSILON;
  31. for(F32 x = -radius; x <= radius; x += 1.0)
  32. {
  33. for(F32 y = -radius; y <= radius; y += 1.0)
  34. {
  35. const Vec2 sampleUv = in_uv + Vec2(x, y) * u_quadTexelSize;
  36. const F32 depthTap = textureLod(u_quarterDepthTex, u_linearAnyClampSampler, sampleUv, 0.0).x;
  37. const F32 w = calculateBilateralWeightDepth(depthCenter, depthTap, 1.0);
  38. sumWeight += w;
  39. const Vec3 colorTap = textureLod(u_quarterDiffuseIndirectTex, u_nearestAnyClampSampler, sampleUv, 0.0).xyz;
  40. out_color += colorTap * w;
  41. }
  42. }
  43. // Modulate
  44. out_color /= sumWeight;
  45. const Vec3 albedo = textureLod(u_gbuffer0Tex, u_linearAnyClampSampler, in_uv, 0.0).xyz;
  46. out_color *= albedo;
  47. }
  48. #pragma anki end