Skip to content

Commit 8ad7625

Browse files
Antoine Lelievresebastienlagarde
andauthored
Fix cookie srgb (#297)
* Fixed srgb flag not updating the cookie atlas * Updated changelog Co-authored-by: sebastienlagarde <[email protected]>
1 parent 7c09c04 commit 8ad7625

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
573573
- DXR: Fixed shader compilation error with shader graph and pathtracer
574574
- Fixed issue with screen-space shadows not enabled properly when RT is disabled (case 1235821)
575575
- Fixed a performance issue with stochastic ray traced area shadows.
576+
- Fixed cookie texture not updated when changing an import settings (srgb for example).
576577

577578
### Changed
578579
- Improve MIP selection for decals on Transparents

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Utility/Texture2DAtlas.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class Texture2DAtlas
142142
private AtlasAllocator m_AtlasAllocator = null;
143143
private Dictionary<int, Vector4> m_AllocationCache = new Dictionary<int, Vector4>();
144144
private Dictionary<int, uint> m_IsGPUTextureUpToDate = new Dictionary<int, uint>();
145+
private Dictionary<int, int> m_TextureHashes = new Dictionary<int, int>();
145146

146147
static readonly Vector4 fullScaleOffset = new Vector4(1, 1, 0, 0);
147148

@@ -280,6 +281,7 @@ public virtual bool AllocateTextureWithoutBlit(int instanceId, int width, int he
280281
scaleOffset.Scale(new Vector4(1.0f / m_Width, 1.0f / m_Height, 1.0f / m_Width, 1.0f / m_Height));
281282
m_AllocationCache.Add(instanceId, scaleOffset);
282283
MarkGPUTextureInvalid(instanceId); // the texture data haven't been uploaded
284+
m_TextureHashes[instanceId] = -1;
283285
return true;
284286
}
285287
else
@@ -291,10 +293,29 @@ public virtual bool AllocateTextureWithoutBlit(int instanceId, int width, int he
291293
public bool IsCached(out Vector4 scaleOffset, Texture texture)
292294
=> m_AllocationCache.TryGetValue(texture.GetInstanceID(), out scaleOffset);
293295

296+
protected int GetTextureHash(Texture texture)
297+
{
298+
int hash = texture.GetHashCode();
299+
300+
unchecked
301+
{
302+
hash = hash * 23 + texture.graphicsFormat.GetHashCode();
303+
hash = hash * 23 + texture.wrapMode.GetHashCode();
304+
hash = hash * 23 + texture.width.GetHashCode();
305+
hash = hash * 23 + texture.height.GetHashCode();
306+
hash = hash * 23 + texture.filterMode.GetHashCode();
307+
hash = hash * 23 + texture.anisoLevel.GetHashCode();
308+
hash = hash * 23 + texture.mipmapCount.GetHashCode();
309+
}
310+
311+
return hash;
312+
}
313+
294314
public virtual bool NeedsUpdate(Texture texture, bool needMips = false)
295315
{
296316
RenderTexture rt = texture as RenderTexture;
297317
int key = texture.GetInstanceID();
318+
int textureHash = GetTextureHash(texture);
298319

299320
// Update the render texture if needed
300321
if (rt != null)
@@ -311,6 +332,12 @@ public virtual bool NeedsUpdate(Texture texture, bool needMips = false)
311332
m_IsGPUTextureUpToDate[key] = rt.updateCount;
312333
}
313334
}
335+
// In case the texture settings/import settings have changed, we need to update it
336+
else if (m_TextureHashes.TryGetValue(key, out int hash) && hash != textureHash)
337+
{
338+
m_TextureHashes[key] = textureHash;
339+
return true;
340+
}
314341
// For regular textures, values == 0 means that their GPU data needs to be updated (either because
315342
// the atlas have been re-layouted or the texture have never been uploaded. We also check if the mips
316343
// are valid for the texture if we need them

0 commit comments

Comments
 (0)