浏览代码

Use SubMesh._effectOverride instead of a new parameter to bindForSubMesh

Popov72 5 年之前
父节点
当前提交
512357779d

+ 3 - 1
src/Lights/Shadows/shadowGenerator.ts

@@ -1073,7 +1073,9 @@ export class ShadowGenerator implements IShadowGenerator {
             }
 
             if (shadowDepthMat) {
-                material.bindForSubMesh(effectiveMesh.getWorldMatrix(), renderingMesh, subMesh, effect);
+                subMesh._effectOverride = effect;
+                material.bindForSubMesh(effectiveMesh.getWorldMatrix(), renderingMesh, subMesh);
+                subMesh._effectOverride = null;
             } else {
                 effect.setMatrix("viewProjection", this.getTransformMatrix());
                 // Alpha test

+ 2 - 3
src/Materials/PBR/pbrBaseMaterial.ts

@@ -1609,9 +1609,8 @@ export abstract class PBRBaseMaterial extends PushMaterial {
      * @param world - The world matrix.
      * @param mesh - The BJS mesh.
      * @param subMesh - A submesh of the BJS mesh.
-     * @param effectOverride - If provided, use this effect instead of the submesh effect
      */
-    public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh, effectOverride?: Nullable<Effect>): void {
+    public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void {
         var scene = this.getScene();
 
         var defines = <PBRMaterialDefines>subMesh._materialDefines;
@@ -1619,7 +1618,7 @@ export abstract class PBRBaseMaterial extends PushMaterial {
             return;
         }
 
-        var effect = effectOverride ?? subMesh.effect;
+        var effect = subMesh._effectOverride ?? subMesh.effect;
 
         if (!effect) {
             return;

+ 1 - 2
src/Materials/material.ts

@@ -863,9 +863,8 @@ export class Material implements IAnimatable {
      * @param world defines the world transformation matrix
      * @param mesh defines the mesh containing the submesh
      * @param subMesh defines the submesh to bind the material to
-     * @param effectOverride - If provided, use this effect instead of the submesh effect
      */
-    public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh, effectOverride?: Nullable<Effect>): void {
+    public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void {
     }
 
     /**

+ 2 - 3
src/Materials/shaderMaterial.ts

@@ -653,10 +653,9 @@ export class ShaderMaterial extends Material {
      * @param world defines the world transformation matrix
      * @param mesh defines the mesh containing the submesh
      * @param subMesh defines the submesh to bind the material to
-     * @param effectOverride - If provided, use this effect instead of internal effect
      */
-    public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh, effectOverride?: Nullable<Effect>): void {
-        this.bind(world, mesh, effectOverride);
+    public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void {
+        this.bind(world, mesh, subMesh._effectOverride ?? this._effect);
     }
 
     /**

+ 2 - 3
src/Materials/standardMaterial.ts

@@ -1290,9 +1290,8 @@ export class StandardMaterial extends PushMaterial {
      * @param world defines the world transformation matrix
      * @param mesh defines the mesh containing the submesh
      * @param subMesh defines the submesh to bind the material to
-     * @param effectOverride - If provided, use this effect instead of the submesh effect
      */
-    public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh, effectOverride?: Nullable<Effect>): void {
+    public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void {
         var scene = this.getScene();
 
         var defines = <StandardMaterialDefines>subMesh._materialDefines;
@@ -1300,7 +1299,7 @@ export class StandardMaterial extends PushMaterial {
             return;
         }
 
-        var effect = effectOverride ?? subMesh.effect;
+        var effect = subMesh._effectOverride ?? subMesh.effect;
         if (!effect) {
             return;
         }

+ 2 - 0
src/Meshes/subMesh.ts

@@ -27,6 +27,8 @@ export class BaseSubMesh {
     public _materialDefines: Nullable<MaterialDefines> = null;
     /** @hidden */
     public _materialEffect: Nullable<Effect> = null;
+    /** @hidden */
+    public _effectOverride: Nullable<Effect> = null;
 
     /**
      * Gets material defines used by the effect associated to the sub mesh