David Catuhe 7 anni fa
parent
commit
6ed72b39ab

+ 18 - 2
src/Lights/Shadows/babylon.shadowGenerator.ts

@@ -902,6 +902,9 @@
                     this._effect.setMatrices("mBones", (<Skeleton>mesh.skeleton).getTransformMatrices((mesh)));
                 }
 
+                // Morph targets
+                MaterialHelper.BindMorphTargetParameters(mesh, this._effect);
+
                 if (this.forceBackFacesOnly) {
                     engine.setState(true, 0, false, true);
                 }
@@ -1075,6 +1078,18 @@
                 defines.push("#define NUM_BONE_INFLUENCERS 0");
             }
 
+            // Morph targets         
+            var manager = (<Mesh>mesh).morphTargetManager;
+            let morphInfluencers = 0;
+            if (manager) {
+                if (manager.numInfluencers > 0) {
+                    defines.push("#define MORPHTARGETS");
+                    morphInfluencers = manager.numInfluencers;
+                    defines.push("#define NUM_MORPH_INFLUENCERS " + morphInfluencers);
+                    MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, {"NUM_MORPH_INFLUENCERS": morphInfluencers });
+                }
+            }
+
             // Instances
             if (useInstances) {
                 defines.push("#define INSTANCES");
@@ -1090,8 +1105,9 @@
                 this._cachedDefines = join;
                 this._effect = this._scene.getEngine().createEffect("shadowMap",
                     attribs,
-                    ["world", "mBones", "viewProjection", "diffuseMatrix", "lightData", "depthValues", "biasAndScale"],
-                    ["diffuseSampler"], join);
+                    ["world", "mBones", "viewProjection", "diffuseMatrix", "lightData", "depthValues", "biasAndScale", "morphTargetInfluences"],
+                    ["diffuseSampler"], join,
+                undefined, undefined, undefined, { maxSimultaneousMorphTargets: morphInfluencers });
             }
 
             if (!this._effect.isReady()) {

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

@@ -8,6 +8,9 @@ attribute vec3 position;
 
 #include<bonesDeclaration>
 
+#include<morphTargetsVertexGlobalDeclaration>
+#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]
+
 // Uniforms
 #include<instancesDeclaration>
 #include<helperFunctions>
@@ -31,10 +34,14 @@ attribute vec2 uv2;
 
 void main(void)
 {
+vec3 positionUpdated = position;
+
+#include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]
+
 #include<instancesVertex>
 #include<bonesVertex>
 
-vec4 worldPos = finalWorld * vec4(position, 1.0);
+vec4 worldPos = finalWorld * vec4(positionUpdated, 1.0);
 
 // Normal inset Bias.
 #ifdef NORMAL