PPSSAOBlur.bsl 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "$ENGINE$\PPBase.bslinc"
  2. #include "$ENGINE$\PerCameraData.bslinc"
  3. shader PPSSAOBlur
  4. {
  5. mixin PPBase;
  6. mixin PerCameraData;
  7. variations
  8. {
  9. DIR_HORZ = { true, false };
  10. };
  11. code
  12. {
  13. [internal]
  14. cbuffer Input
  15. {
  16. float2 gPixelSize;
  17. float2 gPixelOffset;
  18. float gInvDepthThreshold;
  19. }
  20. SamplerState gInputSamp;
  21. Texture2D gInputTex;
  22. Texture2D gDepthTex;
  23. static const int NUM_SAMPLES = 2;
  24. float fsmain(VStoFS input) : SV_Target0
  25. {
  26. float centerDepth = convertFromDeviceZ(gDepthTex.Sample(gInputSamp, input.uv0).r);
  27. float weightedSum = 0.0f;
  28. float weightSum = 0.0f;
  29. float centerAO = gInputTex.Sample(gInputSamp, input.uv0).r;
  30. weightedSum += centerAO;
  31. weightSum += 1.0f;
  32. // Note: Consider using normals as a weight as well
  33. [unroll]
  34. for(int i = 1; i < (NUM_SAMPLES + 1); ++i)
  35. {
  36. float2 sampleUV = gPixelSize * i + input.uv0;
  37. float sampleAO = gInputTex.Sample(gInputSamp, sampleUV).r;
  38. float sampleDepth = convertFromDeviceZ(gDepthTex.Sample(gInputSamp, sampleUV).r);
  39. float weight = saturate(1.0f - abs(sampleDepth - centerDepth) * gInvDepthThreshold);
  40. weightedSum += sampleAO * weight;
  41. weightSum += weight;
  42. }
  43. [unroll]
  44. for(int i = -NUM_SAMPLES; i < 0; ++i)
  45. {
  46. float2 sampleUV = gPixelSize * i + input.uv0;
  47. float sampleAO = gInputTex.Sample(gInputSamp, sampleUV).r;
  48. float sampleDepth = convertFromDeviceZ(gDepthTex.Sample(gInputSamp, sampleUV).r);
  49. float weight = saturate(1.0f - abs(sampleDepth - centerDepth) * gInvDepthThreshold);
  50. weightedSum += sampleAO * weight;
  51. weightSum += weight;
  52. }
  53. return weightedSum / weightSum;
  54. }
  55. };
  56. };