Browse Source

Merge pull request #7820 from sebavan/master

Fix shadow issues with refresh rate and freeze.
sebavan 5 years ago
parent
commit
f3756e65cf

+ 7 - 0
src/Lights/Shadows/shadowGenerator.ts

@@ -870,6 +870,13 @@ export class ShadowGenerator implements IShadowGenerator {
         // Custom render function.
         this._shadowMap.customRenderFunction = this._renderForShadowMap.bind(this);
 
+        // Force the mesh is ready funcion to true as we are double checking it
+        // in the custom render function. Also it prevents side effects and useless
+        // shader variations in DEPTHPREPASS mode.
+        this._shadowMap.customIsReadyFunction = (m: AbstractMesh, r: number) => {
+            return true;
+        };
+
         let engine = this._scene.getEngine();
 
         // Record Face Index before render.

+ 11 - 1
src/Materials/Textures/renderTargetTexture.ts

@@ -121,6 +121,10 @@ export class RenderTargetTexture extends Texture {
      */
     public activeCamera: Nullable<Camera>;
     /**
+     * Override the mesh isReady function with your own one.
+     */
+    public customIsReadyFunction: (mesh: AbstractMesh, refreshRate: number) => boolean;
+    /**
      * Override the render function of the texture with your own one.
      */
     public customRenderFunction: (opaqueSubMeshes: SmartArray<SubMesh>, alphaTestSubMeshes: SmartArray<SubMesh>, transparentSubMeshes: SmartArray<SubMesh>, depthOnlySubMeshes: SmartArray<SubMesh>, beforeTransparents?: () => void) => void;
@@ -745,7 +749,13 @@ export class RenderTargetTexture extends Texture {
             var mesh = currentRenderList[meshIndex];
 
             if (mesh) {
-                if (!mesh.isReady(this.refreshRate === 0)) {
+                if (this.customIsReadyFunction) {
+                    if (!this.customIsReadyFunction(mesh, this.refreshRate)) {
+                        this.resetRefreshCounter();
+                        continue;
+                    }
+                }
+                else if (!mesh.isReady(this.refreshRate === 0)) {
                     this.resetRefreshCounter();
                     continue;
                 }