PPGaussianDOFCombine.bsl 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "$ENGINE$\PPBase.bslinc"
  2. #include "$ENGINE$\PPGaussianDOFCommon.bslinc"
  3. shader PPGaussianDOFCombine
  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 gFocusedTex;
  16. Texture2D gNearTex;
  17. Texture2D gFarTex;
  18. SamplerState gDepthSamp;
  19. Texture2D gDepthTex;
  20. float4 fsmain(VStoFS input) : SV_Target0
  21. {
  22. float4 focusedColor = gFocusedTex.Sample(gColorSamp, input.uv0);
  23. float depth = -convertFromDeviceZ(gDepthTex.SampleLevel(gDepthSamp, input.uv0, 0));
  24. float4 nearColor = 0;
  25. float4 farColor = 0;
  26. float bias = 0.00001f; // To avoid div by zero
  27. #if NEAR
  28. nearColor = gNearTex.Sample(gColorSamp, input.uv0);
  29. nearColor.rgb /= (nearColor.a + bias);
  30. #endif
  31. #if FAR
  32. farColor = gFarTex.Sample(gColorSamp, input.uv0);
  33. farColor.rgb /= (farColor.a + bias);
  34. #endif
  35. float3 combined;
  36. // Background layer
  37. combined = farColor.rgb;
  38. // Focused layer
  39. //// This uses value of background layer as long as the background mask strength is
  40. //// higher than 0.2f. For strength lower than 0.2f it blends with the focused layer.
  41. float focusedMask = calcFarMask(depth);
  42. focusedMask = saturate(1.0f - focusedMask * 5.0f);
  43. focusedMask *= focusedMask;
  44. combined = lerp(combined, focusedColor.rgb, focusedMask);
  45. // Foreground layer
  46. //// Same type of blending as with the layer above
  47. float foregroundMask = calcNearMask(depth);
  48. foregroundMask = saturate(foregroundMask * 5.0f);
  49. foregroundMask *= foregroundMask;
  50. combined = lerp(combined, nearColor.rgb, foregroundMask);
  51. // Alpha channel contains luma required for FXAA
  52. return float4(combined, focusedColor.a);
  53. }
  54. };
  55. };