From 0cbb4c29262a9ba6a1615ce3ad29b2e4ff713eea Mon Sep 17 00:00:00 2001 From: Alexander Gauggel <agauggel@uni-koblenz.de> Date: Fri, 25 Jun 2021 18:20:05 +0200 Subject: [PATCH] [#82] Reduce volumetric sample count to increase performance, add additional noise to hide artifacts --- projects/voxelization/resources/shaders/shader.frag | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/projects/voxelization/resources/shaders/shader.frag b/projects/voxelization/resources/shaders/shader.frag index 7612025a..b5d1ccf6 100644 --- a/projects/voxelization/resources/shaders/shader.frag +++ b/projects/voxelization/resources/shaders/shader.frag @@ -82,19 +82,22 @@ float isotropicPhase(){ vec3 volumetricLighting(vec3 colorIn, vec3 V, vec3 pos, float d){ vec3 color = colorIn; - int sampleCount = 48; + int sampleCount = 20; float stepSize = d / sampleCount; vec3 extinctionCoefficient = scatteringCoefficient + absorptionCoefficient; - float noiseScale = 0.1; + float noise = 2 * pi * interleavedGradientNoise(gl_FragCoord.xy); + vec2 shadowOffset = 3.f * vec2(sin(noise), cos(noise)) / textureSize(sampler2D(shadowMap, shadowMapSampler), 0); + + float noiseScale = 0.1f; pos += V * noiseScale * interleavedGradientNoise(gl_FragCoord.xy); for(int i = 0; i < sampleCount; i++){ vec3 samplePoint = pos + V * i * stepSize; float phase = isotropicPhase(); vec3 light = lightInfo.sunColor * lightInfo.sunStrength; - float shadow = shadowTest(samplePoint, lightInfo, shadowMap, shadowMapSampler, vec2(0)); + float shadow = shadowTest(samplePoint, lightInfo, shadowMap, shadowMapSampler, shadowOffset); light *= shadow; light += volumetricAmbientLight; -- GitLab