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

IECoreGL::Selector : Camera-space depth sampling #1404

Merged
merged 1 commit into from
Feb 6, 2024

Conversation

ericmehl
Copy link
Collaborator

@ericmehl ericmehl commented Feb 2, 2024

Previously, we were using OpenGL's depth buffer to sample depths. OpenGL stores depth samples in a quasi-NDC space range [0.0, 1.0]. This must then be converted to camera-space using a series of multiplication and additions, which accumulate floating point error. The end result can have significant error, especially when clipping planes are set far apart.

This solution uses geometryP output from vertex shaders to get the camera-space Z value without precision-reducing floating point operations.

Checklist

  • I have read the contribution guidelines.
  • I have updated the documentation, if applicable.
  • I have tested my change(s) in the test suite, and added new test cases where necessary.
  • My code follows the Cortex project's prevailing coding style and conventions.

src/IECoreGL/ColorTexture.cpp Outdated Show resolved Hide resolved
src/IECoreGL/Selector.cpp Outdated Show resolved Hide resolved
src/IECoreGL/Selector.cpp Show resolved Hide resolved
src/IECoreGL/Selector.cpp Outdated Show resolved Hide resolved
@ericmehl ericmehl force-pushed the OpenGLWorldDepth branch 4 times, most recently from abd8d39 to 91a3646 Compare February 5, 2024 20:54
@ericmehl
Copy link
Collaborator Author

ericmehl commented Feb 5, 2024

Thanks John! I fixed the issues you pointed out and ready for a new look.

@johnhaddon
Copy link
Member

Thanks Eric, LGTM. Could you squash down and merge please? Then we can get a release out so you can update your Gaffer PR...

Previously, we were using OpenGL's depth buffer to sample depths. OpenGL
stores depth samples in a quasi-NDC space range [0.0, 1.0].
This must then be converted to camera-space using a series of
multiplication and additions, which accumulate floating point error.
The end result can have significant error, especially when clipping
planes are set far apart.

This solution uses `geometryP` output from vertex shaders to get the
camera-space Z value without precision-reducing floating point
operations.
@ericmehl
Copy link
Collaborator Author

ericmehl commented Feb 6, 2024

Squashed!

@johnhaddon johnhaddon merged commit d36ae7d into ImageEngine:RB-10.5 Feb 6, 2024
4 checks passed
ericmehl added a commit to ericmehl/gaffer that referenced this pull request Feb 7, 2024
In ImageEngine/cortex#1404, we added this output
to get un-normalized depth values for greater accuracy, so it is
needed by the `StandardStyle` fragment shader as well.
ericmehl added a commit to ericmehl/gaffer that referenced this pull request Feb 19, 2024
In ImageEngine/cortex#1404, we added this output
to get un-normalized depth values for greater accuracy, so it is
needed by the `StandardStyle` fragment shader as well.
ericmehl added a commit to ericmehl/gaffer that referenced this pull request Feb 21, 2024
In ImageEngine/cortex#1404, we added this output
to get un-normalized depth values for greater accuracy, so it is
needed by the `StandardStyle` fragment shader as well.
ericmehl added a commit to ericmehl/gaffer that referenced this pull request Feb 23, 2024
In ImageEngine/cortex#1404, we added this output
to get un-normalized depth values for greater accuracy, so it is
needed by the `StandardStyle` fragment shader as well.
ericmehl added a commit to ericmehl/gaffer that referenced this pull request Feb 23, 2024
In ImageEngine/cortex#1404, we added this output
to get un-normalized depth values for greater accuracy, so it is
needed by the `StandardStyle` fragment shader as well.
ericmehl added a commit to ericmehl/gaffer that referenced this pull request Feb 29, 2024
In ImageEngine/cortex#1404, we added this output
to get un-normalized depth values for greater accuracy, so it is
needed by the `StandardStyle` fragment shader as well.
ericmehl added a commit to ericmehl/gaffer that referenced this pull request Mar 4, 2024
In ImageEngine/cortex#1404, we added this output
to get un-normalized depth values for greater accuracy, so it is
needed by the `StandardStyle` fragment shader as well.
ericmehl added a commit to ericmehl/gaffer that referenced this pull request Mar 5, 2024
In ImageEngine/cortex#1404, we added this output
to get un-normalized depth values for greater accuracy, so it is
needed by the `StandardStyle` fragment shader as well.
ericmehl added a commit to ericmehl/gaffer that referenced this pull request Mar 5, 2024
In ImageEngine/cortex#1404, we added this output
to get un-normalized depth values for greater accuracy, so it is
needed by the `StandardStyle` fragment shader as well.
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