Skip to content

Commit 86ca8fe

Browse files
pema99Evergreen
authored andcommitted
Handle reassigning cubemap in URP reflection probe atlas
1 parent 0df4e19 commit 86ca8fe

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

Packages/com.unity.render-pipelines.universal/Runtime/ReflectionProbeManager.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ unsafe struct CachedProbe
4040
public Texture texture;
4141
public int lastUsed;
4242
public Vector4 hdrData;
43+
public ReflectionProbe sourceProbe;
4344
}
4445

4546
static class ShaderProperties
@@ -116,10 +117,15 @@ public unsafe void UpdateGpuData(CommandBuffer cmd, ref CullingResults cullResul
116117
// Populate list of probes we need to remove to avoid modifying dictionary while iterating.
117118
foreach (var (id, cachedProbe) in m_Cache)
118119
{
119-
// Evict probe if not used for more than 1 frame, if the texture no longer exists, or if the size changed.
120+
// Evict probe if any of the following are true:
121+
// - Probe was not used for more than 1 frame
122+
// - The texture no longer exists
123+
// - The texture size changed
124+
// - The cached texture no longer matches the texture of the reflection probe (it was reassigned)
120125
if (Math.Abs(cachedProbe.lastUsed - frameIndex) > 1 ||
121126
!cachedProbe.texture ||
122-
cachedProbe.size != cachedProbe.texture.width)
127+
cachedProbe.size != cachedProbe.texture.width ||
128+
(cachedProbe.sourceProbe && cachedProbe.texture != cachedProbe.sourceProbe.texture))
123129
{
124130
m_NeedsRemove.Add(id);
125131
for (var i = 0; i < k_MaxMipCount; i++)
@@ -176,6 +182,7 @@ public unsafe void UpdateGpuData(CommandBuffer cmd, ref CullingResults cullResul
176182
var level = m_AtlasAllocator.levelCount + 2 - mipCount;
177183
cachedProbe.mipCount = math.min(mipCount, k_MaxMipCount);
178184
cachedProbe.texture = texture;
185+
cachedProbe.sourceProbe = probe.reflectionProbe;
179186

180187
var mip = 0;
181188
for (; mip < cachedProbe.mipCount; mip++)

0 commit comments

Comments
 (0)