From 6c7e1ccc01607784852b4a8cdcf1120ee527ba87 Mon Sep 17 00:00:00 2001 From: sywoon Date: Wed, 10 Nov 2021 17:55:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=AD=A3=E4=BA=A4=E7=9B=B8?= =?UTF-8?q?=E6=9C=BA=E4=B8=8B=20=E7=89=A9=E4=BD=93=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E8=B7=9D=E7=A6=BB=E8=AE=A1=E7=AE=97=E9=94=99=E8=AF=AFbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layaAir/laya/d3/core/scene/Scene3D.ts | 1 + src/layaAir/laya/d3/graphics/FrustumCulling.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/layaAir/laya/d3/core/scene/Scene3D.ts b/src/layaAir/laya/d3/core/scene/Scene3D.ts index 57e594e51c..5680918ffe 100644 --- a/src/layaAir/laya/d3/core/scene/Scene3D.ts +++ b/src/layaAir/laya/d3/core/scene/Scene3D.ts @@ -1144,6 +1144,7 @@ export class Scene3D extends Sprite implements ISubmit, ICreateResource { cameraCullInfo.cullingMask = camera.cullingMask; cameraCullInfo.boundFrustum = camera.boundFrustum; cameraCullInfo.useOcclusionCulling = camera.useOcclusionCulling; + cameraCullInfo.orthographic = camera.orthographic; FrustumCulling.renderObjectCulling(cameraCullInfo, this, context, shader, replacementTag, false); } diff --git a/src/layaAir/laya/d3/graphics/FrustumCulling.ts b/src/layaAir/laya/d3/graphics/FrustumCulling.ts index 74be528ac3..f642dc560e 100644 --- a/src/layaAir/laya/d3/graphics/FrustumCulling.ts +++ b/src/layaAir/laya/d3/graphics/FrustumCulling.ts @@ -33,6 +33,8 @@ export class CameraCullInfo { boundFrustum: BoundFrustum; /**遮挡标记 */ cullingMask: number; + /**是否正交 */ + orthographic:boolean; } /** * 阴影裁剪数据 @@ -103,7 +105,14 @@ export class FrustumCulling { Stat.frustumCulling++; if (!cameraCullInfo.useOcclusionCulling || render._needRender(boundFrustum, context)) { render._renderMark = loopCount; - render._distanceForSort = Vector3.distance(render.bounds.getCenter(), camPos);//TODO:合并计算浪费,或者合并后取平均值 + + //@fix 修复正交相机下 物体距离计算错误 导致排序出错 + if (cameraCullInfo.orthographic) { + render._distanceForSort = Vector3.dot(boundFrustum.near.normal, render.bounds.getCenter()); + } else { + render._distanceForSort = Vector3.distance(render.bounds.getCenter(), camPos);//TODO:合并计算浪费,或者合并后取平均值 + } + var elements: RenderElement[] = render._renderElements; for (var j: number = 0, m: number = elements.length; j < m; j++) elements[j]._update(scene, context, customShader, replacementTag);