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 bug retrieving depth buffer for mouse scene collision #620

Merged
merged 2 commits into from
Jan 29, 2025

Conversation

calvertdw
Copy link
Member

@calvertdw calvertdw commented Jan 28, 2025

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

After the fix:
image

@@ -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;
Copy link
Member Author

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);
Copy link
Member Author

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)
Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Contributor

@TomaszTB TomaszTB left a 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

@calvertdw calvertdw merged commit 996f610 into develop Jan 29, 2025
66 of 70 checks passed
@calvertdw calvertdw deleted the bugfix/height-map-mouse-collision branch January 29, 2025 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants