Browse Source

Fix incorrect shadows on the master mesh when using a lod mesh

Popov72 4 năm trước cách đây
mục cha
commit
d15459649e

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

@@ -337,6 +337,8 @@
 - Changed use of mousemove to pointermove in freeCameraMouseInput and flyCameraMouseInput to fix issue with Firefox ([PolygonalSun](https://github.com/PolygonalSun))
 - Fixed `TriPlanarMaterial` to compute the right world normals ([julien-moreau](https://github.com/julien-moreau))
 - Fix `SkeletonViewer` to use utillity layer with custom lighting to improve debug mesh visibility ([Drigax](https://github.com/drigax))
+- Fix same sub mesh being rendered multiple times in the shadow map ([Popov72](https://github.com/Popov72))
+- Fix incorrect shadows on the master mesh when using a lod mesh ([Popov72](https://github.com/Popov72))
 
 ## Breaking changes
 

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

@@ -1099,6 +1099,14 @@ export class ShadowGenerator implements IShadowGenerator {
         }
 
         var hardwareInstancedRendering = engine.getCaps().instancedArrays && (batch.visibleInstances[subMesh._id] !== null && batch.visibleInstances[subMesh._id] !== undefined || renderingMesh.hasThinInstances);
+        if (effectiveMesh._internalAbstractMeshDataInfo._currentLOD !== effectiveMesh) {
+            if (hardwareInstancedRendering) {
+                delete batch.renderSelf[subMesh._id];
+            } else {
+                return;
+            }
+        }
+
         if (this.isReady(subMesh, hardwareInstancedRendering, isTransparent)) {
             subMesh._renderId = scene.getRenderId();
 

+ 1 - 0
src/Meshes/abstractMesh.ts

@@ -86,6 +86,7 @@ class _InternalAbstractMeshDataInfo {
     public _isActiveIntermediate = false;
     public _onlyForInstancesIntermediate = false;
     public _actAsRegularMesh = false;
+    public _currentLOD: Nullable<AbstractMesh> = null;
 }
 
 /**

+ 1 - 0
src/scene.ts

@@ -3555,6 +3555,7 @@ export class Scene extends AbstractScene implements IAnimatable, IClipPlanesHold
             if (meshToRender === undefined || meshToRender === null) {
                 continue;
             }
+            mesh._internalAbstractMeshDataInfo._currentLOD = meshToRender;
 
             // Compute world matrix if LOD is billboard
             if (meshToRender !== mesh && meshToRender.billboardMode !== TransformNode.BILLBOARDMODE_NONE) {