PPGaussianDOFSeparate.bsl 1.5 KB

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