Skip to content

Commit 97b9eb1

Browse files
Antoine Lelievresebastienlagarde
authored andcommitted
Fix cookie srgb #297
1 parent a6a989e commit 97b9eb1

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
@@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4040
- Fixed issue with light layers bigger than 8 (and above the supported range).
4141
- Fixed an issue where decals were duplicated in prefab isolation mode.
4242
- Fixed the valid TRS test failing due to variable not being initialized to the identity matrix in RTShadows (1220600).
43+
- Fixed cookie texture not updated when changing an import settings (srgb for example).
4344

4445
### Changed
4546
- Shadowmask and realtime reflection probe property are hide in Quality settings

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
@@ -141,6 +141,7 @@ class Texture2DAtlas
141141
private AtlasAllocator m_AtlasAllocator = null;
142142
private Dictionary<int, Vector4> m_AllocationCache = new Dictionary<int, Vector4>();
143143
private Dictionary<int, uint> m_IsGPUTextureUpToDate = new Dictionary<int, uint>();
144+
private Dictionary<int, int> m_TextureHashes = new Dictionary<int, int>();
144145

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

@@ -278,6 +279,7 @@ public virtual bool AllocateTextureWithoutBlit(int instanceId, int width, int he
278279
scaleOffset.Scale(new Vector4(1.0f / m_Width, 1.0f / m_Height, 1.0f / m_Width, 1.0f / m_Height));
279280
m_AllocationCache.Add(instanceId, scaleOffset);
280281
MarkGPUTextureInvalid(instanceId); // the texture data haven't been uploaded
282+
m_TextureHashes[instanceId] = -1;
281283
return true;
282284
}
283285
else
@@ -289,10 +291,29 @@ public virtual bool AllocateTextureWithoutBlit(int instanceId, int width, int he
289291
public bool IsCached(out Vector4 scaleOffset, Texture texture)
290292
=> m_AllocationCache.TryGetValue(texture.GetInstanceID(), out scaleOffset);
291293

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

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

0 commit comments

Comments
 (0)