Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复正交相机下 物体排序距离计算错误bug #763

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/layaAir/laya/d3/core/scene/Scene3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
11 changes: 10 additions & 1 deletion src/layaAir/laya/d3/graphics/FrustumCulling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export class CameraCullInfo {
boundFrustum: BoundFrustum;
/**遮挡标记 */
cullingMask: number;
/**是否正交 */
orthographic:boolean;
}
/**
* 阴影裁剪数据
Expand Down Expand Up @@ -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);
Expand Down