From 091e4343dc352e7c372fb3b7c38c64d257c3a547 Mon Sep 17 00:00:00 2001 From: Samuel Pantze <83579186+smlpt@users.noreply.github.com> Date: Fri, 19 Apr 2024 17:10:31 +0200 Subject: [PATCH 1/7] merge the AO calculation of Volume.frag into the current BDVVolume.frag --- .../volumes/AccumulateSimpleVolume.frag | 31 ++++++++++++- .../graphics/scenery/volumes/BDVVolume.frag | 46 ++++++++++++++++--- .../scenery/volumes/SampleSimpleVolume.frag | 7 ++- 3 files changed, 72 insertions(+), 12 deletions(-) diff --git a/src/main/resources/graphics/scenery/volumes/AccumulateSimpleVolume.frag b/src/main/resources/graphics/scenery/volumes/AccumulateSimpleVolume.frag index e622d6098..c01e0b383 100644 --- a/src/main/resources/graphics/scenery/volumes/AccumulateSimpleVolume.frag +++ b/src/main/resources/graphics/scenery/volumes/AccumulateSimpleVolume.frag @@ -2,10 +2,13 @@ // volume uniforms there is wonky and doing them here in a shader segment works better uniform int sceneGraphVisibility; + + vis = vis && bool(sceneGraphVisibility); if (vis && step > localNear && step < localFar) { - vec4 x = sampleVolume(wpos); +// foo = vec3(0.7, 0.7, 0.3); + vec4 x = sampleVolume(wpos, vec3(0.0)); float newAlpha = x.a; vec3 newColor = x.rgb; @@ -15,6 +18,32 @@ if (vis && step > localNear && step < localFar) v.rgb = v.rgb + (1.0f - v.a) * newColor * adjusted_alpha; v.a = v.a + (1.0f - v.a) * adjusted_alpha; + + if(x.a > 0.01f && occlusionSteps > 0 && !isHit) { + // [[unroll]] + for(int s = 0; s < occlusionSteps; s++) { + vec3 lpos = wpos.rgb + vec3(poisson16[s], (poisson16[s].x + poisson16[s].y)/2.0) * kernelSize; + float d = x.a; + float d0 = sampleVolume(wpos, vec3(kernelSize, 0.0, 0.0)).a; + float d1 = sampleVolume(wpos, vec3(0.0, kernelSize, 0.0)).a; + float d2 = sampleVolume(wpos, vec3(0.0, 0.0, kernelSize)).a; +// foo = vec3(0.3, 0.9, 0.5); + vec3 gradient = vec3(d - d0, d - d1, d - d2); + vec3 N = normalize(gradient); + vec3 sampleDir = normalize(direc.rgb); + float NdotS = max(dot(N, sampleDir), 0.0); + foo = vec3(NdotS); + float dist = distance(wpos.rgb, lpos); + float a = smoothstep(maxOcclusionDistance, maxOcclusionDistance*2.0, dist); + shadowDist += a * NdotS/occlusionSteps; + } + + + shadowing = clamp(shadowDist, 0.0, 1.0); + isHit = true; + } + + if(v.a >= 1.0f) { break; } diff --git a/src/main/resources/graphics/scenery/volumes/BDVVolume.frag b/src/main/resources/graphics/scenery/volumes/BDVVolume.frag index 68846925d..579898bfd 100644 --- a/src/main/resources/graphics/scenery/volumes/BDVVolume.frag +++ b/src/main/resources/graphics/scenery/volumes/BDVVolume.frag @@ -1,12 +1,14 @@ #extension GL_EXT_control_flow_attributes : enable #extension GL_EXT_debug_printf : enable #extension SPV_KHR_non_semantic_info : enable +#extension GL_EXT_control_flow_attributes: enable + out vec4 FragColor; uniform vec2 viewportSize; uniform float shuffleDegree; -uniform float maxOcclusionDistance; -uniform float kernelSize; -uniform int occlusionSteps; +//uniform float maxOcclusionDistance; +//uniform float kernelSize; +//uniform int occlusionSteps; uniform int aoDebug; uniform vec2 dsp; uniform float fwnw; @@ -102,6 +104,25 @@ vec3 randomSpherePoint(vec3 rand) { // $insert{SampleVolume} // --------------------- +const vec2 poisson16[] = vec2[]( +vec2( -0.94201624, -0.39906216 ), +vec2( 0.94558609, -0.76890725 ), +vec2( -0.094184101, -0.92938870 ), +vec2( 0.34495938, 0.29387760 ), +vec2( -0.91588581, 0.45771432 ), +vec2( -0.81544232, -0.87912464 ), +vec2( -0.38277543, 0.27676845 ), +vec2( 0.97484398, 0.75648379 ), +vec2( 0.44323325, -0.97511554 ), +vec2( 0.53742981, -0.47373420 ), +vec2( -0.26496911, -0.41893023 ), +vec2( 0.79197514, 0.19090188 ), +vec2( -0.24188840, 0.99706507 ), +vec2( -0.81409955, 0.91437590 ), +vec2( 0.19984126, 0.78641367 ), +vec2( 0.14383161, -0.14100790 ) +); + void main() { mat4 ipv = Vertex.inverseView * Vertex.inverseProjection; @@ -119,7 +140,7 @@ void main() vec2 depthUV = (vrParameters.stereoEnabled ^ 1) * Vertex.textureCoord + vrParameters.stereoEnabled * vec2((Vertex.textureCoord.x/2.0 + currentEye.eye * 0.5), Vertex.textureCoord.y); depthUV = depthUV * 2.0 - vec2(1.0); - + // NDC of frag on near and far plane vec4 front = vec4( uv, -1, 1 ); vec4 back = vec4( uv, 1, 1 ); @@ -130,6 +151,9 @@ void main() vec4 wback = ipv * back; wback *= 1 / wback.w; + vec4 direc = Vertex.inverseView * normalize(wback-wfront); + direc.w = 0.0f; + // -- bounding box intersection for all volumes ---------- float tnear = 1, tfar = 0, tmax = getMaxDepth( depthUV ); float n, f; @@ -183,10 +207,18 @@ void main() float standardStepSize = distance(mix(wfront, wback, step + nw), w_entry); + int occlusionSteps = 6; + float kernelSize = 3.0; + float maxOcclusionDistance = 1.0; + float step_prev = step - stepWidth; vec4 wprev = mix(wfront, wback, step_prev); vec4 v = vec4( 0 ); + float shadowDist = 0.0f; + float shadowing = 0.0f; vec4 previous = vec4(0.0f); + bool isHit = false; + vec3 foo = vec3(0.9, 0.3, 0.2); for ( int i = 0; i < numSteps; ++i) { vec4 wpos = mix( wfront, wback, step ); @@ -203,15 +235,15 @@ void main() */ wprev = wpos; + if(fixedStepSize) { step += stepWidth * (1.0f+shuffleDegree*shuffle.x/2.0f); } else { step += nw + step * fwnw * (1.0f+shuffleDegree*shuffle.x/2.0f); } } - FragColor = v; - - + FragColor = vec4(foo, 1); +// FragColor = v; if(v.w < 0.001f) { discard; } diff --git a/src/main/resources/graphics/scenery/volumes/SampleSimpleVolume.frag b/src/main/resources/graphics/scenery/volumes/SampleSimpleVolume.frag index 2da2b8103..85ce8e22d 100644 --- a/src/main/resources/graphics/scenery/volumes/SampleSimpleVolume.frag +++ b/src/main/resources/graphics/scenery/volumes/SampleSimpleVolume.frag @@ -15,7 +15,7 @@ uniform sampler3D volume; uniform sampler2D transferFunction; uniform sampler2D colorMap; -vec4 sampleVolume( vec4 wpos ) +vec4 sampleVolume( vec4 wpos, vec3 kernelOffset ) { bool cropping = slicingMode == 1 || slicingMode == 3; bool slicing = slicingMode == 2 || slicingMode == 3; @@ -28,7 +28,7 @@ vec4 sampleVolume( vec4 wpos ) float dv = slicingPlane.x * wpos.x + slicingPlane.y * wpos.y + slicingPlane.z * wpos.z; // compare position to slicing plane - // negative w inverts the comparision + // negative w inverts the comparison isCropped = isCropped || (slicingPlane.w >= 0 && dv > slicingPlane.w) || (slicingPlane.w < 0 && dv < abs(slicingPlane.w)); float dist = abs(dv - abs(slicingPlane.w)) / length(slicingPlane.xyz); @@ -41,10 +41,9 @@ vec4 sampleVolume( vec4 wpos ) return vec4(0); } - vec3 pos = (im * wpos).xyz + 0.5; - float rawsample = convert(texture( volume, pos / textureSize( volume, 0 ) ).r); + float rawsample = convert(texture( volume, pos / textureSize( volume, 0 ) + kernelOffset / textureSize(volume, 0) ).r); float tf = texture(transferFunction, vec2(rawsample + 0.001f, 0.5f)).r; vec3 cmapplied = texture(colorMap, vec2(rawsample + 0.001f, 0.5f)).rgb; From a51cc5cfb39c78935b1448685e56852028fcff4f Mon Sep 17 00:00:00 2001 From: Samuel Pantze <83579186+smlpt@users.noreply.github.com> Date: Fri, 19 Apr 2024 22:14:51 +0200 Subject: [PATCH 2/7] BDVVolume: fix view normals for proper light falloff --- .../volumes/AccumulateSimpleVolume.frag | 41 +++++++++---------- .../graphics/scenery/volumes/BDVVolume.frag | 12 +++--- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/main/resources/graphics/scenery/volumes/AccumulateSimpleVolume.frag b/src/main/resources/graphics/scenery/volumes/AccumulateSimpleVolume.frag index c01e0b383..3feaa5671 100644 --- a/src/main/resources/graphics/scenery/volumes/AccumulateSimpleVolume.frag +++ b/src/main/resources/graphics/scenery/volumes/AccumulateSimpleVolume.frag @@ -2,12 +2,9 @@ // volume uniforms there is wonky and doing them here in a shader segment works better uniform int sceneGraphVisibility; - - vis = vis && bool(sceneGraphVisibility); if (vis && step > localNear && step < localFar) { -// foo = vec3(0.7, 0.7, 0.3); vec4 x = sampleVolume(wpos, vec3(0.0)); float newAlpha = x.a; @@ -19,27 +16,29 @@ if (vis && step > localNear && step < localFar) v.a = v.a + (1.0f - v.a) * adjusted_alpha; - if(x.a > 0.01f && occlusionSteps > 0 && !isHit) { - // [[unroll]] - for(int s = 0; s < occlusionSteps; s++) { - vec3 lpos = wpos.rgb + vec3(poisson16[s], (poisson16[s].x + poisson16[s].y)/2.0) * kernelSize; - float d = x.a; - float d0 = sampleVolume(wpos, vec3(kernelSize, 0.0, 0.0)).a; - float d1 = sampleVolume(wpos, vec3(0.0, kernelSize, 0.0)).a; - float d2 = sampleVolume(wpos, vec3(0.0, 0.0, kernelSize)).a; -// foo = vec3(0.3, 0.9, 0.5); - vec3 gradient = vec3(d - d0, d - d1, d - d2); - vec3 N = normalize(gradient); - vec3 sampleDir = normalize(direc.rgb); - float NdotS = max(dot(N, sampleDir), 0.0); - foo = vec3(NdotS); + if(x.a > shadowThreshold && occlusionSteps > 0 && !isHit) { + + float d = x.a; + float d0 = sampleVolume(wpos, vec3(kernelSize, 0.0, 0.0)).a; + float d1 = sampleVolume(wpos, vec3(0.0, kernelSize, 0.0)).a; + float d2 = sampleVolume(wpos, vec3(0.0, 0.0, kernelSize)).a; + vec3 gradient = vec3(d - d0, d - d1, d - d2); + vec3 N = normalize(gradient); + + vec3 viewNormal = normalize(ViewMatrices[0] * vec4(N, 0.0)).xyz; + + vec3 sampleDir = vec3(0, 0, 1); + float NdotV = max(dot(viewNormal, sampleDir), 0.0); + + [[unroll]] for(int s = 0; s < occlusionSteps; s++) { + vec3 lpos = wpos.rgb + vec3(poisson16[s], (poisson16[s].x + poisson16[s].y) / 2.0) * kernelSize; float dist = distance(wpos.rgb, lpos); - float a = smoothstep(maxOcclusionDistance, maxOcclusionDistance*2.0, dist); - shadowDist += a * NdotS/occlusionSteps; + float a = smoothstep(maxOcclusionDistance, maxOcclusionDistance * 2.0, dist); + shadowDist += a * NdotV/occlusionSteps; } + foo = viewNormal; - - shadowing = clamp(shadowDist, 0.0, 1.0); + shadowing = clamp(shadowDist, 0.3, 1.0); isHit = true; } diff --git a/src/main/resources/graphics/scenery/volumes/BDVVolume.frag b/src/main/resources/graphics/scenery/volumes/BDVVolume.frag index 579898bfd..b00511f97 100644 --- a/src/main/resources/graphics/scenery/volumes/BDVVolume.frag +++ b/src/main/resources/graphics/scenery/volumes/BDVVolume.frag @@ -6,7 +6,7 @@ out vec4 FragColor; uniform vec2 viewportSize; uniform float shuffleDegree; -//uniform float maxOcclusionDistance; +//uniform float maxOcclusionDistance; // TODO make these available again from the shader properties //uniform float kernelSize; //uniform int occlusionSteps; uniform int aoDebug; @@ -207,9 +207,10 @@ void main() float standardStepSize = distance(mix(wfront, wback, step + nw), w_entry); - int occlusionSteps = 6; - float kernelSize = 3.0; - float maxOcclusionDistance = 1.0; + int occlusionSteps = 8; + float kernelSize = 5.0; + float maxOcclusionDistance = 4.0; + float shadowThreshold = 0.01; float step_prev = step - stepWidth; vec4 wprev = mix(wfront, wback, step_prev); @@ -242,8 +243,7 @@ void main() step += nw + step * fwnw * (1.0f+shuffleDegree*shuffle.x/2.0f); } } - FragColor = vec4(foo, 1); -// FragColor = v; + FragColor = v * shadowing; if(v.w < 0.001f) { discard; } From 6f5ac6d58b2849dc83645f2524a1041850c5994a Mon Sep 17 00:00:00 2001 From: Samuel Pantze <83579186+smlpt@users.noreply.github.com> Date: Mon, 22 Apr 2024 18:48:03 +0200 Subject: [PATCH 3/7] fix view normals calculation, add overlay blend mode --- .../scenery/volumes/AccumulateSimpleVolume.frag | 6 ++---- .../graphics/scenery/volumes/BDVVolume.frag | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/resources/graphics/scenery/volumes/AccumulateSimpleVolume.frag b/src/main/resources/graphics/scenery/volumes/AccumulateSimpleVolume.frag index 3feaa5671..5cdda7143 100644 --- a/src/main/resources/graphics/scenery/volumes/AccumulateSimpleVolume.frag +++ b/src/main/resources/graphics/scenery/volumes/AccumulateSimpleVolume.frag @@ -20,13 +20,12 @@ if (vis && step > localNear && step < localFar) float d = x.a; float d0 = sampleVolume(wpos, vec3(kernelSize, 0.0, 0.0)).a; - float d1 = sampleVolume(wpos, vec3(0.0, kernelSize, 0.0)).a; + float d1 = sampleVolume(wpos, vec3(0.0, -kernelSize, 0.0)).a; float d2 = sampleVolume(wpos, vec3(0.0, 0.0, kernelSize)).a; vec3 gradient = vec3(d - d0, d - d1, d - d2); vec3 N = normalize(gradient); vec3 viewNormal = normalize(ViewMatrices[0] * vec4(N, 0.0)).xyz; - vec3 sampleDir = vec3(0, 0, 1); float NdotV = max(dot(viewNormal, sampleDir), 0.0); @@ -36,9 +35,8 @@ if (vis && step > localNear && step < localFar) float a = smoothstep(maxOcclusionDistance, maxOcclusionDistance * 2.0, dist); shadowDist += a * NdotV/occlusionSteps; } - foo = viewNormal; - shadowing = clamp(shadowDist, 0.3, 1.0); + shadowing = clamp(shadowDist, 0.0, 1.0); isHit = true; } diff --git a/src/main/resources/graphics/scenery/volumes/BDVVolume.frag b/src/main/resources/graphics/scenery/volumes/BDVVolume.frag index b00511f97..dcf209064 100644 --- a/src/main/resources/graphics/scenery/volumes/BDVVolume.frag +++ b/src/main/resources/graphics/scenery/volumes/BDVVolume.frag @@ -123,6 +123,18 @@ vec2( 0.19984126, 0.78641367 ), vec2( 0.14383161, -0.14100790 ) ); +// code from https://github.com/jamieowen/glsl-blend/blob/master/overlay.glsl +float blendOverlay(float base, float blend) { + return base<0.5?(2.0*base*blend):(1.0-2.0*(1.0-base)*(1.0-blend)); +} +vec3 blendOverlay(vec3 base, vec3 blend) { + return vec3(blendOverlay(base.r,blend.r),blendOverlay(base.g,blend.g),blendOverlay(base.b,blend.b)); +} +vec3 blendOverlay(vec3 base, vec3 blend, float opacity) { + return (blendOverlay(base, blend) * opacity + base * (1.0 - opacity)); +} + + void main() { mat4 ipv = Vertex.inverseView * Vertex.inverseProjection; @@ -243,7 +255,8 @@ void main() step += nw + step * fwnw * (1.0f+shuffleDegree*shuffle.x/2.0f); } } - FragColor = v * shadowing; +// FragColor = v * shadowing; + FragColor = vec4(blendOverlay(v.xyz, vec3(shadowing), 1.0), 1.0); if(v.w < 0.001f) { discard; } From bca7392322a3dc963a821b05b7d2f91c2240ec33 Mon Sep 17 00:00:00 2001 From: Samuel Pantze <83579186+smlpt@users.noreply.github.com> Date: Tue, 23 Apr 2024 10:08:38 +0200 Subject: [PATCH 4/7] fix black shadow artifacts --- src/main/resources/graphics/scenery/volumes/BDVVolume.frag | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/resources/graphics/scenery/volumes/BDVVolume.frag b/src/main/resources/graphics/scenery/volumes/BDVVolume.frag index dcf209064..186678925 100644 --- a/src/main/resources/graphics/scenery/volumes/BDVVolume.frag +++ b/src/main/resources/graphics/scenery/volumes/BDVVolume.frag @@ -255,8 +255,9 @@ void main() step += nw + step * fwnw * (1.0f+shuffleDegree*shuffle.x/2.0f); } } -// FragColor = v * shadowing; - FragColor = vec4(blendOverlay(v.xyz, vec3(shadowing), 1.0), 1.0); + // use shadow squared as the opacity of the final value + // to get rid of black artifacts from the shadows + FragColor = vec4(blendOverlay(v.xyz, vec3(shadowing), 1.0), shadowing * shadowing); if(v.w < 0.001f) { discard; } From 6dea52a4988e1e158e8065aced7201c5daf6f77e Mon Sep 17 00:00:00 2001 From: Samuel Pantze <83579186+smlpt@users.noreply.github.com> Date: Tue, 23 Apr 2024 11:45:02 +0200 Subject: [PATCH 5/7] temporary: debug volume manager shaderProperties --- .../graphics/scenery/volumes/VolumeManager.kt | 2 +- .../graphics/scenery/volumes/BDVVolume.frag | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/graphics/scenery/volumes/VolumeManager.kt b/src/main/kotlin/graphics/scenery/volumes/VolumeManager.kt index bd5b0cbe6..407612d62 100644 --- a/src/main/kotlin/graphics/scenery/volumes/VolumeManager.kt +++ b/src/main/kotlin/graphics/scenery/volumes/VolumeManager.kt @@ -131,7 +131,7 @@ class VolumeManager( shaderProperties["shuffleDegree"] = value } - var maxOcclusionDistance = 4.0f + var maxOcclusionDistance = 0.8f set(value) { field = value shaderProperties["maxOcclusionDistance"] = value diff --git a/src/main/resources/graphics/scenery/volumes/BDVVolume.frag b/src/main/resources/graphics/scenery/volumes/BDVVolume.frag index 186678925..98155775a 100644 --- a/src/main/resources/graphics/scenery/volumes/BDVVolume.frag +++ b/src/main/resources/graphics/scenery/volumes/BDVVolume.frag @@ -6,9 +6,9 @@ out vec4 FragColor; uniform vec2 viewportSize; uniform float shuffleDegree; -//uniform float maxOcclusionDistance; // TODO make these available again from the shader properties -//uniform float kernelSize; -//uniform int occlusionSteps; +uniform float maxOcclusionDistance; // TODO make these available again from the shader properties +uniform float kernelSize; +uniform int occlusionSteps; uniform int aoDebug; uniform vec2 dsp; uniform float fwnw; @@ -219,9 +219,9 @@ void main() float standardStepSize = distance(mix(wfront, wback, step + nw), w_entry); - int occlusionSteps = 8; - float kernelSize = 5.0; - float maxOcclusionDistance = 4.0; +// int occlusionSteps = 8; +// float kernelSize = 5.0; +// float maxOcclusionDistance = 4.0; float shadowThreshold = 0.01; float step_prev = step - stepWidth; @@ -257,7 +257,8 @@ void main() } // use shadow squared as the opacity of the final value // to get rid of black artifacts from the shadows - FragColor = vec4(blendOverlay(v.xyz, vec3(shadowing), 1.0), shadowing * shadowing); +// FragColor = vec4(blendOverlay(v.xyz, vec3(shadowing), 1.0), shadowing * shadowing); + FragColor = vec4(vec3(maxOcclusionDistance), 1.0); if(v.w < 0.001f) { discard; } From 82ceed05b0d86f9d04f2af3e06f23c184de774e9 Mon Sep 17 00:00:00 2001 From: Ulrik Guenther Date: Tue, 23 Apr 2024 12:02:28 +0200 Subject: [PATCH 6/7] VolumeManager: Initialise new shader properties correctly --- .../kotlin/graphics/scenery/volumes/VolumeManager.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/graphics/scenery/volumes/VolumeManager.kt b/src/main/kotlin/graphics/scenery/volumes/VolumeManager.kt index 407612d62..70c494f81 100644 --- a/src/main/kotlin/graphics/scenery/volumes/VolumeManager.kt +++ b/src/main/kotlin/graphics/scenery/volumes/VolumeManager.kt @@ -126,11 +126,6 @@ class VolumeManager( /** Amount of randomisation for ray start and ray steps. 0.0 turns this off, 1.0 is the default, * values larger than 1.0 might lead to noisy renderings. */ var shuffleDegree = 1.0f - set(value) { - field = value - shaderProperties["shuffleDegree"] = value - } - var maxOcclusionDistance = 0.8f set(value) { field = value @@ -213,6 +208,11 @@ class VolumeManager( shaderProperties["viewportSize"] = Vector2f() shaderProperties["dsp"] = Vector2f() shaderProperties["shuffleDegree"] = shuffleDegree + shaderProperties["maxOcclusionDistance"] = maxOcclusionDistance + shaderProperties["aoDebug"] = aoDebug + shaderProperties["kernelSize"] = kernelSize + shaderProperties["occlusionSteps"] = occlusionSteps + val oldKeys = material().textures.filter { it.key !in customTextures }.keys val texturesToKeep = material().textures.filter { it.key in customTextures } oldKeys.forEach { From 2a657f8497690be8562b036509af0909ab688792 Mon Sep 17 00:00:00 2001 From: Samuel Pantze <83579186+smlpt@users.noreply.github.com> Date: Tue, 23 Apr 2024 12:23:41 +0200 Subject: [PATCH 7/7] add: falloffBlend and falloffHitThreshold shader props to control the falloff --- .../graphics/scenery/volumes/VolumeManager.kt | 20 +++++++++++++++++-- .../volumes/AccumulateSimpleVolume.frag | 2 +- .../graphics/scenery/volumes/BDVVolume.frag | 12 ++++------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/graphics/scenery/volumes/VolumeManager.kt b/src/main/kotlin/graphics/scenery/volumes/VolumeManager.kt index 70c494f81..64f96876f 100644 --- a/src/main/kotlin/graphics/scenery/volumes/VolumeManager.kt +++ b/src/main/kotlin/graphics/scenery/volumes/VolumeManager.kt @@ -126,13 +126,13 @@ class VolumeManager( /** Amount of randomisation for ray start and ray steps. 0.0 turns this off, 1.0 is the default, * values larger than 1.0 might lead to noisy renderings. */ var shuffleDegree = 1.0f - var maxOcclusionDistance = 0.8f + var maxOcclusionDistance = 4.0f set(value) { field = value shaderProperties["maxOcclusionDistance"] = value } - var kernelSize = 8.0f + var kernelSize = 5.0f set(value) { field = value shaderProperties["kernelSize"] = value @@ -144,6 +144,20 @@ class VolumeManager( shaderProperties["occlusionSteps"] = value } + // how strongly to blend the light falloff pass over the volume. Range 0-1 + var falloffBlend = 1f + set(value) { + field = value + shaderProperties["falloffBlend"] = value + } + + // the alpha value at which to register the ray hit to calculate the light falloff gradient + var falloffHitThreshold = 0.02f + set(value) { + field = value + shaderProperties["falloffHitThreshold"] = value + } + var aoDebug = 0 set(value) { field = value @@ -212,6 +226,8 @@ class VolumeManager( shaderProperties["aoDebug"] = aoDebug shaderProperties["kernelSize"] = kernelSize shaderProperties["occlusionSteps"] = occlusionSteps + shaderProperties["falloffBlend"] = falloffBlend + shaderProperties["falloffHitThreshold"] = falloffHitThreshold val oldKeys = material().textures.filter { it.key !in customTextures }.keys val texturesToKeep = material().textures.filter { it.key in customTextures } diff --git a/src/main/resources/graphics/scenery/volumes/AccumulateSimpleVolume.frag b/src/main/resources/graphics/scenery/volumes/AccumulateSimpleVolume.frag index 5cdda7143..528aed788 100644 --- a/src/main/resources/graphics/scenery/volumes/AccumulateSimpleVolume.frag +++ b/src/main/resources/graphics/scenery/volumes/AccumulateSimpleVolume.frag @@ -16,7 +16,7 @@ if (vis && step > localNear && step < localFar) v.a = v.a + (1.0f - v.a) * adjusted_alpha; - if(x.a > shadowThreshold && occlusionSteps > 0 && !isHit) { + if(x.a > falloffHitThreshold && occlusionSteps > 0 && !isHit) { float d = x.a; float d0 = sampleVolume(wpos, vec3(kernelSize, 0.0, 0.0)).a; diff --git a/src/main/resources/graphics/scenery/volumes/BDVVolume.frag b/src/main/resources/graphics/scenery/volumes/BDVVolume.frag index 98155775a..99dbe3a8c 100644 --- a/src/main/resources/graphics/scenery/volumes/BDVVolume.frag +++ b/src/main/resources/graphics/scenery/volumes/BDVVolume.frag @@ -6,9 +6,11 @@ out vec4 FragColor; uniform vec2 viewportSize; uniform float shuffleDegree; -uniform float maxOcclusionDistance; // TODO make these available again from the shader properties +uniform float maxOcclusionDistance; uniform float kernelSize; uniform int occlusionSteps; +uniform float falloffBlend; +uniform float falloffHitThreshold; uniform int aoDebug; uniform vec2 dsp; uniform float fwnw; @@ -219,11 +221,6 @@ void main() float standardStepSize = distance(mix(wfront, wback, step + nw), w_entry); -// int occlusionSteps = 8; -// float kernelSize = 5.0; -// float maxOcclusionDistance = 4.0; - float shadowThreshold = 0.01; - float step_prev = step - stepWidth; vec4 wprev = mix(wfront, wback, step_prev); vec4 v = vec4( 0 ); @@ -257,8 +254,7 @@ void main() } // use shadow squared as the opacity of the final value // to get rid of black artifacts from the shadows -// FragColor = vec4(blendOverlay(v.xyz, vec3(shadowing), 1.0), shadowing * shadowing); - FragColor = vec4(vec3(maxOcclusionDistance), 1.0); + FragColor = vec4(blendOverlay(v.xyz, vec3(shadowing), falloffBlend), shadowing * shadowing); if(v.w < 0.001f) { discard; }