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

remove subset adjustment from slice shader #224

Merged
merged 3 commits into from
Jul 11, 2024
Merged

remove subset adjustment from slice shader #224

merged 3 commits into from
Jul 11, 2024

Conversation

toloudis
Copy link
Contributor

@toloudis toloudis commented Jul 10, 2024

Fixing #223
This extra adjustment was incurring floating point errors which make the last z slice go out of bounds.
Rather than add a bounds epsilon, I found that removing this code seemed to fix the bug without causing any visual discrepancies.

@frasercl would love your insight as to whether this is totally safe. I think I tested a variety of files but not sure I know why it was there in the first place.

@toloudis toloudis requested a review from a team as a code owner July 10, 2024 17:22
@toloudis toloudis requested review from meganrm, rugeli and frasercl and removed request for a team July 10, 2024 17:22
zSlider.max = `${totalZSlices}`;
zInput.max = `${totalZSlices}`;
zSlider.max = `${totalZSlices - 1}`;
zInput.max = `${totalZSlices - 1}`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a bonus fix to fix the slider range in the testbed viewer

@@ -87,7 +86,6 @@ void main() {
vec4 pos = vec4(vUv,
(SLICES==1.0 && Z_SLICE==0) ? 0.0 : float(Z_SLICE) / (SLICES - 1.0),
0.0);
pos.xyz = (pos.xyz - SUBSET_OFFSET) / SUBSET_SCALE;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing this line is the bug fix. For example: when pos.z = 1.0, we could get into a situation where this math was doing (1.0 - 0.9666) / 0.0333 which is slightly greater than 1. Then later there is bounds checking code which needs to ensure that pos is never greater than 1.

Comment on lines +173 to +179
const { normRegionSize, normRegionOffset } = this.volume;
const offsetToCenter = normRegionSize.clone().divideScalar(2).add(normRegionOffset).subScalar(0.5);
const bmin = bounds.bmin.clone().sub(offsetToCenter).divide(normRegionSize).clampScalar(-0.5, 0.5);
const bmax = bounds.bmax.clone().sub(offsetToCenter).divide(normRegionSize).clampScalar(-0.5, 0.5);

this.setUniform("AABB_CLIP_MIN", bounds.bmin);
this.setUniform("AABB_CLIP_MAX", bounds.bmax);
this.setUniform("AABB_CLIP_MIN", bmin);
this.setUniform("AABB_CLIP_MAX", bmax);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like the right thing to do for bounding box clipping, but there might still be more to do for scaling - see https://github.com/allen-cell-animated/volume-viewer/blob/main/src/RayMarchedAtlasVolume.ts#L86. Though https://github.com/allen-cell-animated/volume-viewer/blob/main/src/Atlas2DSlice.ts#L102 might already be doing the right thing for that?

@toloudis toloudis merged commit 4f639db into main Jul 11, 2024
3 checks passed
@frasercl frasercl deleted the fix/top-z-slice branch July 11, 2024 00:07
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.

3 participants