PPSSRStencil.bsl 1.4 KB

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