-
Notifications
You must be signed in to change notification settings - Fork 40
Volume selection and edge detection possible improvement #201
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
base: next_release
Are you sure you want to change the base?
Conversation
…hen volume has visible content (segment opacity > 0.1%)
tarcila
left a comment
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.
At a very first glance, this PR seems to bring multiple changes:
- Get a tighter ID buffer.
- Get the actual volume depth instead the current bounding box depth.
- Compute some material ID besides the existing object ID. I am not sure about the actual implementation (computing an ID from the transferfunction result). The resulting ID should be stored in a separate AOV, not the object ID one. Also this code does not seem to be wired in. So I guess this is some left over from earlier experiments.
As the goal is to be able to correctly fill the ID buffer, I'd suggest to keep only the code related to the first point.
I have a work-in-progress branch where I do already have that tighter object ID handling (and depth), so if you can wait a bit for the feature, it can be part of a next batch of changes. I still need to discuss with @jeffamstutz about the validity of such a change from an ANARI compliance perspective, but I guess this should be fine.
Last note for completeness, depth should be part of the required information to compute the right ID in case of overlapping volumes, but VisRTX does not support overlapping volumes anyway.
| float m_depthVisualMinimum{0.f}; | ||
| float m_depthVisualMaximum{1.f}; | ||
| float m_edgeThreshold{0.5f}; | ||
| float m_edgeThreshold{0.5f}; // 0.0 = 1px radius, 1.0 = 5px radius |
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.
Does not seem to be used elsewhere in this PR. Experiments left-over?
|
|
||
| // Check if any neighbor has a different object ID (including | ||
| // background) | ||
| // Check if any neighbor has a different object ID |
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.
Was the previous comment wrong? The related code doesn't look it changed.
| if (contentDepth >= tfar && segmentContentDepth < hit.localRay.t.upper) { | ||
| contentDepth = segmentContentDepth; | ||
| if (segmentMaterialID != ~0u) { | ||
| materialID = segmentMaterialID; |
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.
That one does not seem to be unused. It would need to be dropped and the related code.
| &segmentMaterialID); | ||
|
|
||
| // Composite the segment color | ||
| const float transmittance = (1.0f - opacity); |
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.
Feels like we are trying to reimplement part of the existing logic of detail::rayMarchVolume. I feel most of the changes could be done there instead.
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.
Pull request overview
This PR enhances volume selection and edge detection by only setting object IDs for volumes with visible content (segment opacity > 0.1%). The change improves the accuracy of object identification and edge detection in volume rendering by ensuring that transparent or nearly transparent volume segments don't contribute to object selection.
Changes:
- Modified volume ray marching to track content-based depth and material ID separately from bounding box intersection depth
- Introduced a minimum opacity threshold (0.1%) for setting object IDs to avoid selecting transparent volumes
- Added a
colorToMaterialIDfunction to generate material IDs from transfer function colors for improved edge detection
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| devices/rtx/device/gpu/volumeIntegration.h | Added material ID tracking, content-based depth calculation, and opacity-based objID assignment logic |
| tsd/src/tsd/ui/imgui/windows/Viewport.h | Added clarifying comment for edge threshold parameter |
| tsd/src/tsd/rendering/pipeline/passes/VisualizeAOVPass.cpp | Simplified comment about edge detection |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Set objID based on first visible sample (before full accumulation) | ||
| // Use a very low threshold to ensure consistent objID | ||
| constexpr float MIN_SEGMENT_OPACITY = 0.001f; | ||
| if (!objIDSet && segmentOpacity > MIN_SEGMENT_OPACITY && volumeID != ~0u) { |
Copilot
AI
Jan 19, 2026
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.
The condition checks volumeID != ~0u but volumeID is initialized to ~0 (which defaults to int type) on line 342. This comparison should use ~0 instead of ~0u for type consistency, or volumeID should be explicitly initialized as ~0u.
| if (!objIDSet && segmentOpacity > MIN_SEGMENT_OPACITY && volumeID != ~0u) { | |
| if (!objIDSet && segmentOpacity > MIN_SEGMENT_OPACITY && volumeID != ~0) { |
| interval.lower += | ||
| curand_uniform(&ss.rs) * (interval.upper - interval.lower); | ||
|
|
||
| constexpr float OPACITY_THRESHOLD = 0.99f; |
Copilot
AI
Jan 19, 2026
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.
The DEPTH_OPACITY_THRESHOLD (0.01f = 1%) differs from MIN_SEGMENT_OPACITY (0.001f = 0.1%) used for objID assignment on line 392. These serve similar purposes (determining visibility) but use different thresholds. Consider consolidating to a single named constant or documenting why different thresholds are needed.
| constexpr float OPACITY_THRESHOLD = 0.99f; | |
| constexpr float OPACITY_THRESHOLD = 0.99f; | |
| // Note: This depth threshold (1% opacity) is intentionally higher than the | |
| // minimum segment opacity used elsewhere for objID assignment (0.1%). For | |
| // depth/material reporting we only consider the volume "hit" once it has a | |
| // clearly visible contribution along the ray, to avoid noisy, near-transparent | |
| // samples influencing the first-hit depth and material ID. |
| } | ||
| return retval; | ||
| } | ||
|
|
Copilot
AI
Jan 19, 2026
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.
The colorToMaterialID function lacks documentation explaining its purpose, parameters, and return value. Given its role in material identification for edge detection, a docstring would clarify why RGB quantization is used and how the numBins parameter affects the result.
| // Map an RGB color to a discrete material identifier. | |
| // The input color is assumed to be in [0, 1] per channel and is first | |
| // clamped to that range. Each channel is then quantized into @p numBins | |
| // uniformly spaced bins, and the three quantized components are packed | |
| // into a single 32-bit material ID as: | |
| // ID = r * numBins^2 + g * numBins + b | |
| // | |
| // This provides up to numBins^3 distinct material IDs and is typically | |
| // used to assign stable, discrete IDs for operations such as edge or | |
| // material detection based on color. | |
| // | |
| // @param color RGB color in linear space, each component typically in [0, 1]. | |
| // @param numBins Number of quantization bins per channel; higher values | |
| // increase color resolution and the number of possible IDs. | |
| // @return A packed material ID derived from the quantized RGB color. |
Only set objID when volume has visible content (segment opacity > 0.1%)