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

Fix incorrect distance given by ViewRangefinder3d #11993

Closed

Conversation

floppyhammer
Copy link
Contributor

@floppyhammer floppyhammer commented Feb 20, 2024

Objective

Fixes #11608.

Solution

This PR makes ViewRangefinder3d calculate object-to-camera distance correctly in order to sort them properly.

Migration Guide

In sturct ViewRangefinder3d, from_view_matrix has been renamed to from_view_proj_matrix.

@IDEDARY
Copy link
Contributor

IDEDARY commented Feb 20, 2024

This PR is a major improvement and almost fixes #11608 issue. Under normal circumstances, the bug is gone, but I noticed the same behavior happens under extreme angles.

Works as expected now
image

But if the camera's direction vector is pointing in the direction of the plane's normal vector while the plane is still visible, the order issue is still there. (note that the middle plane is at 0,0,0, so if we see it's back that means we are looking in the direction of the plane's normal)

image

@floppyhammer
Copy link
Contributor Author

But if the camera's direction vector is pointing in the direction of the plane's normal vector while the plane is still visible, the order issue is still there. (note that the middle plane is at 0,0,0, so if we see it's back that means we are looking in the direction of the plane's normal)

Sorry I don't really get what you mean. How the plane can be visible if its front face points outward from the camera?

@alice-i-cecile alice-i-cecile added this to the 0.13.1 milestone Feb 20, 2024
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen labels Feb 20, 2024
@IDEDARY
Copy link
Contributor

IDEDARY commented Feb 20, 2024

Sorry I don't really get what you mean. How the plane can be visible if its front face points outward from the camera?
Ah, I will showcase it here:

These diagrams are showcasing the situation from my example above in birds perspective (top down)...
image
As you can see, the issue was fixed under this condition (thanks so much btw, great work. Much appreciated 👍🏻 )

But in the second picture I show this situation...
image
It breaks things, because if not the top rectangle should have been darkened like in the first image, because there is a black square on top of it with 60% opacity.

That sums up my review.
I would 100% merge this PR (unless it breaks other stuff), but I would not consider the issue fixed.
Great job 👍🏻

@floppyhammer
Copy link
Contributor Author

@IDEDARY Okay I get it.

1

@floppyhammer
Copy link
Contributor Author

@IDEDARY Why the plane positions along X and Y are different?

For the two planes having order issue, their positions are as follows.

Plane 1 Vec3(9.0, -182.5, -170.0)
Plane 2 Vec3(-2.5, 202.5, -140.0)

From the render result, I suppose the two planes should have different Z coordinate only.

@floppyhammer floppyhammer marked this pull request as draft February 21, 2024 03:11
@floppyhammer
Copy link
Contributor Author

@IDEDARY Considering the 3d/texture example is all good at any camera angle, it's very possible the issue has something to do with how you place the UI panels in your layouting system.

@IDEDARY
Copy link
Contributor

IDEDARY commented Feb 21, 2024

I don't believe so, but I will carry out further investigation and try to create a minimal recreation project without my layouting. It should give us some insight into the origin of the problem.

Im unsure about the different cords, but I use parenting. Quads are defined through center point and they aren't perfectly centered either so it might come from that. But I will also look into it.

@IDEDARY
Copy link
Contributor

IDEDARY commented Mar 7, 2024

@IDEDARY Considering the 3d/texture example is all good at any camera angle, it's very possible the issue has something to do with how you place the UI panels in your layouting system.

@floppyhammer I have created bare-bones reproducible (roughly 100 lines of code) without any of my layouting code present. It's the same thing, but the abstraction is removed. The issue is unfortunately still present :/

@floppyhammer
Copy link
Contributor Author

@IDEDARY I'll look into it.

@floppyhammer
Copy link
Contributor Author

I'm closing this as this solution is not good enough. We might need a more sophisticated solution (e.g. BSP trees) to handle the order issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AlphaMode Blend - Z ordering errors
3 participants