PPSSRStencil.bsl 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "$ENGINE$\PPBase.bslinc"
  2. #include "$ENGINE$\GBufferInput.bslinc"
  3. #include "$ENGINE$\PerCameraData.bslinc"
  4. shader PPSSRStencil
  5. {
  6. mixin PPBase;
  7. mixin PerCameraData;
  8. mixin GBufferInput;
  9. variations
  10. {
  11. MSAA_COUNT = { 1, 2 };
  12. MSAA_RESOLVE_0TH = { true, false };
  13. };
  14. stencil
  15. {
  16. enabled = true;
  17. reference = 1;
  18. front = { replace, replace, replace, always };
  19. writemask = 0x7F;
  20. };
  21. code
  22. {
  23. [internal]
  24. cbuffer Input
  25. {
  26. float2 gRoughnessScaleBias;
  27. }
  28. float fsmain(VStoFS input
  29. #if MSAA_COUNT > 1 && !MSAA_RESOLVE_0TH
  30. , uint sampleIdx : SV_SampleIndex
  31. #endif
  32. ) : SV_Target0
  33. {
  34. #if MSAA_COUNT > 1
  35. #if MSAA_RESOLVE_0TH
  36. SurfaceData surfData = getGBufferData(trunc(input.uv0.xy), 0);
  37. #else
  38. SurfaceData surfData = getGBufferData(trunc(input.uv0.xy), sampleIdx);
  39. #endif
  40. #else
  41. SurfaceData surfData = getGBufferData(input.uv0);
  42. #endif
  43. // Surfaces that are too rough fall back to refl. probes
  44. float fadeValue = 1.0f - saturate(surfData.roughness * gRoughnessScaleBias.x + gRoughnessScaleBias.y);
  45. // Reflection contribution is too low for dieletrics to waste performance on high quality reflections
  46. // 0 if metalness <= 0.4
  47. // [0, 1] if metalness > 0.4 && < 0.6
  48. // 1 if metalness >= 0.6
  49. fadeValue *= saturate(surfData.metalness * 5 - 2);
  50. if(fadeValue > 0.0f)
  51. discard;
  52. return 0.0f;
  53. }
  54. };
  55. };