Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

- Fixed sub-shadow rendering for cached shadow maps.
- Fixed PCSS filtering issues with cached shadow maps.

### Changed
- Removed the material pass probe volumes evaluation mode.
- Unifying the history validation pass so that it is only done once for the whole frame and not per effect.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,8 @@ internal int shadowPrecision
// Data for cached shadow maps
[System.NonSerialized]
internal int lightIdxForCachedShadows = -1;
Vector3 m_CachedViewPos = new Vector3(0, 0, 0);

Vector3[] m_CachedViewPositions;


[System.NonSerialized]
Expand Down Expand Up @@ -1983,11 +1984,12 @@ internal void ReserveShadowMap(Camera camera, HDShadowManager shadowManager, HDS
return;

// Create shadow requests array using the light type
if (shadowRequests == null || m_ShadowRequestIndices == null)
if (shadowRequests == null || m_ShadowRequestIndices == null || m_CachedViewPositions == null)
{
const int maxLightShadowRequestsCount = 6;
shadowRequests = new HDShadowRequest[maxLightShadowRequestsCount];
m_ShadowRequestIndices = new int[maxLightShadowRequestsCount];
m_CachedViewPositions = new Vector3[maxLightShadowRequestsCount];

for (int i = 0; i < maxLightShadowRequestsCount; i++)
{
Expand Down Expand Up @@ -2208,9 +2210,12 @@ internal int UpdateShadowRequest(HDCamera hdCamera, HDShadowManager manager, HDS
if (shadowRequestIndex == -1)
continue;

shadowRequest.dynamicAtlasViewport = resolutionRequest.dynamicAtlasViewport;
shadowRequest.cachedAtlasViewport = resolutionRequest.cachedAtlasViewport;

if (needToUpdateCachedContent)
{
m_CachedViewPos = cameraPos;
m_CachedViewPositions[index] = cameraPos;
shadowRequest.cachedShadowData.cacheTranslationDelta = new Vector3(0.0f, 0.0f, 0.0f);

// Write per light type matrices, splitDatas and culling parameters
Expand All @@ -2222,7 +2227,7 @@ internal int UpdateShadowRequest(HDCamera hdCamera, HDShadowManager manager, HDS
}
else if (hasCachedComponent)
{
shadowRequest.cachedShadowData.cacheTranslationDelta = cameraPos - m_CachedViewPos;
shadowRequest.cachedShadowData.cacheTranslationDelta = cameraPos - m_CachedViewPositions[index];
shadowRequest.shouldUseCachedShadowData = true;
shadowRequest.shouldRenderCachedComponent = false;
// If directional we still need to calculate the split data.
Expand All @@ -2239,8 +2244,6 @@ internal int UpdateShadowRequest(HDCamera hdCamera, HDShadowManager manager, HDS
UpdateShadowRequestData(hdCamera, manager, shadowSettings, visibleLight, cullResults, lightIndex, lightingDebugSettings, filteringQuality, viewportSize, lightType, index, ref shadowRequest);
}

shadowRequest.dynamicAtlasViewport = resolutionRequest.dynamicAtlasViewport;
shadowRequest.cachedAtlasViewport = resolutionRequest.cachedAtlasViewport;
manager.UpdateShadowRequest(shadowRequestIndex, shadowRequest, updateType);

if (needToUpdateCachedContent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ void LoadDirectionalShadowDatas(inout HDShadowData sd, HDShadowContext shadowCon
sd.shadowFilterParams0.x = shadowContext.shadowDatas[index].shadowFilterParams0.x;
sd.zBufferParam = shadowContext.shadowDatas[index].zBufferParam;
#endif
sd.cacheTranslationDelta = shadowContext.shadowDatas[index].cacheTranslationDelta;
}

float EvalShadow_CascadedDepth_Blend_SplitIndex(HDShadowContext shadowContext, Texture2D tex, SamplerComparisonState samp, float2 positionSS, float3 positionWS, float3 normalWS, int index, float3 L, out int shadowSplitIndex)
Expand All @@ -244,11 +245,13 @@ float EvalShadow_CascadedDepth_Blend_SplitIndex(HDShadowContext shadowContext, T
float shadow = 1.0;
shadowSplitIndex = EvalShadow_GetSplitIndex(shadowContext, index, positionWS, alpha, cascadeCount);

float3 basePositionWS = positionWS;

if (shadowSplitIndex >= 0.0)
{
HDShadowData sd = shadowContext.shadowDatas[index];
LoadDirectionalShadowDatas(sd, shadowContext, index + shadowSplitIndex);
positionWS = positionWS + sd.cacheTranslationDelta.xyz;
positionWS = basePositionWS + sd.cacheTranslationDelta.xyz;

/* normal based bias */
float3 orig_pos = positionWS;
Expand All @@ -269,8 +272,9 @@ float EvalShadow_CascadedDepth_Blend_SplitIndex(HDShadowContext shadowContext, T
if (alpha > 0.0)
{
LoadDirectionalShadowDatas(sd, shadowContext, index + shadowSplitIndex);
float3 evaluationPosWS = basePositionWS + sd.cacheTranslationDelta.xyz + normalBias;
float3 posNDC;
posTC = EvalShadow_GetTexcoordsAtlas(sd, _CascadeShadowAtlasSize.zw, positionWS, posNDC, false);
posTC = EvalShadow_GetTexcoordsAtlas(sd, _CascadeShadowAtlasSize.zw, evaluationPosWS, posNDC, false);
/* sample the texture */
UNITY_BRANCH
if (all(abs(posNDC.xy) <= (1.0 - sd.shadowMapSize.zw * 0.5)))
Expand All @@ -296,11 +300,13 @@ float EvalShadow_CascadedDepth_Dither_SplitIndex(HDShadowContext shadowContext,
float shadow = 1.0;
shadowSplitIndex = EvalShadow_GetSplitIndex(shadowContext, index, positionWS, alpha, cascadeCount);

float3 basePositionWS = positionWS;

if (shadowSplitIndex >= 0.0)
{
HDShadowData sd = shadowContext.shadowDatas[index];
LoadDirectionalShadowDatas(sd, shadowContext, index + shadowSplitIndex);
positionWS = positionWS + sd.cacheTranslationDelta.xyz;
positionWS = basePositionWS + sd.cacheTranslationDelta.xyz;

/* normal based bias */
float worldTexelSize = sd.worldTexelSize;
Expand All @@ -313,6 +319,7 @@ float EvalShadow_CascadedDepth_Dither_SplitIndex(HDShadowContext shadowContext,
if (evalNextCascade)
{
LoadDirectionalShadowDatas(sd, shadowContext, index + nextSplit);
positionWS = basePositionWS + sd.cacheTranslationDelta.xyz;
float biasModifier = (sd.worldTexelSize / worldTexelSize);
normalBias *= biasModifier;
}
Expand Down