Feat: option to hide cross section background in 3D slice views #45
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a new global setting to optionally hide the background of 3D cross-sections in Neuroglancer. When activated, this setting allows users to view 3D slice projections without the background color, offering a less obstructed view of the data while still keeping the slice views in 3D on. Open to thoughts and suggestions on the functionality and implementation!
Default (background visible):
New Option (background hidden):
Motivation
When displaying slice views in 3D, the background of 2D cross-sections can sometimes appear prominently, especially when the user is zoomed out. This view can be useful but may also limit visibility of the 3D content itself. This feature provides the flexibility to hide the background in 3D, to improve visibility without turning off the section rendering completely. 2D cross-section views remain unaffected.
User interaction
In neuroglancer, this setting is available in the same panel where users toggle 3D view sections. It can also be enabled or disabled with the global "t" keybind (representing "Transparent"), selected to avoid overlap with existing shortcuts. Very open to suggestions on the keybind.
Implementation
The primary change is to the
SliceViewRenderHelper
class, and specifically the constructor and shader. The shader becomes a context and parameter dependent shader instead of a fixed shader. This allows the shader to change based on whether the user controlled setting is toggled on or off (the parameter to the memoized shader getter), and whether the render helper is for a cross-section view or projection view (the context).When the hide setting is on, and the rendering is for a projection view, if the alpha of the sampled cross-section texture is 0 in the fragment shader, instead of picking up the background color, the fragment is discarded.
Oblique slicing example
For clarity, here is an example with oblique slicing and a red projection background to illustrate the effects of this new setting.