Forráskód Böngészése

Merge pull request #6435 from MarkusBillharz/Add-MeshMorph-Support-To-DepthRenderer

Add MeshMorph support to the DepthRenderer.
David Catuhe 6 éve
szülő
commit
0b3b23a260

+ 1 - 0
dist/preview release/what's new.md

@@ -18,6 +18,7 @@
 - Added support for PBR [irradiance map](https://doc.babylonjs.com/how_to/physically_based_rendering_master#irradiance-map)
 - Added support for PBR [irradiance map](https://doc.babylonjs.com/how_to/physically_based_rendering_master#irradiance-map)
 - Ability to set render camera on utility layer instead of using the latest active camera ([TrevorDev](https://github.com/TrevorDev))
 - Ability to set render camera on utility layer instead of using the latest active camera ([TrevorDev](https://github.com/TrevorDev))
 - Method to check if device orientation is available ([TrevorDev](https://github.com/TrevorDev))
 - Method to check if device orientation is available ([TrevorDev](https://github.com/TrevorDev))
+- Added MorphTarget support to the DepthRenderer ([MarkusBillharz](https://github.com/MarkusBillharz))
 
 
 ### Engine
 ### Engine
 - Added preprocessors for shaders to improve how shaders are compiled for WebGL1/2 or WebGPU ([Deltakosh](https://github.com/deltakosh/))
 - Added preprocessors for shaders to improve how shaders are compiled for WebGL1/2 or WebGPU ([Deltakosh](https://github.com/deltakosh/))

+ 21 - 2
src/Rendering/depthRenderer.ts

@@ -1,5 +1,6 @@
 import { Nullable } from "../types";
 import { Nullable } from "../types";
 import { Color4 } from "../Maths/math";
 import { Color4 } from "../Maths/math";
+import { Mesh } from "../Meshes/mesh";
 import { SubMesh } from "../Meshes/subMesh";
 import { SubMesh } from "../Meshes/subMesh";
 import { VertexBuffer } from "../Meshes/buffer";
 import { VertexBuffer } from "../Meshes/buffer";
 import { SmartArray } from "../Misc/smartArray";
 import { SmartArray } from "../Misc/smartArray";
@@ -118,6 +119,9 @@ export class DepthRenderer {
                     this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
                     this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
                 }
                 }
 
 
+                // Morph targets
+                MaterialHelper.BindMorphTargetParameters(mesh, this._effect);
+
                 // Draw
                 // Draw
                 mesh._processRendering(subMesh, this._effect, Material.TriangleFillMode, batch, hardwareInstancedRendering,
                 mesh._processRendering(subMesh, this._effect, Material.TriangleFillMode, batch, hardwareInstancedRendering,
                     (isInstance, world) => this._effect.setMatrix("world", world));
                     (isInstance, world) => this._effect.setMatrix("world", world));
@@ -190,6 +194,20 @@ export class DepthRenderer {
             defines.push("#define NUM_BONE_INFLUENCERS 0");
             defines.push("#define NUM_BONE_INFLUENCERS 0");
         }
         }
 
 
+        // Morph targets
+        const morphTargetManager = (mesh as Mesh).morphTargetManager;
+        let numMorphInfluencers = 0;
+        if (morphTargetManager) {
+            if (morphTargetManager.numInfluencers > 0) {
+                numMorphInfluencers = morphTargetManager.numInfluencers;
+
+                defines.push("#define MORPHTARGETS");
+                defines.push("#define NUM_MORPH_INFLUENCERS " + numMorphInfluencers);
+
+                MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, { "NUM_MORPH_INFLUENCERS": numMorphInfluencers });
+            }
+        }
+
         // Instances
         // Instances
         if (useInstances) {
         if (useInstances) {
             defines.push("#define INSTANCES");
             defines.push("#define INSTANCES");
@@ -202,8 +220,9 @@ export class DepthRenderer {
             this._cachedDefines = join;
             this._cachedDefines = join;
             this._effect = this._scene.getEngine().createEffect("depth",
             this._effect = this._scene.getEngine().createEffect("depth",
                 attribs,
                 attribs,
-                ["world", "mBones", "viewProjection", "diffuseMatrix", "depthValues"],
-                ["diffuseSampler"], join);
+                ["world", "mBones", "viewProjection", "diffuseMatrix", "depthValues", "morphTargetInfluences"],
+                ["diffuseSampler"], join,
+                undefined, undefined, undefined, { maxSimultaneousMorphTargets: numMorphInfluencers });
         }
         }
 
 
         return this._effect.isReady();
         return this._effect.isReady();

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

@@ -2,6 +2,9 @@
 attribute vec3 position;
 attribute vec3 position;
 #include<bonesDeclaration>
 #include<bonesDeclaration>
 
 
+#include<morphTargetsVertexGlobalDeclaration>
+#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]
+
 // Uniform
 // Uniform
 #include<instancesDeclaration>
 #include<instancesDeclaration>
 
 
@@ -23,11 +26,14 @@ varying float vDepthMetric;
 
 
 void main(void)
 void main(void)
 {
 {
+vec3 positionUpdated = position;
+#include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]
+
 #include<instancesVertex>
 #include<instancesVertex>
 
 
 #include<bonesVertex>
 #include<bonesVertex>
 
 
-	gl_Position = viewProjection * finalWorld * vec4(position, 1.0);
+	gl_Position = viewProjection * finalWorld * vec4(positionUpdated, 1.0);
 	
 	
 	vDepthMetric = ((gl_Position.z + depthValues.x) / (depthValues.y));
 	vDepthMetric = ((gl_Position.z + depthValues.x) / (depthValues.y));
 
 
@@ -39,4 +45,4 @@ void main(void)
 	vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));
 	vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));
 #endif
 #endif
 #endif
 #endif
-}
+}