PPGaussianDOFSeparate.bsl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "$ENGINE$\PPBase.bslinc"
  2. #include "$ENGINE$\PPGaussianDOFCommon.bslinc"
  3. shader PPGaussianDOFSeparate
  4. {
  5. mixin PPBase;
  6. mixin PPGaussianDOFCommon;
  7. variations
  8. {
  9. NEAR = { true, false };
  10. FAR = { true, false };
  11. };
  12. code
  13. {
  14. SamplerState gColorSamp;
  15. Texture2D gColorTex;
  16. SamplerState gDepthSamp;
  17. Texture2D gDepthTex;
  18. void addSample(float2 uv, float2 offset, float depth, inout float4 nearColor, inout float4 farColor)
  19. {
  20. float4 smp;
  21. smp.rgb = gColorTex.SampleLevel(gColorSamp, uv + gHalfPixelOffset * offset, 0.0f).rgb;
  22. smp.a = 1.0f;
  23. #if NEAR
  24. nearColor += smp * calcNearMask(depth);
  25. #endif
  26. #if FAR
  27. farColor += smp * calcFarMask(depth);
  28. #endif
  29. }
  30. void fsmain(
  31. VStoFS input,
  32. out float4 output0 : SV_Target0
  33. #if NEAR && FAR
  34. , out float4 output1 : SV_Target1
  35. #endif
  36. )
  37. {
  38. float4 depth = -convertFromDeviceZ(gDepthTex.Gather(gDepthSamp, input.uv0));
  39. float4 nearColor = 0;
  40. float4 farColor = 0;
  41. // Samples start in bottom left and go in counter-clockwise order, in order to match
  42. // depth Gather
  43. addSample(input.uv0, float2(-1, 1), depth.x, nearColor, farColor);
  44. addSample(input.uv0, float2(1, 1), depth.y, nearColor, farColor);
  45. addSample(input.uv0, float2(1, -1), depth.z, nearColor, farColor);
  46. addSample(input.uv0, float2(-1, -1), depth.w, nearColor, farColor);
  47. nearColor *= 0.25f;
  48. farColor *= 0.25f;
  49. #if NEAR && FAR
  50. output0 = nearColor;
  51. output1 = farColor;
  52. #else
  53. #if NEAR
  54. output0 = nearColor;
  55. #else
  56. output0 = farColor;
  57. #endif
  58. #endif
  59. }
  60. };
  61. };