From 50fecf5e0139bd7b93dc2d20c827800d15d7ef4b Mon Sep 17 00:00:00 2001
From: Olivier Prat <olivier@zvork.fr>
Date: Wed, 3 Apr 2019 11:29:59 +0200
Subject: [PATCH] Ambient map has different hash than sky map to prevent using
 one instead of the other, even if they are using the same source texture.

---
 libraries/baking/src/TextureBaker.cpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/libraries/baking/src/TextureBaker.cpp b/libraries/baking/src/TextureBaker.cpp
index 60cca77bda..bed0e9a40b 100644
--- a/libraries/baking/src/TextureBaker.cpp
+++ b/libraries/baking/src/TextureBaker.cpp
@@ -131,7 +131,14 @@ void TextureBaker::handleTextureNetworkReply() {
 void TextureBaker::processTexture() {
     // the baked textures need to have the source hash added for cache checks in Interface
     // so we add that to the processed texture before handling it off to be serialized
-    auto hashData = QCryptographicHash::hash(_originalTexture, QCryptographicHash::Md5);
+    QCryptographicHash hasher(QCryptographicHash::Md5);
+    hasher.addData(_originalTexture);
+    // An ambient texture is built with the same pixel data as sky texture but its Mip Maps are different
+    // so we mustn't use one instead of the other.
+    if (_textureType == image::TextureUsage::AMBIENT_TEXTURE) {
+        hasher.addData((const char*)&_textureType, sizeof(_textureType));
+    }
+    auto hashData = hasher.result();
     std::string hash = hashData.toHex().toStdString();
 
     TextureMeta meta;