Help me understand Baked Volumetric Fog

I came across this repository and I was very interested as it claims to provide lightweight and inexpensive volumetric fog rendering for VR and Mobile in Unity.

It does this by computing the fog values offline and storing it inside a 3D texture to be sampled at runtime.

It looks like an amazing package, but one of the noted drawbacks is.

“High-resolution 3D textures can eat up VRAM and disk space easily, so to keep it small they have to be low resolution which isn’t good for crisp shadows.”

I’m just thinking if there’s anyway to ‘compress’ a 3D texture, or instead of storing values in a voxel grid they can be stored in an octree so large areas of uniform fog density, color and luminosity are not repeated in memory?

[Header(Raymarching)]
_RaymarchStepSize("Raymarch Step Size", Float) = 25

[Header(Rendering)]
[Toggle(_HALF_RESOLUTION)] _HalfResolution("Half Resolution", Float) = 0
[Toggle(_ANIMATED_NOISE)] _EnableAnimatedJitter("Animated Noise", Float) = 0
[Toggle(_KILL_RAYS_EXITING_VOLUME)] _StopRaysExitingVolume("Kill Rays Exiting Volume", Float) = 1
_JitterTexture("Jitter Texture", 2D) = "white" {}
_RaymarchJitterStrength("Raymarch Jitter", Float) = 2

I always thought ray marching was an expensive shader to run? Or is that only when you’re using it for real time lighting calculations?

Just based on some very rough tests It seems to add 1-2ms per frame, which is pretty great.

It works great on PC but Ray marching kills mobile, I can tell you that. Also this shader doesn’t smooth edge at composition so you can’t use half res and need a high slice number. It’s as brute force as brute force get. Or as they say, room for optimization :wink:

In my quick test, integrating it with the 3d texture produced by Bakery volumes, VRAM isn’t the issue. You get 70MB on a large level with zero staircasing. Graph kill GPU for sport. You want Bakery’s volume compression instead, which uses an extra 3D texture as compression mask instead of a graph.

1 Like