Selaa lähdekoodia

Merge pull request #6445 from MarkusBillharz/Add-MeshMorph-Support-To-The-OutlineRenderer

Add MeshMorph support to the OutlineRenderer
David Catuhe 6 vuotta sitten
vanhempi
commit
f6ea554c81

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

@@ -19,7 +19,7 @@
 - Ability to set render camera on utility layer instead of using the latest active camera ([TrevorDev](https://github.com/TrevorDev))
 - Move normalizeToUnitCube to transformNode instead of abstract mesh and add predicate to exclude sub objects when scaling ([TrevorDev](https://github.com/TrevorDev))
 - Method to check if device orientation is available ([TrevorDev](https://github.com/TrevorDev))
-- Added MorphTarget support to the DepthRenderer and GeometryBufferRenderer ([MarkusBillharz](https://github.com/MarkusBillharz))
+- Added MorphTarget support to the DepthRenderer, GeometryBufferRenderer and OutlineRenderer ([MarkusBillharz](https://github.com/MarkusBillharz))
 
 ### Engine
 - Added preprocessors for shaders to improve how shaders are compiled for WebGL1/2 or WebGPU ([Deltakosh](https://github.com/deltakosh/))

+ 22 - 3
src/Rendering/outlineRenderer.ts

@@ -1,6 +1,6 @@
 import { VertexBuffer } from "../Meshes/buffer";
 import { SubMesh } from "../Meshes/subMesh";
-import { _InstancesBatch } from "../Meshes/mesh";
+import { _InstancesBatch, Mesh } from "../Meshes/mesh";
 import { AbstractMesh } from "../Meshes/abstractMesh";
 import { Scene } from "../scene";
 import { Engine } from "../Engines/engine";
@@ -188,6 +188,9 @@ export class OutlineRenderer implements ISceneComponent {
             this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
         }
 
+        // Morph targets
+        MaterialHelper.BindMorphTargetParameters(mesh, this._effect);
+
         mesh._bind(subMesh, this._effect, Material.TriangleFillMode);
 
         // Alpha test
@@ -253,6 +256,20 @@ export class OutlineRenderer implements ISceneComponent {
             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
         if (useInstances) {
             defines.push("#define INSTANCES");
@@ -265,8 +282,10 @@ export class OutlineRenderer implements ISceneComponent {
             this._cachedDefines = join;
             this._effect = this.scene.getEngine().createEffect("outline",
                 attribs,
-                ["world", "mBones", "viewProjection", "diffuseMatrix", "offset", "color", "logarithmicDepthConstant"],
-                ["diffuseSampler"], join);
+                ["world", "mBones", "viewProjection", "diffuseMatrix", "offset", "color", "logarithmicDepthConstant", "morphTargetInfluences"],
+                ["diffuseSampler"], join,
+                undefined, undefined, undefined,
+                { maxSimultaneousMorphTargets: numMorphInfluencers });
         }
 
         return this._effect.isReady();

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

@@ -4,6 +4,9 @@ attribute vec3 normal;
 
 #include<bonesDeclaration>
 
+#include<morphTargetsVertexGlobalDeclaration>
+#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]
+
 // Uniform
 uniform float offset;
 
@@ -25,7 +28,11 @@ attribute vec2 uv2;
 
 void main(void)
 {
-	vec3 offsetPosition = position + normal * offset;
+    vec3 positionUpdated = position;
+    vec3 normalUpdated = normal;
+    #include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]
+
+	vec3 offsetPosition = positionUpdated + (normalUpdated * offset);
 
 #include<instancesVertex>
 #include<bonesVertex>