DeferredIBLSky.bsl 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #if MSAA
  2. #define MSAA_COUNT 2
  3. #else
  4. #define MSAA_COUNT 1
  5. #endif
  6. #include "$ENGINE$\GBufferInput.bslinc"
  7. #include "$ENGINE$\PPBase.bslinc"
  8. #include "$ENGINE$\PerCameraData.bslinc"
  9. #include "$ENGINE$\ImageBasedLighting.bslinc"
  10. #include "$ENGINE$\DirectLighting.bslinc"
  11. shader DeferredIBLFinalize
  12. {
  13. mixin PPBase;
  14. mixin GBufferInput;
  15. mixin PerCameraData;
  16. mixin ImageBasedLighting;
  17. mixin DirectLighting;
  18. blend
  19. {
  20. target
  21. {
  22. enabled = true;
  23. color = { dstA, one, add };
  24. };
  25. };
  26. variations
  27. {
  28. MSAA = { true, false };
  29. MSAA_RESOLVE_0TH = { true, false };
  30. };
  31. #if MSAA
  32. stencil
  33. {
  34. enabled = true;
  35. readmask = 0x80;
  36. #if INSIDE_GEOMETRY
  37. back = { keep, keep, keep, eq };
  38. #else
  39. front = { keep, keep, keep, eq };
  40. #endif
  41. #if MSAA_RESOLVE_0TH
  42. reference = 0;
  43. #else
  44. reference = 0x80;
  45. #endif
  46. };
  47. #endif
  48. code
  49. {
  50. float4 fsmain(VStoFS input, float4 pixelPos : SV_Position
  51. #if MSAA_COUNT > 1 && !MSAA_RESOLVE_0TH
  52. , uint sampleIdx : SV_SampleIndex
  53. #endif
  54. ) : SV_Target0
  55. {
  56. #if MSAA_COUNT > 1
  57. #if MSAA_RESOLVE_0TH
  58. SurfaceData surfaceData = getGBufferData((uint2)pixelPos.xy, 0);
  59. #else
  60. SurfaceData surfaceData = getGBufferData((uint2)pixelPos.xy, sampleIdx);
  61. #endif
  62. #else
  63. SurfaceData surfaceData = getGBufferData((uint2)pixelPos.xy);
  64. #endif
  65. if(surfaceData.worldNormal.w > 0.0f && gSkyCubemapAvailable > 0 && gUseReflectionMaps != 0)
  66. {
  67. float3 worldPosition = NDCToWorld(input.screenPos, surfaceData.depth);
  68. float3 V = normalize(gViewOrigin - worldPosition);
  69. float3 N = surfaceData.worldNormal.xyz;
  70. float3 R = 2 * dot(V, N) * N - V;
  71. float3 specR = getSpecularDominantDir(N, R, surfaceData.roughness);
  72. float skyMipLevel = mapRoughnessToMipLevel(surfaceData.roughness, gSkyCubemapNumMips);
  73. float4 skySample = gSkyReflectionTex.SampleLevel(gSkyReflectionSamp, specR, skyMipLevel) * gSkyBrightness;
  74. return float4(skySample.rgb, 1.0f);
  75. }
  76. else
  77. return float4(0.0f, 0.0f, 0.0f, 0.0f);
  78. }
  79. };
  80. };