-
Notifications
You must be signed in to change notification settings - Fork 94
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 bug retrieving depth buffer for mouse scene collision #620
Conversation
@@ -129,9 +129,9 @@ public Point3DReadOnly getPickPointInWorld(double fallbackXYPlaneIntersectionHei | |||
|
|||
int rowAdjustment = aliasedFlippedMouseY * aliasedRenderedAreaWidth * Float.BYTES; | |||
int columnAdjustment = aliasedMouseX * Float.BYTES; | |||
float normalizedDeviceCoordinateZ = depthBuffer.getFloat(rowAdjustment + columnAdjustment); | |||
float normalizedDeviceCoordinateZ = 2.0f * depthBuffer.getFloat(rowAdjustment + columnAdjustment) - 1.0f; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apply the same math that's in the depth sensor shader
GL41.glPixelStorei(GL41.GL_UNPACK_ALIGNMENT, 4); // to read floats | ||
// Note: This line has significant performance impact | ||
GL41.glReadPixels(0, 0, (int) renderSizeX, (int) renderSizeY, GL41.GL_RED, GL41.GL_FLOAT, normalizedDeviceCoordinateDepthDirectByteBuffer); | ||
GL41.glReadPixels(0, 0, (int) renderSizeX, (int) renderSizeY, GL41.GL_DEPTH_COMPONENT, GL41.GL_FLOAT, normalizedDeviceCoordinateDepthDirectByteBuffer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switch to correctly using the DEPTH_COMPONENT
@@ -65,4 +65,20 @@ public static void clear(HeightMapMessage messageToClear) | |||
messageToClear.getVariances().clear(); | |||
messageToClear.getCentroids().clear(); | |||
} | |||
|
|||
public static void setToFlatGround(HeightMapMessage message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useful for generating a flat ground height map graphic for testing purposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This demo class has been expanded to cover more cases for mouse scene collision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OpenGL stuff looks good to me
Depth for scene collision looked like this for some objects because we retrieved the RED channel erroneously. Now that we moved to the GLTF shader by msgX, it's actually the red channel. Easily fixed by doing the correct thing and grabbing the depth attachment.
![image](https://private-user-images.githubusercontent.com/1161586/407502565-8681c196-f990-4d1f-8cbf-cb99d924aa41.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg4MTg0OTIsIm5iZiI6MTczODgxODE5MiwicGF0aCI6Ii8xMTYxNTg2LzQwNzUwMjU2NS04NjgxYzE5Ni1mOTkwLTRkMWYtOGNiZi1jYjk5ZDkyNGFhNDEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDZUMDUwMzEyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NDlkM2FjNTM4YjQxY2VhYjEwMDg4ZDdmNDVhYmJhNDk3YTE0YzI3ZDM3MTdmMjczNzlkOGY0Zjk1OTcxMzZiZCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.SzOmWhRBTIqtScg0s1WlCQ6Inu5SzAdrBeCIYLjwPCQ)
After the fix:
![image](https://private-user-images.githubusercontent.com/1161586/407503824-c759254b-3b9e-4f53-a862-11faeb4b47ef.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIi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