Skip to content

Commit

Permalink
VolumeManager, AccumulateBlockVolume.frag, AccumulateSimpleVolume.fra…
Browse files Browse the repository at this point in the history
…g: Respect Volume visibilty of the volume node.

Add sceneGraphVisibility per volume shader uniform. Should solve scenerygraphics/sciview#422
  • Loading branch information
moreApi committed Jun 13, 2023
1 parent 63edcca commit 62715f9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/main/kotlin/graphics/scenery/volumes/VolumeManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import java.nio.IntBuffer
import java.util.*
import java.util.concurrent.CopyOnWriteArrayList
import java.util.concurrent.ForkJoinPool
import java.util.function.BiConsumer
import kotlin.math.max
import kotlin.math.min
import kotlin.system.measureTimeMillis
Expand Down Expand Up @@ -287,34 +286,39 @@ class VolumeManager(
"convert",
"slicingPlanes",
"slicingMode",
"usedSlicingPlanes"
"usedSlicingPlanes",

Check warning on line 289 in src/main/kotlin/graphics/scenery/volumes/VolumeManager.kt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/main/kotlin/graphics/scenery/volumes/VolumeManager.kt#L289

Multiple occurrences of the same string literal within a single file detected.
"sceneGraphVisibility"
)
segments[SegmentType.SampleVolume] = SegmentTemplate(
"SampleSimpleVolume.frag",
"im", "sourcemax", "intersectBoundingBox",
"volume", "transferFunction", "colorMap", "sampleVolume", "convert", "slicingPlanes",
"slicingMode", "usedSlicingPlanes"
"slicingMode", "usedSlicingPlanes",
"sceneGraphVisibility"
)
segments[SegmentType.Convert] = SegmentTemplate(
"Converter.frag",
"convert", "offset", "scale"
)
segments[SegmentType.AccumulatorMultiresolution] = SegmentTemplate(
"AccumulateBlockVolume.frag",
"vis", "sampleVolume", "convert"
"vis", "sampleVolume", "convert", "sceneGraphVisibility"
)
segments[SegmentType.Accumulator] = SegmentTemplate(
"AccumulateSimpleVolume.frag",
"vis", "sampleVolume", "convert"
"vis", "sampleVolume", "convert", "sceneGraphVisibility"
)

customSegments?.forEach { type, segment -> segments[type] = segment }

val additionalBindings = customBindings
?: TriConsumer { _: Map<SegmentType, SegmentTemplate>, instances: Map<SegmentType, Segment>, _: Int ->
?: TriConsumer { _: Map<SegmentType, SegmentTemplate>, instances: Map<SegmentType, Segment>, i: Int ->
logger.debug("Connecting additional bindings")

instances[SegmentType.SampleMultiresolutionVolume]?.bind("convert", instances[SegmentType.Convert])
instances[SegmentType.SampleVolume]?.bind("convert", instances[SegmentType.Convert])
instances[SegmentType.SampleVolume]?.bind("sceneGraphVisibility", instances[SegmentType.Accumulator])
instances[SegmentType.SampleMultiresolutionVolume]?.bind("sceneGraphVisibility", instances[SegmentType.AccumulatorMultiresolution])
}

val newProgvol = MultiVolumeShaderMip(
Expand Down Expand Up @@ -465,6 +469,7 @@ class VolumeManager(
currentProg.setCustomUniformForVolume(i, "slicingMode", state.node.slicingMode.id)
currentProg.setCustomUniformForVolume(i,"usedSlicingPlanes",
min(state.node.slicingPlaneEquations.size, Volume.MAX_SUPPORTED_SLICING_PLANES))
currentProg.setCustomUniformForVolume(i, "sceneGraphVisibility", if (state.node.visible) 1 else 0)

context.bindTexture(state.transferFunction)
context.bindTexture(state.colorMap)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// sceneGraphVisibility should be in main BDVVolume.frag but doing per
// volume uniforms there is wonky and doing them here in a shader segment works better
uniform int sceneGraphVisibility;

vis = vis && bool(sceneGraphVisibility);
if (vis)
{
vec4 x = sampleVolume(wpos, volumeCache, cacheSize, blockSize, paddedBlockSize, cachePadOffset);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// sceneGraphVisibility should be in main BDVVolume.frag but doing per
// volume uniforms there is wonky and doing them here in a shader segment works better
uniform int sceneGraphVisibility;

vis = vis && bool(sceneGraphVisibility);
if (vis)
{
vec4 x = sampleVolume(wpos);
Expand Down

0 comments on commit 62715f9

Please sign in to comment.