Skip to content

Commit f3d659a

Browse files
alexey-unityEvergreen
authored andcommitted
[srp] added casts ot int of CubeMapFaceID where needed
1 parent 4b2fd4f commit f3d659a

3 files changed

Lines changed: 15 additions & 13 deletions

File tree

  • Packages
    • com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop
    • com.unity.render-pipelines.universal/ShaderLibrary
    • com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary

Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/HDShadow.hlsl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ float GetPunctualShadowAttenuation(HDShadowContext shadowContext, float2 positio
4949

5050
if (pointLight)
5151
{
52-
sd.rot0 = shadowContext.shadowDatas[shadowDataIndex + CubeMapFaceID(-L)].rot0;
53-
sd.rot1 = shadowContext.shadowDatas[shadowDataIndex + CubeMapFaceID(-L)].rot1;
54-
sd.rot2 = shadowContext.shadowDatas[shadowDataIndex + CubeMapFaceID(-L)].rot2;
55-
sd.atlasOffset = shadowContext.shadowDatas[shadowDataIndex + CubeMapFaceID(-L)].atlasOffset;
52+
const int cubeFaceOffset = CubeMapFaceID(-L);
53+
sd.rot0 = shadowContext.shadowDatas[shadowDataIndex + cubeFaceOffset].rot0;
54+
sd.rot1 = shadowContext.shadowDatas[shadowDataIndex + cubeFaceOffset].rot1;
55+
sd.rot2 = shadowContext.shadowDatas[shadowDataIndex + cubeFaceOffset].rot2;
56+
sd.atlasOffset = shadowContext.shadowDatas[shadowDataIndex + cubeFaceOffset].atlasOffset;
5657
}
5758

5859
if (sd.isInCachedAtlas > 0) // This is a scalar branch.
@@ -77,11 +78,12 @@ float GetPunctualShadowClosestDistance(HDShadowContext shadowContext, SamplerSta
7778

7879
if (pointLight)
7980
{
80-
sd.shadowToWorld = shadowContext.shadowDatas[shadowDataIndex + CubeMapFaceID(-L)].shadowToWorld;
81-
sd.atlasOffset = shadowContext.shadowDatas[shadowDataIndex + CubeMapFaceID(-L)].atlasOffset;
82-
sd.rot0 = shadowContext.shadowDatas[shadowDataIndex + CubeMapFaceID(-L)].rot0;
83-
sd.rot1 = shadowContext.shadowDatas[shadowDataIndex + CubeMapFaceID(-L)].rot1;
84-
sd.rot2 = shadowContext.shadowDatas[shadowDataIndex + CubeMapFaceID(-L)].rot2;
81+
const int cubeFaceOffset = CubeMapFaceID(-L);
82+
sd.shadowToWorld = shadowContext.shadowDatas[shadowDataIndex + cubeFaceOffset].shadowToWorld;
83+
sd.atlasOffset = shadowContext.shadowDatas[shadowDataIndex + cubeFaceOffset].atlasOffset;
84+
sd.rot0 = shadowContext.shadowDatas[shadowDataIndex + cubeFaceOffset].rot0;
85+
sd.rot1 = shadowContext.shadowDatas[shadowDataIndex + cubeFaceOffset].rot1;
86+
sd.rot2 = shadowContext.shadowDatas[shadowDataIndex + cubeFaceOffset].rot2;
8587
}
8688

8789
if (sd.isInCachedAtlas > 0) // This is a scalar branch.

Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ half AdditionalLightRealtimeShadow(int lightIndex, float3 positionWS, half3 ligh
406406
if (isPointLight)
407407
{
408408
// This is a point light, we have to find out which shadow slice to sample from
409-
float cubemapFaceId = CubeMapFaceID(-lightDirection);
410-
shadowSliceIndex += cubemapFaceId;
409+
const int cubeFaceOffset = CubeMapFaceID(-lightDirection);
410+
shadowSliceIndex += cubeFaceOffset;
411411
}
412412

413413
#if USE_STRUCTURED_BUFFER_FOR_LIGHT_DATA

Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Shadows.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ half AdditionalLightRealtimeShadow(int lightIndex, float3 positionWS, half3 ligh
326326
if (isPointLight)
327327
{
328328
// This is a point light, we have to find out which shadow slice to sample from
329-
float cubemapFaceId = CubeMapFaceID(-lightDirection);
330-
shadowSliceIndex += cubemapFaceId;
329+
const int cubeFaceOffset = CubeMapFaceID(-lightDirection);
330+
shadowSliceIndex += cubeFaceOffset;
331331
}
332332

333333
#if USE_STRUCTURED_BUFFER_FOR_LIGHT_DATA

0 commit comments

Comments
 (0)