From f569169662160fad5029a81854463c8cc395d372 Mon Sep 17 00:00:00 2001
From: samcake <samuel.gateau@gmail.com>
Date: Fri, 13 May 2016 11:01:15 -0700
Subject: [PATCH 1/7] Trying to support ambient occlusion map from blender

---
 libraries/fbx/src/FBXReader.cpp          |  7 ++++++-
 libraries/fbx/src/FBXReader.h            |  2 ++
 libraries/fbx/src/FBXReader_Material.cpp | 16 ++++++++++++++++
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp
index 2df388e1d4..5a57a3c6d8 100644
--- a/libraries/fbx/src/FBXReader.cpp
+++ b/libraries/fbx/src/FBXReader.cpp
@@ -924,6 +924,9 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
                                         //  material.emissiveColor = getVec3(property.properties, index);
                                         //  material.emissiveFactor = 1.0;
 
+                                    } else if (property.properties.at(0) == "AmbientFactor") {
+                                        material.ambientFactor = property.properties.at(index).value<double>();
+                                        // Detected just for BLender AO vs lightmap
                                     } else if (property.properties.at(0) == "Shininess") {
                                         material.shininess = property.properties.at(index).value<double>();
 
@@ -1126,8 +1129,10 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
                             emissiveTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
                         } else if (type.contains("tex_emissive_map")) {
                             emissiveTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
-                        } else if (type.contains("ambient")) {
+                        } else if (type.contains("ambientcolor")) {
                             ambientTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
+                        } else if (type.contains("ambientfactor")) {
+                            ambientFactorTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
                         } else if (type.contains("tex_ao_map")) {
                             occlusionTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
 
diff --git a/libraries/fbx/src/FBXReader.h b/libraries/fbx/src/FBXReader.h
index c1952fc550..9e960126b5 100644
--- a/libraries/fbx/src/FBXReader.h
+++ b/libraries/fbx/src/FBXReader.h
@@ -151,6 +151,7 @@ public:
     float metallic{ 0.0f };
     float roughness{ 1.0f };
     float emissiveIntensity{ 1.0f };
+    float ambientFactor{ 1.0f };
 
     QString materialID;
     QString name;
@@ -436,6 +437,7 @@ public:
     QHash<QString, QString> shininessTextures;
     QHash<QString, QString> emissiveTextures;
     QHash<QString, QString> ambientTextures;
+    QHash<QString, QString> ambientFactorTextures;
     QHash<QString, QString> occlusionTextures;
 
     QHash<QString, FBXMaterial> _fbxMaterials;
diff --git a/libraries/fbx/src/FBXReader_Material.cpp b/libraries/fbx/src/FBXReader_Material.cpp
index 11c6dad2f2..3503fe1054 100644
--- a/libraries/fbx/src/FBXReader_Material.cpp
+++ b/libraries/fbx/src/FBXReader_Material.cpp
@@ -175,6 +175,14 @@ void FBXReader::consolidateFBXMaterials() {
 
         FBXTexture occlusionTexture;
         QString occlusionTextureID = occlusionTextures.value(material.materialID);
+        if (occlusionTextureID.isNull()) {
+            // 2nd chance
+            // For blender we use the ambient factor texture ONLY if the ambientFactor value is set to 0
+            if (material.ambientFactor == 0.0) {
+                occlusionTextureID = ambientFactorTextures.value(material.materialID);
+            }
+        }
+
         if (!occlusionTextureID.isNull()) {
             occlusionTexture = getTexture(occlusionTextureID);
             detectDifferentUVs |= (occlusionTexture.texcoordSet != 0) || (!emissiveTexture.transform.isIdentity());
@@ -187,6 +195,14 @@ void FBXReader::consolidateFBXMaterials() {
 
         FBXTexture ambientTexture;
         QString ambientTextureID = ambientTextures.value(material.materialID);
+        if (ambientTextureID.isNull()) {
+            // 2nd chance
+            // For blender we use the ambient factor texture ONLY if the ambientFactor value is set to 1
+            if (material.ambientFactor == 1.0) {
+                ambientTextureID = ambientFactorTextures.value(material.materialID);
+            }
+        }
+        
         if (_loadLightmaps && !ambientTextureID.isNull()) {
             ambientTexture = getTexture(ambientTextureID);
             detectDifferentUVs |= (ambientTexture.texcoordSet != 0) || (!ambientTexture.transform.isIdentity());

From 1c06c1a6ab9915b255812d994c1c88886d454a4f Mon Sep 17 00:00:00 2001
From: samcake <samuel.gateau@gmail.com>
Date: Fri, 13 May 2016 11:09:53 -0700
Subject: [PATCH 2/7] Cleaning up the pr from tthe transform.h file

---
 libraries/gpu/src/gpu/Transform.h | 36 -------------------------------
 1 file changed, 36 deletions(-)
 delete mode 100644 libraries/gpu/src/gpu/Transform.h

diff --git a/libraries/gpu/src/gpu/Transform.h b/libraries/gpu/src/gpu/Transform.h
deleted file mode 100644
index 82974964a8..0000000000
--- a/libraries/gpu/src/gpu/Transform.h
+++ /dev/null
@@ -1,36 +0,0 @@
-//
-//  Transform.h
-//  libraries/gpu/src/gpu
-//
-//  Created by Sam Gateau on 06/12/2016.
-//  Copyright 2014 High Fidelity, Inc.
-//
-//  Distributed under the Apache License, Version 2.0.
-//  See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
-//
-#ifndef hifi_gpu_Transform_h
-#define hifi_gpu_Transform_h
-
-#include <vector>
-
-#include <assert.h>
-
-#include "Resource.h"
-
-namespace gpu {
-
-class TransformBuffer {
-public:
-
-    TransformBuffer() {}
-    ~TransformBuffer() {}
-
-protected:
-    BufferPointer _buffer;
-};
-typedef std::shared_ptr<TransformBuffer> TransformBufferPointer;
-
-};
-
-
-#endif

From c1fa096e78847f9aef8ef95bd730105f5188bb66 Mon Sep 17 00:00:00 2001
From: samcake <samuel.gateau@gmail.com>
Date: Mon, 16 May 2016 15:42:48 -0700
Subject: [PATCH 3/7] adding texcoord 1 on all the material/model and go fetch
 occlusion map with this uv instead of texcoor0. this allow for separate
 transforms just for occlusoin map

---
 libraries/fbx/src/FBXReader_Material.cpp         |  8 ++++----
 .../src/model-networking/ModelCache.cpp          |  4 ++++
 libraries/model/src/model/Material.cpp           |  4 ++++
 libraries/render-utils/src/MaterialTextures.slh  | 16 +++++++++-------
 libraries/render-utils/src/model.slf             |  4 +++-
 libraries/render-utils/src/model.slv             |  2 ++
 libraries/render-utils/src/model_lightmap.slf    |  4 ++--
 .../src/model_lightmap_normal_map.slf            |  4 ++--
 .../src/model_lightmap_normal_specular_map.slf   |  4 ++--
 .../src/model_lightmap_specular_map.slf          |  4 ++--
 libraries/render-utils/src/model_normal_map.slf  |  4 +++-
 .../src/model_normal_specular_map.slf            |  4 +++-
 .../render-utils/src/model_specular_map.slf      |  4 +++-
 libraries/render-utils/src/model_translucent.slf |  6 ++++--
 .../render-utils/src/model_translucent_unlit.slf |  2 +-
 libraries/render-utils/src/model_unlit.slf       |  4 ++--
 libraries/render-utils/src/skin_model.slv        |  2 ++
 .../render-utils/src/skin_model_normal_map.slv   |  2 ++
 18 files changed, 54 insertions(+), 28 deletions(-)

diff --git a/libraries/fbx/src/FBXReader_Material.cpp b/libraries/fbx/src/FBXReader_Material.cpp
index e539f849c7..01878d6ccf 100644
--- a/libraries/fbx/src/FBXReader_Material.cpp
+++ b/libraries/fbx/src/FBXReader_Material.cpp
@@ -188,8 +188,8 @@ void FBXReader::consolidateFBXMaterials() {
         QString occlusionTextureID = occlusionTextures.value(material.materialID);
         if (occlusionTextureID.isNull()) {
             // 2nd chance
-            // For blender we use the ambient factor texture ONLY if the ambientFactor value is set to 0
-            if (material.ambientFactor == 0.0) {
+            // For blender we use the ambient factor texture as AOMap ONLY if the ambientFactor value is > 0.0
+            if (material.ambientFactor > 0.0f) {
                 occlusionTextureID = ambientFactorTextures.value(material.materialID);
             }
         }
@@ -208,8 +208,8 @@ void FBXReader::consolidateFBXMaterials() {
         QString ambientTextureID = ambientTextures.value(material.materialID);
         if (ambientTextureID.isNull()) {
             // 2nd chance
-            // For blender we use the ambient factor texture ONLY if the ambientFactor value is set to 1
-            if (material.ambientFactor == 1.0) {
+            // For blender we use the ambient factor texture as Lightmap ONLY if the ambientFactor value is set to 0
+            if (material.ambientFactor == 0.0f) {
                 ambientTextureID = ambientFactorTextures.value(material.materialID);
             }
         }
diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp
index 8cd6d9b65e..40388e6123 100644
--- a/libraries/model-networking/src/model-networking/ModelCache.cpp
+++ b/libraries/model-networking/src/model-networking/ModelCache.cpp
@@ -418,6 +418,8 @@ model::TextureMapPointer NetworkMaterial::fetchTextureMap(const QUrl& baseUrl, c
 
     auto map = std::make_shared<model::TextureMap>();
     map->setTextureSource(texture->_textureSource);
+    map->setTextureTransform(fbxTexture.transform);
+
     return map;
 }
 
@@ -427,6 +429,7 @@ model::TextureMapPointer NetworkMaterial::fetchTextureMap(const QUrl& url, Textu
 
     auto map = std::make_shared<model::TextureMap>();
     map->setTextureSource(texture->_textureSource);
+
     return map;
 }
 
@@ -475,6 +478,7 @@ NetworkMaterial::NetworkMaterial(const FBXMaterial& material, const QUrl& textur
 
     if (!material.occlusionTexture.filename.isEmpty()) {
         auto map = fetchTextureMap(textureBaseUrl, material.occlusionTexture, NetworkTexture::OCCLUSION_TEXTURE, MapChannel::OCCLUSION_MAP);
+        map->setTextureTransform(material.occlusionTexture.transform);
         setTextureMap(MapChannel::OCCLUSION_MAP, map);
     }
 
diff --git a/libraries/model/src/model/Material.cpp b/libraries/model/src/model/Material.cpp
index 53478be536..dbe3cabdeb 100755
--- a/libraries/model/src/model/Material.cpp
+++ b/libraries/model/src/model/Material.cpp
@@ -122,6 +122,10 @@ void Material::setTextureMap(MapChannel channel, const TextureMapPointer& textur
         _texMapArrayBuffer.edit<TexMapArraySchema>()._texcoordTransforms[0] = (textureMap ? textureMap->getTextureTransform().getMatrix() : glm::mat4());
     }
 
+    if (channel == MaterialKey::OCCLUSION_MAP) {
+        _texMapArrayBuffer.edit<TexMapArraySchema>()._texcoordTransforms[1] = (textureMap ? textureMap->getTextureTransform().getMatrix() : glm::mat4());
+    }
+
     if (channel == MaterialKey::LIGHTMAP_MAP) {
         // update the texcoord1 with lightmap
         _texMapArrayBuffer.edit<TexMapArraySchema>()._texcoordTransforms[1] = (textureMap ? textureMap->getTextureTransform().getMatrix() : glm::mat4());
diff --git a/libraries/render-utils/src/MaterialTextures.slh b/libraries/render-utils/src/MaterialTextures.slh
index f9b1c76104..5cede16e13 100644
--- a/libraries/render-utils/src/MaterialTextures.slh
+++ b/libraries/render-utils/src/MaterialTextures.slh
@@ -90,7 +90,7 @@ float fetchOcclusionMap(vec2 uv) {
 <@endfunc@>
 
 
-<@func fetchMaterialTextures(matKey, texcoord0, albedo, roughness, normal, metallic, emissive, occlusion)@>
+<@func fetchMaterialTexturesCoord0(matKey, texcoord0, albedo, roughness, normal, metallic, emissive)@>
 <@if albedo@>
     vec4 <$albedo$> = (((<$matKey$> & (ALBEDO_MAP_BIT | OPACITY_MASK_MAP_BIT | OPACITY_TRANSLUCENT_MAP_BIT)) != 0) ? fetchAlbedoMap(<$texcoord0$>) : vec4(1.0));
 <@endif@>
@@ -106,12 +106,19 @@ float fetchOcclusionMap(vec2 uv) {
 <@if emissive@>
     vec3 <$emissive$> = (((<$matKey$> & EMISSIVE_MAP_BIT) != 0) ? fetchEmissiveMap(<$texcoord0$>) : vec3(0.0));
 <@endif@>
+<@endfunc@>
+
+<@func fetchMaterialTexturesCoord1(matKey, texcoord1, occlusion, lightmapVal)@>
 <@if occlusion@>
-    float <$occlusion$> = (((<$matKey$> & OCCLUSION_MAP_BIT) != 0) ? fetchOcclusionMap(<$texcoord0$>) : 1.0);
+    float <$occlusion$> = (((<$matKey$> & OCCLUSION_MAP_BIT) != 0) ? fetchOcclusionMap(<$texcoord1$>) : 1.0);
+<@endif@>
+<@if lightmapVal@>
+    vec3 <$lightmapVal$> = fetchLightmapMap(<$texcoord1$>);
 <@endif@>
 <@endfunc@>
 
 
+
 <@func declareMaterialLightmap()@>
 
 <$declareMaterialTexMapArrayBuffer()$>
@@ -123,11 +130,6 @@ vec3 fetchLightmapMap(vec2 uv) {
 }
 <@endfunc@>
 
-<@func fetchMaterialLightmap(texcoord1, lightmapVal)@>
-    vec3 <$lightmapVal$> = fetchLightmapMap(<$texcoord1$>);
-<@endfunc@>
-
-
 <@func tangentToViewSpace(fetchedNormal, interpolatedNormal, interpolatedTangent, normal)@>
 {
     vec3 normalizedNormal = normalize(<$interpolatedNormal$>.xyz);
diff --git a/libraries/render-utils/src/model.slf b/libraries/render-utils/src/model.slf
index f1dcc942c9..c1f5cb1f88 100755
--- a/libraries/render-utils/src/model.slf
+++ b/libraries/render-utils/src/model.slf
@@ -22,12 +22,14 @@ in vec4 _position;
 in vec3 _normal;
 in vec3 _color;
 in vec2 _texCoord0;
+in vec2 _texCoord1;
 
 
 void main(void) {
     Material mat = getMaterial();
     int matKey = getMaterialKey(mat);
-    <$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, _SCRIBE_NULL, emissiveTex, occlusionTex)$>
+    <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, _SCRIBE_NULL, emissiveTex)$>
+    <$fetchMaterialTexturesCoord1(matKey, _texCoord1, occlusionTex)$>
 
     float opacity = 1.0;
     <$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>;
diff --git a/libraries/render-utils/src/model.slv b/libraries/render-utils/src/model.slv
index f1989dcf76..4d36673123 100755
--- a/libraries/render-utils/src/model.slv
+++ b/libraries/render-utils/src/model.slv
@@ -22,6 +22,7 @@
 out vec3 _color;
 out float _alpha;
 out vec2 _texCoord0;
+out vec2 _texCoord1;
 out vec4 _position;
 out vec3 _normal;
 
@@ -31,6 +32,7 @@ void main(void) {
 
     TexMapArray texMapArray = getTexMapArray();
     <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord0)$>
+    <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord0, _texCoord1)$>
 
     // standard transform
     TransformCamera cam = getTransformCamera();
diff --git a/libraries/render-utils/src/model_lightmap.slf b/libraries/render-utils/src/model_lightmap.slf
index 3afbbfd405..3a8cfde290 100755
--- a/libraries/render-utils/src/model_lightmap.slf
+++ b/libraries/render-utils/src/model_lightmap.slf
@@ -29,8 +29,8 @@ in vec3 _color;
 void main(void) {
     Material mat = getMaterial();
     int matKey = getMaterialKey(mat);
-    <$fetchMaterialTextures(matKey, _texCoord0, albedo, roughness)$>
-    <$fetchMaterialLightmap(_texCoord1, lightmapVal)$>
+    <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedo, roughness)$>
+    <$fetchMaterialTexturesCoord1(matKey, _texCoord1, _SCRIBE_NULL, lightmapVal)$>
 
 
     packDeferredFragmentLightmap(
diff --git a/libraries/render-utils/src/model_lightmap_normal_map.slf b/libraries/render-utils/src/model_lightmap_normal_map.slf
index 9ccc6e5352..64c61e255d 100755
--- a/libraries/render-utils/src/model_lightmap_normal_map.slf
+++ b/libraries/render-utils/src/model_lightmap_normal_map.slf
@@ -30,8 +30,8 @@ in vec3 _color;
 void main(void) {
     Material mat = getMaterial();
     int matKey = getMaterialKey(mat);
-    <$fetchMaterialTextures(matKey, _texCoord0, albedo, roughness, normalTexel)$>
-    <$fetchMaterialLightmap(_texCoord1, lightmapVal)$>
+    <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedo, roughness, normalTexel)$>
+    <$fetchMaterialTexturesCoord1(matKey, _texCoord1, _SCRIBE_NULL, lightmapVal)$>
 
     vec3 viewNormal;
     <$tangentToViewSpace(normalTexel, _normal, _tangent, viewNormal)$>
diff --git a/libraries/render-utils/src/model_lightmap_normal_specular_map.slf b/libraries/render-utils/src/model_lightmap_normal_specular_map.slf
index 71909a789f..34a116eac1 100755
--- a/libraries/render-utils/src/model_lightmap_normal_specular_map.slf
+++ b/libraries/render-utils/src/model_lightmap_normal_specular_map.slf
@@ -30,8 +30,8 @@ in vec3 _color;
 void main(void) {
     Material mat = getMaterial();
     int matKey = getMaterialKey(mat);
-    <$fetchMaterialTextures(matKey, _texCoord0, albedo, roughness, normalTexel, metallicTex)$>
-    <$fetchMaterialLightmap(_texCoord1, lightmapVal)$>
+    <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedo, roughness, normalTexel, metallicTex)$>
+    <$fetchMaterialTexturesCoord1(matKey, _texCoord1, _SCRIBE_NULL, lightmapVal)$>
     
     vec3 viewNormal;
     <$tangentToViewSpace(normalTexel, _normal, _tangent, viewNormal)$>
diff --git a/libraries/render-utils/src/model_lightmap_specular_map.slf b/libraries/render-utils/src/model_lightmap_specular_map.slf
index 5eefefdc29..4dbc10a834 100755
--- a/libraries/render-utils/src/model_lightmap_specular_map.slf
+++ b/libraries/render-utils/src/model_lightmap_specular_map.slf
@@ -29,8 +29,8 @@ in vec3 _color;
 void main(void) {
     Material mat = getMaterial();
     int matKey = getMaterialKey(mat);
-    <$fetchMaterialTextures(matKey, _texCoord0, albedo, roughness, _SCRIBE_NULL, metallicTex)$>
-    <$fetchMaterialLightmap(_texCoord1, lightmapVal)$>
+    <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedo, roughness, _SCRIBE_NULL, metallicTex)$>
+    <$fetchMaterialTexturesCoord1(matKey, _texCoord1, _SCRIBE_NULL, lightmapVal)$>
 
     packDeferredFragmentLightmap(
         normalize(_normal), 
diff --git a/libraries/render-utils/src/model_normal_map.slf b/libraries/render-utils/src/model_normal_map.slf
index 519b41e17f..daaa1ed977 100755
--- a/libraries/render-utils/src/model_normal_map.slf
+++ b/libraries/render-utils/src/model_normal_map.slf
@@ -21,6 +21,7 @@
 
 in vec4 _position;
 in vec2 _texCoord0;
+in vec2 _texCoord1;
 in vec3 _normal;
 in vec3 _tangent;
 in vec3 _color;
@@ -28,7 +29,8 @@ in vec3 _color;
 void main(void) {
     Material mat = getMaterial();
     int matKey = getMaterialKey(mat);
-    <$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, normalTex, _SCRIBE_NULL, emissiveTex, occlusionTex)$>
+    <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, normalTex, _SCRIBE_NULL, emissiveTex)$>
+    <$fetchMaterialTexturesCoord1(matKey, _texCoord1, occlusionTex)$>
 
     float opacity = 1.0;
     <$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>;
diff --git a/libraries/render-utils/src/model_normal_specular_map.slf b/libraries/render-utils/src/model_normal_specular_map.slf
index 2529596818..dd2d3cc951 100755
--- a/libraries/render-utils/src/model_normal_specular_map.slf
+++ b/libraries/render-utils/src/model_normal_specular_map.slf
@@ -21,6 +21,7 @@
 
 in vec4 _position;
 in vec2 _texCoord0;
+in vec2 _texCoord1;
 in vec3 _normal;
 in vec3 _tangent;
 in vec3 _color;
@@ -28,7 +29,8 @@ in vec3 _color;
 void main(void) {
     Material mat = getMaterial();
     int matKey = getMaterialKey(mat);
-    <$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, normalTex, metallicTex, emissiveTex, occlusionTex)$>
+    <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, normalTex, metallicTex, emissiveTex)$>
+    <$fetchMaterialTexturesCoord1(matKey, _texCoord1, occlusionTex)$>
 
     float opacity = 1.0;
     <$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)&>;
diff --git a/libraries/render-utils/src/model_specular_map.slf b/libraries/render-utils/src/model_specular_map.slf
index 3cbb060ab5..f0fe20293c 100755
--- a/libraries/render-utils/src/model_specular_map.slf
+++ b/libraries/render-utils/src/model_specular_map.slf
@@ -21,6 +21,7 @@
 
 in vec4 _position;
 in vec2 _texCoord0;
+in vec2 _texCoord1;
 in vec3 _normal;
 in vec3 _color;
 
@@ -28,7 +29,8 @@ in vec3 _color;
 void main(void) {
     Material mat = getMaterial();
     int matKey = getMaterialKey(mat);
-    <$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, metallicTex, emissiveTex, occlusionTex)$>
+    <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, metallicTex, emissiveTex)$>
+    <$fetchMaterialTexturesCoord1(matKey, _texCoord1, occlusionTex)$>
 
     float opacity = 1.0;
     <$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>;
diff --git a/libraries/render-utils/src/model_translucent.slf b/libraries/render-utils/src/model_translucent.slf
index 27a22a9763..8f62a3a3e0 100755
--- a/libraries/render-utils/src/model_translucent.slf
+++ b/libraries/render-utils/src/model_translucent.slf
@@ -25,6 +25,7 @@
 <$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, _SCRIBE_NULL, EMISSIVE, OCCLUSION)$>
 
 in vec2 _texCoord0;
+in vec2 _texCoord1;
 in vec4 _position;
 in vec3 _normal;
 in vec3 _color;
@@ -35,7 +36,8 @@ out vec4 _fragColor;
 void main(void) {
     Material mat = getMaterial();
     int matKey = getMaterialKey(mat);
-    <$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, _SCRIBE_NULL, emissiveTex, occlusionTex)$>
+    <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, _SCRIBE_NULL, emissiveTex)$>
+    <$fetchMaterialTexturesCoord1(matKey, _texCoord1, occlusionTex)$>
 
     float opacity = getMaterialOpacity(mat) * _alpha;
     <$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>;
@@ -61,7 +63,7 @@ void main(void) {
     _fragColor =  vec4(evalGlobalLightingAlphaBlended(
         cam._viewInverse,
         1.0,
-        1.0,
+        occlusionTex,
         fragPosition,
         fragNormal,
         albedo,
diff --git a/libraries/render-utils/src/model_translucent_unlit.slf b/libraries/render-utils/src/model_translucent_unlit.slf
index b9d6c64d6f..e2676636bf 100644
--- a/libraries/render-utils/src/model_translucent_unlit.slf
+++ b/libraries/render-utils/src/model_translucent_unlit.slf
@@ -26,7 +26,7 @@ out vec4 _fragColor;
 void main(void) {
     Material mat = getMaterial();
     int matKey = getMaterialKey(mat);
-    <$fetchMaterialTextures(matKey, _texCoord0, albedoTex, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL)$>
+    <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex)$>
 
     float opacity = getMaterialOpacity(mat) * _alpha;
     <$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>;
diff --git a/libraries/render-utils/src/model_unlit.slf b/libraries/render-utils/src/model_unlit.slf
index 50778153fb..3c2e4ae2e0 100644
--- a/libraries/render-utils/src/model_unlit.slf
+++ b/libraries/render-utils/src/model_unlit.slf
@@ -16,7 +16,7 @@
 <@include model/Material.slh@>
 
 <@include MaterialTextures.slh@>
-<$declareMaterialTextures(ALBEDO, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL)$>
+<$declareMaterialTextures(ALBEDO)$>
 
 in vec2 _texCoord0;
 in vec3 _normal;
@@ -27,7 +27,7 @@ void main(void) {
 
     Material mat = getMaterial();
     int matKey = getMaterialKey(mat);
-    <$fetchMaterialTextures(matKey, _texCoord0, albedoTex, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL)$>
+    <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex)$>
 
     float opacity = 1.0;
     <$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>;
diff --git a/libraries/render-utils/src/skin_model.slv b/libraries/render-utils/src/skin_model.slv
index c8501b8ddf..268b203e35 100755
--- a/libraries/render-utils/src/skin_model.slv
+++ b/libraries/render-utils/src/skin_model.slv
@@ -24,6 +24,7 @@
 
 out vec4 _position;
 out vec2 _texCoord0;
+out vec2 _texCoord1;
 out vec3 _normal;
 out vec3 _color;
 out float _alpha;
@@ -40,6 +41,7 @@ void main(void) {
 
     TexMapArray texMapArray = getTexMapArray();
     <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord0)$>
+    <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord0, _texCoord1)$>
 
     // standard transform
     TransformCamera cam = getTransformCamera();
diff --git a/libraries/render-utils/src/skin_model_normal_map.slv b/libraries/render-utils/src/skin_model_normal_map.slv
index db4b206405..05524385ef 100755
--- a/libraries/render-utils/src/skin_model_normal_map.slv
+++ b/libraries/render-utils/src/skin_model_normal_map.slv
@@ -24,6 +24,7 @@
 
 out vec4 _position;
 out vec2 _texCoord0;
+out vec2 _texCoord1;
 out vec3 _normal;
 out vec3 _tangent;
 out vec3 _color;
@@ -42,6 +43,7 @@ void main(void) {
 
     TexMapArray texMapArray = getTexMapArray();
     <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord0)$>
+    <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord0, _texCoord1)$>
 
     interpolatedNormal = vec4(normalize(interpolatedNormal.xyz), 0.0);
     interpolatedTangent = vec4(normalize(interpolatedTangent.xyz), 0.0);

From a12e56f8802b0e52d9683a683499aaefb6be2b43 Mon Sep 17 00:00:00 2001
From: samcake <samuel.gateau@gmail.com>
Date: Mon, 16 May 2016 17:43:54 -0700
Subject: [PATCH 4/7] Fix forgotten vertex shader case

---
 libraries/render-utils/src/model_normal_map.slv | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libraries/render-utils/src/model_normal_map.slv b/libraries/render-utils/src/model_normal_map.slv
index ded37923c2..e70d93f909 100755
--- a/libraries/render-utils/src/model_normal_map.slv
+++ b/libraries/render-utils/src/model_normal_map.slv
@@ -34,6 +34,7 @@ void main(void) {
 
     TexMapArray texMapArray = getTexMapArray();
     <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord0)$>
+    <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord0, _texCoord1)$>
 
     // standard transform
     TransformCamera cam = getTransformCamera();

From d06c6e2a5967ef72a8333749623457d6820377f6 Mon Sep 17 00:00:00 2001
From: samcake <samuel.gateau@gmail.com>
Date: Mon, 16 May 2016 17:54:42 -0700
Subject: [PATCH 5/7] Fix forgotten vertex shader case

---
 libraries/render-utils/src/model_normal_map.slv | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libraries/render-utils/src/model_normal_map.slv b/libraries/render-utils/src/model_normal_map.slv
index e70d93f909..494e40ccff 100755
--- a/libraries/render-utils/src/model_normal_map.slv
+++ b/libraries/render-utils/src/model_normal_map.slv
@@ -22,6 +22,7 @@
 
 out vec4 _position;
 out vec2 _texCoord0;
+out vec2 _texCoord1;
 out vec3 _normal;
 out vec3 _tangent;
 out vec3 _color;

From 079f6af2cc3c07d881c23d01c2da32f2eb6866b0 Mon Sep 17 00:00:00 2001
From: samcake <samuel.gateau@gmail.com>
Date: Thu, 2 Jun 2016 16:14:46 -0700
Subject: [PATCH 6/7] Fixing the gamma correction for the debug view of
 occlusion

---
 libraries/render-utils/src/DebugDeferredBuffer.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp
index 6dfec30b16..dc46b5d897 100644
--- a/libraries/render-utils/src/DebugDeferredBuffer.cpp
+++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp
@@ -83,7 +83,7 @@ static const std::string DEFAULT_NORMAL_SHADER {
 static const std::string DEFAULT_OCCLUSION_SHADER{
     "vec4 getFragmentColor() {"
     "    DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
-    "    return vec4(vec3(frag.obscurance), 1.0);"
+    "    return vec4(vec3(pow(frag.obscurance, 1.0 / 2.2)), 1.0);"
     " }"
 };
 

From 681da201fc7dfcec6f9649be1b11972ccab97657 Mon Sep 17 00:00:00 2001
From: samcake <samuel.gateau@gmail.com>
Date: Thu, 2 Jun 2016 16:25:14 -0700
Subject: [PATCH 7/7] COrrect the name of the Unlit dbug view

---
 scripts/developer/utilities/render/framebuffer.qml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/developer/utilities/render/framebuffer.qml b/scripts/developer/utilities/render/framebuffer.qml
index 0d8d85cc32..1612f59276 100644
--- a/scripts/developer/utilities/render/framebuffer.qml
+++ b/scripts/developer/utilities/render/framebuffer.qml
@@ -33,7 +33,7 @@ Column {
                 "Roughness",
                 "Metallic",     
                 "Emissive",
-                "Shaded/Lightmapped/Unlit",
+                "Unlit",
                 "Occlusion",
                 "Lightmap",
                 "Lighting",