Skip to content

Conversation

@favreau
Copy link
Collaborator

@favreau favreau commented Jan 19, 2026

Only set objID when volume has visible content (segment opacity > 0.1%)

…hen volume has visible content (segment opacity > 0.1%)
@favreau favreau requested a review from jeffamstutz January 19, 2026 16:37
@tarcila tarcila self-requested a review January 19, 2026 20:37
Copy link
Collaborator

@tarcila tarcila left a 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
Copy link
Collaborator

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
Copy link
Collaborator

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;
Copy link
Collaborator

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

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.

@tarcila tarcila requested a review from Copilot January 19, 2026 21:15
Copy link
Contributor

Copilot AI left a 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 colorToMaterialID function 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) {
Copy link

Copilot AI Jan 19, 2026

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.

Suggested change
if (!objIDSet && segmentOpacity > MIN_SEGMENT_OPACITY && volumeID != ~0u) {
if (!objIDSet && segmentOpacity > MIN_SEGMENT_OPACITY && volumeID != ~0) {

Copilot uses AI. Check for mistakes.
interval.lower +=
curand_uniform(&ss.rs) * (interval.upper - interval.lower);

constexpr float OPACITY_THRESHOLD = 0.99f;
Copy link

Copilot AI Jan 19, 2026

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.

Suggested change
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.

Copilot uses AI. Check for mistakes.
}
return retval;
}

Copy link

Copilot AI Jan 19, 2026

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.

Suggested change
// 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.

Copilot uses AI. Check for mistakes.
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