diff --git a/data/base/shaders/vk/pointlights.glsl b/data/base/shaders/vk/pointlights.glsl index 87635f75b7c..929a9478e75 100644 --- a/data/base/shaders/vk/pointlights.glsl +++ b/data/base/shaders/vk/pointlights.glsl @@ -74,11 +74,12 @@ vec4 iterateOverAllPointLights( return light; } -//volumetric -vec4 volumetricIterateOverAllPointLights( +// based on equations found here : https://www.shadertoy.com/view/lstfR7 +vec4 volumetricLights( vec2 clipSpaceCoord, vec3 cameraPosition, - vec3 WorldFragPos + vec3 WorldFragPos, + vec3 sunLightColor ) { vec3 result = vec3(0); ivec2 bucket = ivec2(WZ_BUCKET_DIMENSION * clipSpaceCoord); @@ -93,12 +94,15 @@ vec4 volumetricIterateOverAllPointLights( #define STEPS 64 for (int i = 0; i < STEPS; i++) { - vec3 od = fogColor.xyz * length(viewLine / STEPS) / 10000; + vec3 posOnViewLine = WorldFragPos + viewLine * i / STEPS; + // fog is thicker near 0 + float thickness = exp(-posOnViewLine.y / 300); + vec3 od = fogColor.xyz * thickness * length(viewLine / STEPS) / 1000; - float sunLightEnergy = getShadowVisibility(posOnViewLine); - vec3 scatteredLight = vec3(sunLightEnergy) * od; + float sunLightEnergy = getShadowVisibility(posOnViewLine) ; + vec3 scatteredLight = vec3(sunLightEnergy) * sunLightColor * od; for (int i = 0; i < bucketOffsetAndSize[bucketId].y; i++) { diff --git a/data/base/shaders/vk/tcmask_instanced.frag b/data/base/shaders/vk/tcmask_instanced.frag index 02397444573..ea32a171e2e 100644 --- a/data/base/shaders/vk/tcmask_instanced.frag +++ b/data/base/shaders/vk/tcmask_instanced.frag @@ -375,7 +375,7 @@ void main() #if 1 vec2 clipSpaceCoord = gl_FragCoord.xy / vec2(viewportWidth, viewportHeight); - vec4 volumetric = volumetricIterateOverAllPointLights(clipSpaceCoord, cameraPos.xyz, fragPos); + vec4 volumetric = volumetricLights(clipSpaceCoord, cameraPos.xyz, fragPos, diffuse.xyz); fragColour.xyz = toneMap(fragColour.xyz * volumetric.a + volumetric.xyz); #else if (fogEnabled > 0) diff --git a/data/base/shaders/vk/terrain_combined_high.frag b/data/base/shaders/vk/terrain_combined_high.frag index fca0ac85354..7879cfd3b41 100644 --- a/data/base/shaders/vk/terrain_combined_high.frag +++ b/data/base/shaders/vk/terrain_combined_high.frag @@ -128,7 +128,7 @@ void main() #if 1 vec2 clipSpaceCoord = gl_FragCoord.xy / vec2(viewportWidth, viewportHeight); - vec4 volumetric = volumetricIterateOverAllPointLights(clipSpaceCoord, cameraPos.xyz, frag.fragPos); + vec4 volumetric = volumetricLights(clipSpaceCoord, cameraPos.xyz, frag.fragPos, diffuseLight.xyz); fragColor.xyz = toneMap(fragColor.xyz * volumetric.a + volumetric.xyz); #else if (fogEnabled > 0)