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

Add early-termination optimization to attenuated mip #2465

Merged
merged 4 commits into from
Apr 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 19 additions & 10 deletions vispy/visuals/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,13 @@
int maxi = -1; // Where the maximum value was encountered
""",
in_loop="""
if( val > maxval ) {
if ( val > maxval ) {
maxval = val;
maxi = iter;
if ( maxval >= clim.y ) {
// stop if no chance of finding a higher maxval
iter = nsteps;
}
}
""",
after_loop="""
Expand All @@ -395,8 +399,7 @@
}
frag_depth_point = max_loc_tex * u_shape;
gl_FragColor = applyColormap(maxval);
}
else {
} else {
discard;
}
""",
Expand All @@ -406,7 +409,7 @@
before_loop="""
float maxval = u_mip_cutoff; // The maximum encountered value
float sumval = 0.0; // The sum of the encountered values
float scaled = 0.0; // The scaled value
float scale = 0.0; // The cumulative attenuation
int maxi = -1; // Where the maximum value was encountered
vec3 max_loc_tex = vec3(0.0); // Location where the maximum value was encountered
""",
Expand All @@ -415,9 +418,12 @@
// * attenuation value does not depend on data values
// * negative values do not amplify instead of attenuate
sumval = sumval + clamp((val - clim.x) / (clim.y - clim.x), 0.0, 1.0);
scaled = val * exp(-u_attenuation * (sumval - 1) / u_relative_step_size);
if( scaled > maxval ) {
maxval = scaled;
scale = exp(-u_attenuation * (sumval - 1) / u_relative_step_size);
if( maxval > scale * clim.y ) {
// stop if no chance of finding a higher maxval
iter = nsteps;
} else if( val * scale > maxval ) {
maxval = val * scale;
maxi = iter;
max_loc_tex = loc;
}
Expand All @@ -439,9 +445,13 @@
int mini = -1; // Where the minimum value was encountered
""",
in_loop="""
if( val < minval ) {
if ( val < minval ) {
minval = val;
mini = iter;
if ( minval <= clim.x ) {
// stop if no chance of finding a lower minval
iter = nsteps;
}
}
""",
after_loop="""
Expand All @@ -465,8 +475,7 @@
}
frag_depth_point = min_loc_tex * u_shape;
gl_FragColor = applyColormap(minval);
}
else {
} else {
discard;
}
""",
Expand Down