浏览代码

Fix bug in standalone mode

Popov72 5 年之前
父节点
当前提交
e5d8297bbc
共有 2 个文件被更改,包括 16 次插入2 次删除
  1. 5 1
      src/Lights/Shadows/shadowGenerator.ts
  2. 11 1
      src/Materials/shadowDepthWrapper.ts

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

@@ -1074,7 +1074,11 @@ export class ShadowGenerator implements IShadowGenerator {
 
             if (shadowDepthWrapper) {
                 subMesh._effectOverride = effect;
-                material.bindForSubMesh(effectiveMesh.getWorldMatrix(), renderingMesh, subMesh);
+                if (shadowDepthWrapper.standalone) {
+                    shadowDepthWrapper.baseMaterial.bindForSubMesh(effectiveMesh.getWorldMatrix(), renderingMesh, subMesh);
+                } else {
+                    material.bindForSubMesh(effectiveMesh.getWorldMatrix(), renderingMesh, subMesh);
+                }
                 subMesh._effectOverride = null;
             } else {
                 effect.setMatrix("viewProjection", this.getTransformMatrix());

+ 11 - 1
src/Materials/shadowDepthWrapper.ts

@@ -63,6 +63,16 @@ export class ShadowDepthWrapper {
     /** @hidden */
     public _matriceNames: any;
 
+    /** Gets the standalone status of the wrapper */
+    public get standalone(): boolean {
+        return this._options?.standalone ?? false;
+    }
+
+    /** Gets the base material the wrapper is built upon */
+    public get baseMaterial(): Material {
+        return this._baseMaterial;
+    }
+
     /**
      * Instantiate a new shadow depth wrapper.
      * It works by injecting some specific code in the vertex/fragment shaders of the base material and is used by a shadow generator to
@@ -134,7 +144,7 @@ export class ShadowDepthWrapper {
      * @returns a boolean indicating that the submesh is ready or not
      */
     public isReadyForSubMesh(subMesh: SubMesh, defines: string[], shadowGenerator: ShadowGenerator, useInstances: boolean): boolean {
-        if (this._options?.standalone) {
+        if (this.standalone) {
             // will ensure the effect is (re)created for the base material
             this._baseMaterial.isReadyForSubMesh(subMesh.getMesh(), subMesh, useInstances);
         }