David Catuhe 6 anni fa
parent
commit
a8db5e20a9

+ 25 - 0
src/Materials/Node/Blocks/Vertex/morphTargetsBlock.ts

@@ -27,9 +27,11 @@ export class MorphTargetsBlock extends NodeMaterialBlock {
         this.registerInput("position", NodeMaterialBlockConnectionPointTypes.Vector3);
         this.registerInput("normal", NodeMaterialBlockConnectionPointTypes.Vector3);
         this.registerInput("tangent", NodeMaterialBlockConnectionPointTypes.Vector3);
+        this.registerInput("uv", NodeMaterialBlockConnectionPointTypes.Vector2);
         this.registerOutput("positionOutput", NodeMaterialBlockConnectionPointTypes.Vector3);
         this.registerOutput("normalOutput", NodeMaterialBlockConnectionPointTypes.Vector3);
         this.registerOutput("tangentOutput", NodeMaterialBlockConnectionPointTypes.Vector3);
+        this.registerOutput("uvOutput", NodeMaterialBlockConnectionPointTypes.Vector2);
     }
 
     /**
@@ -62,6 +64,13 @@ export class MorphTargetsBlock extends NodeMaterialBlock {
     }
 
     /**
+     * Gets the tangent input component
+     */
+    public get uv(): NodeMaterialConnectionPoint {
+        return this._inputs[3];
+    }
+
+    /**
      * Gets the position output component
      */
     public get positionOutput(): NodeMaterialConnectionPoint {
@@ -82,6 +91,13 @@ export class MorphTargetsBlock extends NodeMaterialBlock {
         return this._outputs[2];
     }
 
+    /**
+     * Gets the tangent output component
+     */
+    public get uvOutput(): NodeMaterialConnectionPoint {
+        return this._outputs[3];
+    }
+
     public initialize(state: NodeMaterialBuildState) {
         state._excludeVariableName("morphTargetInfluences");
     }
@@ -117,9 +133,11 @@ export class MorphTargetsBlock extends NodeMaterialBlock {
         let position = this.position;
         let normal = this.normal;
         let tangent = this.tangent;
+        let uv = this.uv;
         let positionOutput = this.positionOutput;
         let normalOutput = this.normalOutput;
         let tangentOutput = this.tangentOutput;
+        let uvOutput = this.uvOutput;
         let state = vertexShaderState;
         let repeatCount = defines.NUM_MORPH_INFLUENCERS as number;
         this._repeatebleContentGenerated = repeatCount;
@@ -127,6 +145,7 @@ export class MorphTargetsBlock extends NodeMaterialBlock {
         var manager = (<Mesh>mesh).morphTargetManager;
         var hasNormals = manager && manager.supportsNormals && defines["NORMAL"];
         var hasTangents = manager && manager.supportsTangents && defines["TANGENT"];
+        var hasUVs = manager && manager.supportsUVs && defines["UV1"];
 
         let injectionCode = "";
 
@@ -146,6 +165,12 @@ export class MorphTargetsBlock extends NodeMaterialBlock {
                 injectionCode += `#endif\r\n`;
             }
 
+            if (hasUVs) {
+                injectionCode += `#ifdef MORPHTARGETS_UV\r\n`;
+                injectionCode += `${uvOutput.associatedVariableName}.xyz += (uv_${index} - ${uv.associatedVariableName}.xyz) * morphTargetInfluences[${index}];\r\n`;
+                injectionCode += `#endif\r\n`;
+            }
+
             injectionCode += `#endif\r\n`;
         }
 

+ 1 - 0
src/Materials/Node/nodeMaterial.ts

@@ -47,6 +47,7 @@ export class NodeMaterialDefines extends MaterialDefines implements IImageProces
     public MORPHTARGETS = false;
     public MORPHTARGETS_NORMAL = false;
     public MORPHTARGETS_TANGENT = false;
+    public MORPHTARGETS_UV = false;
     public NUM_MORPH_INFLUENCERS = 0;
 
     /** IMAGE PROCESSING */

+ 1 - 0
src/Materials/PBR/pbrBaseMaterial.ts

@@ -151,6 +151,7 @@ export class PBRMaterialDefines extends MaterialDefines
     public MORPHTARGETS = false;
     public MORPHTARGETS_NORMAL = false;
     public MORPHTARGETS_TANGENT = false;
+    public MORPHTARGETS_UV = false;
     public NUM_MORPH_INFLUENCERS = 0;
 
     public IMAGEPROCESSING = false;

+ 7 - 0
src/Materials/materialHelper.ts

@@ -196,11 +196,13 @@ export class MaterialHelper {
     public static PrepareDefinesForMorphTargets(mesh: AbstractMesh, defines: any) {
         var manager = (<Mesh>mesh).morphTargetManager;
         if (manager) {
+            defines["MORPHTARGETS_UV"] = manager.supportsUVs && defines["UV1"];
             defines["MORPHTARGETS_TANGENT"] = manager.supportsTangents && defines["TANGENT"];
             defines["MORPHTARGETS_NORMAL"] = manager.supportsNormals && defines["NORMAL"];
             defines["MORPHTARGETS"] = (manager.numInfluencers > 0);
             defines["NUM_MORPH_INFLUENCERS"] = manager.numInfluencers;
         } else {
+            defines["MORPHTARGETS_UV"] = false;
             defines["MORPHTARGETS_TANGENT"] = false;
             defines["MORPHTARGETS_NORMAL"] = false;
             defines["MORPHTARGETS"] = false;
@@ -566,6 +568,7 @@ export class MaterialHelper {
             var manager = (<Mesh>mesh).morphTargetManager;
             var normal = manager && manager.supportsNormals && defines["NORMAL"];
             var tangent = manager && manager.supportsTangents && defines["TANGENT"];
+            var uv = manager && manager.supportsUVs && defines["UV1"];
             for (var index = 0; index < influencers; index++) {
                 attribs.push(VertexBuffer.PositionKind + index);
 
@@ -577,6 +580,10 @@ export class MaterialHelper {
                     attribs.push(VertexBuffer.TangentKind + index);
                 }
 
+                if (uv) {
+                    attribs.push(VertexBuffer.UVKind + index);
+                }
+
                 if (attribs.length > maxAttributesCount) {
                     Logger.Error("Cannot add more vertex attributes for mesh " + mesh.name);
                 }

+ 1 - 0
src/Materials/standardMaterial.ts

@@ -107,6 +107,7 @@ export class StandardMaterialDefines extends MaterialDefines implements IImagePr
     public MORPHTARGETS = false;
     public MORPHTARGETS_NORMAL = false;
     public MORPHTARGETS_TANGENT = false;
+    public MORPHTARGETS_UV = false;
     public NUM_MORPH_INFLUENCERS = 0;
     public NONUNIFORMSCALING = false; // https://playground.babylonjs.com#V6DWIH
     public PREMULTIPLYALPHA = false; // https://playground.babylonjs.com#LNVJJ7

+ 39 - 0
src/Morph/morphTarget.ts

@@ -25,6 +25,7 @@ export class MorphTarget implements IAnimatable {
     private _positions: Nullable<FloatArray> = null;
     private _normals: Nullable<FloatArray> = null;
     private _tangents: Nullable<FloatArray> = null;
+    private _uvs: Nullable<FloatArray> = null;
     private _influence: number;
 
     /**
@@ -112,6 +113,13 @@ export class MorphTarget implements IAnimatable {
     }
 
     /**
+     * Gets a boolean defining if the target contains texture coordinates data
+     */
+    public get hasUVs(): boolean {
+        return !!this._uvs;
+    }
+
+    /**
      * Affects position data to this target
      * @param data defines the position data to use
      */
@@ -178,6 +186,28 @@ export class MorphTarget implements IAnimatable {
     }
 
     /**
+     * Affects texture coordinates data to this target
+     * @param data defines the texture coordinates data to use
+     */
+    public setUVs(data: Nullable<FloatArray>) {
+        const hadUVs = this.hasUVs;
+
+        this._uvs = data;
+
+        if (hadUVs !== this.hasUVs) {
+            this._onDataLayoutChanged.notifyObservers(undefined);
+        }
+    }
+
+    /**
+     * Gets the texture coordinates data stored in this target
+     * @returns a FloatArray containing the texture coordinates data (or null if not present)
+     */
+    public getUVs(): Nullable<FloatArray> {
+        return this._uvs;
+    }
+
+    /**
      * Serializes the current target into a Serialization object
      * @returns the serialized object
      */
@@ -197,6 +227,9 @@ export class MorphTarget implements IAnimatable {
         if (this.hasTangents) {
             serializationObject.tangents = Array.prototype.slice.call(this.getTangents());
         }
+        if (this.hasUVs) {
+            serializationObject.uvs = Array.prototype.slice.call(this.getUVs());
+        }
 
         // Animations
         SerializationHelper.AppendSerializedAnimations(this, serializationObject);
@@ -233,6 +266,9 @@ export class MorphTarget implements IAnimatable {
         if (serializationObject.tangents) {
             result.setTangents(serializationObject.tangents);
         }
+        if (serializationObject.uvs) {
+            result.setUVs(serializationObject.uvs);
+        }
 
         // Animations
         if (serializationObject.animations) {
@@ -270,6 +306,9 @@ export class MorphTarget implements IAnimatable {
         if (mesh.isVerticesDataPresent(VertexBuffer.TangentKind)) {
             result.setTangents(<FloatArray>mesh.getVerticesData(VertexBuffer.TangentKind));
         }
+        if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
+            result.setUVs(<FloatArray>mesh.getVerticesData(VertexBuffer.UVKind));
+        }
 
         return result;
     }

+ 10 - 0
src/Morph/morphTargetManager.ts

@@ -19,6 +19,7 @@ export class MorphTargetManager {
     private _influences: Float32Array;
     private _supportsNormals = false;
     private _supportsTangents = false;
+    private _supportsUVs = false;
     private _vertexCount = 0;
     private _uniqueId = 0;
     private _tempInfluences = new Array<number>();
@@ -70,6 +71,13 @@ export class MorphTargetManager {
     }
 
     /**
+     * Gets a boolean indicating if this manager supports morphing of texture coordinates
+     */
+    public get supportsUVs(): boolean {
+        return this._supportsUVs;
+    }
+
+    /**
      * Gets the number of targets stored in this manager
      */
     public get numTargets(): number {
@@ -160,6 +168,7 @@ export class MorphTargetManager {
         this._activeTargets.reset();
         this._supportsNormals = true;
         this._supportsTangents = true;
+        this._supportsUVs = true;
         this._vertexCount = 0;
         for (var target of this._targets) {
             if (target.influence === 0) {
@@ -171,6 +180,7 @@ export class MorphTargetManager {
 
             this._supportsNormals = this._supportsNormals && target.hasNormals;
             this._supportsTangents = this._supportsTangents && target.hasTangents;
+            this._supportsUVs = this._supportsUVs && target.hasUVs;
 
             const positions = target.getPositions();
             if (positions) {

+ 4 - 0
src/Shaders/ShadersInclude/morphTargetsVertex.fx

@@ -8,4 +8,8 @@
 	#ifdef MORPHTARGETS_TANGENT
 	tangentUpdated.xyz += (tangent{X} - tangent.xyz) * morphTargetInfluences[{X}];
 	#endif
+
+    #ifdef MORPHTARGETS_UV
+	uvUpdated += (uv_{X} - uv) * morphTargetInfluences[{X}];
+	#endif
 #endif

+ 4 - 0
src/Shaders/ShadersInclude/morphTargetsVertexDeclaration.fx

@@ -8,4 +8,8 @@
 	#ifdef MORPHTARGETS_TANGENT
 	attribute vec3 tangent{X};
 	#endif
+
+    #ifdef MORPHTARGETS_UV
+	attribute vec2 uv_{X};
+	#endif
 #endif

+ 12 - 9
src/Shaders/default.vertex.fx

@@ -105,6 +105,9 @@ void main(void) {
 #ifdef TANGENT
 	vec4 tangentUpdated = tangent;
 #endif
+#ifdef UV1
+	vec2 uvUpdated = uv;
+#endif
 
 #include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]
 
@@ -153,14 +156,14 @@ void main(void) {
 
 	// Texture coordinates
 #ifndef UV1
-	vec2 uv = vec2(0., 0.);
+	vec2 uvUpdated = vec2(0., 0.);
 #endif
 #ifndef UV2
 	vec2 uv2 = vec2(0., 0.);
 #endif
 
 #ifdef MAINUV1
-	vMainUV1 = uv;
+	vMainUV1 = uvUpdated;
 #endif
 
 #ifdef MAINUV2
@@ -170,7 +173,7 @@ void main(void) {
 #if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0
 	if (vDiffuseInfos.x == 0.)
 	{
-		vDiffuseUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));
+		vDiffuseUV = vec2(diffuseMatrix * vec4(uvUpdated, 1.0, 0.0));
 	}
 	else
 	{
@@ -181,7 +184,7 @@ void main(void) {
 #if defined(AMBIENT) && AMBIENTDIRECTUV == 0
 	if (vAmbientInfos.x == 0.)
 	{
-		vAmbientUV = vec2(ambientMatrix * vec4(uv, 1.0, 0.0));
+		vAmbientUV = vec2(ambientMatrix * vec4(uvUpdated, 1.0, 0.0));
 	}
 	else
 	{
@@ -192,7 +195,7 @@ void main(void) {
 #if defined(OPACITY) && OPACITYDIRECTUV == 0
 	if (vOpacityInfos.x == 0.)
 	{
-		vOpacityUV = vec2(opacityMatrix * vec4(uv, 1.0, 0.0));
+		vOpacityUV = vec2(opacityMatrix * vec4(uvUpdated, 1.0, 0.0));
 	}
 	else
 	{
@@ -203,7 +206,7 @@ void main(void) {
 #if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0
 	if (vEmissiveInfos.x == 0.)
 	{
-		vEmissiveUV = vec2(emissiveMatrix * vec4(uv, 1.0, 0.0));
+		vEmissiveUV = vec2(emissiveMatrix * vec4(uvUpdated, 1.0, 0.0));
 	}
 	else
 	{
@@ -214,7 +217,7 @@ void main(void) {
 #if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0
 	if (vLightmapInfos.x == 0.)
 	{
-		vLightmapUV = vec2(lightmapMatrix * vec4(uv, 1.0, 0.0));
+		vLightmapUV = vec2(lightmapMatrix * vec4(uvUpdated, 1.0, 0.0));
 	}
 	else
 	{
@@ -225,7 +228,7 @@ void main(void) {
 #if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0
 	if (vSpecularInfos.x == 0.)
 	{
-		vSpecularUV = vec2(specularMatrix * vec4(uv, 1.0, 0.0));
+		vSpecularUV = vec2(specularMatrix * vec4(uvUpdated, 1.0, 0.0));
 	}
 	else
 	{
@@ -236,7 +239,7 @@ void main(void) {
 #if defined(BUMP) && BUMPDIRECTUV == 0
 	if (vBumpInfos.x == 0.)
 	{
-		vBumpUV = vec2(bumpMatrix * vec4(uv, 1.0, 0.0));
+		vBumpUV = vec2(bumpMatrix * vec4(uvUpdated, 1.0, 0.0));
 	}
 	else
 	{

+ 5 - 2
src/Shaders/depth.vertex.fx

@@ -26,7 +26,10 @@ varying float vDepthMetric;
 
 void main(void)
 {
-vec3 positionUpdated = position;
+    vec3 positionUpdated = position;
+#ifdef UV1
+    vec2 uvUpdated = uv;
+#endif
 #include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]
 
 #include<instancesVertex>
@@ -39,7 +42,7 @@ vec3 positionUpdated = position;
 
 #if defined(ALPHATEST) || defined(BASIC_RENDER)
 #ifdef UV1
-	vUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));
+	vUV = vec2(diffuseMatrix * vec4(uvUpdated, 1.0, 0.0));
 #endif
 #ifdef UV2
 	vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));

+ 6 - 3
src/Shaders/geometry.vertex.fx

@@ -48,8 +48,11 @@ varying vec4 vPreviousPosition;
 
 void main(void)
 {
-vec3 positionUpdated = position;
-vec3 normalUpdated = normal;
+    vec3 positionUpdated = position;
+    vec3 normalUpdated = normal;
+#ifdef UV1
+    vec2 uvUpdated = uv;
+#endif
 #include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]
 
 #include<instancesVertex>
@@ -109,7 +112,7 @@ vec3 normalUpdated = normal;
 
 #if defined(ALPHATEST) || defined(BASIC_RENDER)
 #ifdef UV1
-	vUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));
+	vUV = vec2(diffuseMatrix * vec4(uvUpdated, 1.0, 0.0));
 #endif
 #ifdef UV2
 	vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));

+ 6 - 4
src/Shaders/glowMapGeneration.vertex.fx

@@ -44,7 +44,9 @@ attribute vec2 uv2;
 void main(void)
 {
 	vec3 positionUpdated = position;
-
+#ifdef UV1
+    vec2 uvUpdated = uv;
+#endif
 #include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]
 #include<instancesVertex>
 #include<bonesVertex>
@@ -59,7 +61,7 @@ void main(void)
 
 #ifdef DIFFUSE
 	#ifdef DIFFUSEUV1
-		vUVDiffuse = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));
+		vUVDiffuse = vec2(diffuseMatrix * vec4(uvUpdated, 1.0, 0.0));
 	#endif
 	#ifdef DIFFUSEUV2
 		vUVDiffuse = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));
@@ -68,7 +70,7 @@ void main(void)
 
 #ifdef OPACITY
 	#ifdef OPACITYUV1
-		vUVOpacity = vec2(opacityMatrix * vec4(uv, 1.0, 0.0));
+		vUVOpacity = vec2(opacityMatrix * vec4(uvUpdated, 1.0, 0.0));
 	#endif
 	#ifdef OPACITYUV2
 		vUVOpacity = vec2(opacityMatrix * vec4(uv2, 1.0, 0.0));
@@ -77,7 +79,7 @@ void main(void)
 
 #ifdef EMISSIVE
 	#ifdef EMISSIVEUV1
-		vUVEmissive = vec2(emissiveMatrix * vec4(uv, 1.0, 0.0));
+		vUVEmissive = vec2(emissiveMatrix * vec4(uvUpdated, 1.0, 0.0));
 	#endif
 	#ifdef EMISSIVEUV2
 		vUVEmissive = vec2(emissiveMatrix * vec4(uv2, 1.0, 0.0));

+ 4 - 1
src/Shaders/outline.vertex.fx

@@ -30,6 +30,9 @@ void main(void)
 {
     vec3 positionUpdated = position;
     vec3 normalUpdated = normal;
+#ifdef UV1
+    vec2 uvUpdated = uv;
+#endif    
     #include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]
 
 	vec3 offsetPosition = positionUpdated + (normalUpdated * offset);
@@ -41,7 +44,7 @@ void main(void)
 
 #ifdef ALPHATEST
 #ifdef UV1
-	vUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));
+	vUV = vec2(diffuseMatrix * vec4(uvUpdated, 1.0, 0.0));
 #endif
 #ifdef UV2
 	vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));

+ 19 - 16
src/Shaders/pbr.vertex.fx

@@ -146,6 +146,9 @@ void main(void) {
 #ifdef TANGENT
     vec4 tangentUpdated = tangent;
 #endif
+#ifdef UV1
+    vec2 uvUpdated = uv;
+#endif  
 
 #include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]
 
@@ -205,14 +208,14 @@ void main(void) {
 
     // Texture coordinates
 #ifndef UV1
-    vec2 uv = vec2(0., 0.);
+    vec2 uvUpdated = vec2(0., 0.);
 #endif
 #ifndef UV2
     vec2 uv2 = vec2(0., 0.);
 #endif
 
 #ifdef MAINUV1
-    vMainUV1 = uv;
+    vMainUV1 = uvUpdated;
 #endif 
 
 #ifdef MAINUV2
@@ -222,7 +225,7 @@ void main(void) {
 #if defined(ALBEDO) && ALBEDODIRECTUV == 0 
     if (vAlbedoInfos.x == 0.)
     {
-        vAlbedoUV = vec2(albedoMatrix * vec4(uv, 1.0, 0.0));
+        vAlbedoUV = vec2(albedoMatrix * vec4(uvUpdated, 1.0, 0.0));
     }
     else
     {
@@ -233,7 +236,7 @@ void main(void) {
 #if defined(AMBIENT) && AMBIENTDIRECTUV == 0 
     if (vAmbientInfos.x == 0.)
     {
-        vAmbientUV = vec2(ambientMatrix * vec4(uv, 1.0, 0.0));
+        vAmbientUV = vec2(ambientMatrix * vec4(uvUpdated, 1.0, 0.0));
     }
     else
     {
@@ -244,7 +247,7 @@ void main(void) {
 #if defined(OPACITY) && OPACITYDIRECTUV == 0 
     if (vOpacityInfos.x == 0.)
     {
-        vOpacityUV = vec2(opacityMatrix * vec4(uv, 1.0, 0.0));
+        vOpacityUV = vec2(opacityMatrix * vec4(uvUpdated, 1.0, 0.0));
     }
     else
     {
@@ -255,7 +258,7 @@ void main(void) {
 #if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0 
     if (vEmissiveInfos.x == 0.)
     {
-        vEmissiveUV = vec2(emissiveMatrix * vec4(uv, 1.0, 0.0));
+        vEmissiveUV = vec2(emissiveMatrix * vec4(uvUpdated, 1.0, 0.0));
     }
     else
     {
@@ -266,7 +269,7 @@ void main(void) {
 #if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0 
     if (vLightmapInfos.x == 0.)
     {
-        vLightmapUV = vec2(lightmapMatrix * vec4(uv, 1.0, 0.0));
+        vLightmapUV = vec2(lightmapMatrix * vec4(uvUpdated, 1.0, 0.0));
     }
     else
     {
@@ -277,7 +280,7 @@ void main(void) {
 #if defined(REFLECTIVITY) && REFLECTIVITYDIRECTUV == 0 
     if (vReflectivityInfos.x == 0.)
     {
-        vReflectivityUV = vec2(reflectivityMatrix * vec4(uv, 1.0, 0.0));
+        vReflectivityUV = vec2(reflectivityMatrix * vec4(uvUpdated, 1.0, 0.0));
     }
     else
     {
@@ -288,7 +291,7 @@ void main(void) {
 #if defined(MICROSURFACEMAP) && MICROSURFACEMAPDIRECTUV == 0 
     if (vMicroSurfaceSamplerInfos.x == 0.)
     {
-        vMicroSurfaceSamplerUV = vec2(microSurfaceSamplerMatrix * vec4(uv, 1.0, 0.0));
+        vMicroSurfaceSamplerUV = vec2(microSurfaceSamplerMatrix * vec4(uvUpdated, 1.0, 0.0));
     }
     else
     {
@@ -299,7 +302,7 @@ void main(void) {
 #if defined(BUMP) && BUMPDIRECTUV == 0 
     if (vBumpInfos.x == 0.)
     {
-        vBumpUV = vec2(bumpMatrix * vec4(uv, 1.0, 0.0));
+        vBumpUV = vec2(bumpMatrix * vec4(uvUpdated, 1.0, 0.0));
     }
     else
     {
@@ -311,7 +314,7 @@ void main(void) {
     #if defined(CLEARCOAT_TEXTURE) && CLEARCOAT_TEXTUREDIRECTUV == 0 
         if (vClearCoatInfos.x == 0.)
         {
-            vClearCoatUV = vec2(clearCoatMatrix * vec4(uv, 1.0, 0.0));
+            vClearCoatUV = vec2(clearCoatMatrix * vec4(uvUpdated, 1.0, 0.0));
         }
         else
         {
@@ -322,7 +325,7 @@ void main(void) {
     #if defined(CLEARCOAT_BUMP) && CLEARCOAT_BUMPDIRECTUV == 0 
         if (vClearCoatBumpInfos.x == 0.)
         {
-            vClearCoatBumpUV = vec2(clearCoatBumpMatrix * vec4(uv, 1.0, 0.0));
+            vClearCoatBumpUV = vec2(clearCoatBumpMatrix * vec4(uvUpdated, 1.0, 0.0));
         }
         else
         {
@@ -333,7 +336,7 @@ void main(void) {
     #if defined(CLEARCOAT_TINT_TEXTURE) && CLEARCOAT_TINT_TEXTUREDIRECTUV == 0 
         if (vClearCoatTintInfos.x == 0.)
         {
-            vClearCoatTintUV = vec2(clearCoatTintMatrix * vec4(uv, 1.0, 0.0));
+            vClearCoatTintUV = vec2(clearCoatTintMatrix * vec4(uvUpdated, 1.0, 0.0));
         }
         else
         {
@@ -346,7 +349,7 @@ void main(void) {
     #if defined(SHEEN_TEXTURE) && SHEEN_TEXTUREDIRECTUV == 0 
         if (vSheenInfos.x == 0.)
         {
-            vSheenUV = vec2(sheenMatrix * vec4(uv, 1.0, 0.0));
+            vSheenUV = vec2(sheenMatrix * vec4(uvUpdated, 1.0, 0.0));
         }
         else
         {
@@ -359,7 +362,7 @@ void main(void) {
     #if defined(ANISOTROPIC_TEXTURE) && ANISOTROPIC_TEXTUREDIRECTUV == 0 
         if (vAnisotropyInfos.x == 0.)
         {
-            vAnisotropyUV = vec2(anisotropyMatrix * vec4(uv, 1.0, 0.0));
+            vAnisotropyUV = vec2(anisotropyMatrix * vec4(uvUpdated, 1.0, 0.0));
         }
         else
         {
@@ -372,7 +375,7 @@ void main(void) {
     #if defined(SS_THICKNESSANDMASK_TEXTURE) && SS_THICKNESSANDMASK_TEXTUREDIRECTUV == 0 
         if (vThicknessInfos.x == 0.)
         {
-            vThicknessUV = vec2(thicknessMatrix * vec4(uv, 1.0, 0.0));
+            vThicknessUV = vec2(thicknessMatrix * vec4(uvUpdated, 1.0, 0.0));
         }
         else
         {

+ 4 - 1
src/Shaders/shadowMap.vertex.fx

@@ -35,6 +35,9 @@ attribute vec2 uv2;
 void main(void)
 {
 vec3 positionUpdated = position;
+#ifdef UV1
+    vec2 uvUpdated = uv;
+#endif  
 
 #include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]
 
@@ -80,7 +83,7 @@ gl_Position = viewProjection * worldPos;
 
 #ifdef ALPHATEST
     #ifdef UV1
-        vUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));
+        vUV = vec2(diffuseMatrix * vec4(uvUpdated, 1.0, 0.0));
     #endif
     #ifdef UV2
         vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));