Advertisement
Zgragselus

No for loops cascaded shadow maps

Mar 5th, 2023 (edited)
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.89 KB | None | 0 0
  1. uint numCascades = asuint(Lights[i].data1.x);
  2.  
  3. [branch] if (numCascades > 0)
  4. {
  5.     float4 positionProj = float4(0.0f, 0.0f, 0.0f, 0.0f);
  6.  
  7.     [flatten] if (posz < Lights[i].data4[0])
  8.     {
  9.         positionProj = ShadowMap_ProjectionCoord(ShadowAtlas[asuint(Lights[i].data2[0])].shadowMatrix, positionWS, dirLight.offset, ShadowAtlas[asuint(Lights[i].data2[0])].size, ShadowAtlas[asuint(Lights[i].data2[0])].offset, false, 1.0f, 0.0f);
  10.         shadowMask *= ShadowMap_Naive(ShadowMap, PointSampler, positionProj.xyz);
  11.         cascadeMul = float3(1.0f, 0.0f, 0.0f);
  12.     }
  13.     else if (numCascades > 1)
  14.     {
  15.         [flatten] if (posz < Lights[i].data4[1])
  16.         {
  17.             positionProj = ShadowMap_ProjectionCoord(ShadowAtlas[asuint(Lights[i].data2[1])].shadowMatrix, positionWS, dirLight.offset, ShadowAtlas[asuint(Lights[i].data2[1])].size, ShadowAtlas[asuint(Lights[i].data2[1])].offset, false, 1.0f, 0.0f);
  18.             shadowMask *= ShadowMap_Naive(ShadowMap, PointSampler, positionProj.xyz);
  19.             cascadeMul = float3(0.0f, 1.0f, 0.0f);
  20.         }
  21.         else if (numCascades > 2)
  22.         {
  23.             [flatten] if (posz < Lights[i].data4[2])
  24.             {
  25.                 positionProj = ShadowMap_ProjectionCoord(ShadowAtlas[asuint(Lights[i].data2[2])].shadowMatrix, positionWS, dirLight.offset, ShadowAtlas[asuint(Lights[i].data2[2])].size, ShadowAtlas[asuint(Lights[i].data2[2])].offset, false, 1.0f, 0.0f);
  26.                 shadowMask *= ShadowMap_Naive(ShadowMap, PointSampler, positionProj.xyz);
  27.                 cascadeMul = float3(0.0f, 0.0f, 1.0f);
  28.             }
  29.             else if (numCascades > 3)
  30.             {
  31.                 [flatten] if (posz < Lights[i].data4[3])
  32.                 {
  33.                     positionProj = ShadowMap_ProjectionCoord(ShadowAtlas[asuint(Lights[i].data2[3])].shadowMatrix, positionWS, dirLight.offset, ShadowAtlas[asuint(Lights[i].data2[3])].size, ShadowAtlas[asuint(Lights[i].data2[3])].offset, false, 1.0f, 0.0f);
  34.                     shadowMask *= ShadowMap_Naive(ShadowMap, PointSampler, positionProj.xyz);
  35.                     cascadeMul = float3(1.0f, 1.0f, 0.0f);
  36.                 }
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement