PPSSAOBlur.bsl 1.6 KB

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