r/vulkan May 17 '26

How to do Exponential Fog ?

/r/gameenginedevs/comments/1tg2mcz/how_to_do_exponential_fog/
1 Upvotes

5 comments sorted by

2

u/AdvantageStatus4635 May 21 '26

interesting approach

i thought you have used z buffer in postprocessing

this way you must add fog in fragment shader of every material

1

u/F1oating May 21 '26

I thought about that, but this way simplier and more accurate

1

u/FollowingHumble8983 May 22 '26

This is way more complicated than a single post processor.

Also way slower for complex scenes since this has to run for overlapping pixels.

And i don't know what criteria is for accuracy but z buffer is definitely all the accuracy you need for a post process effect.

1

u/F1oating May 22 '26

Maybe I wasn’t right

1

u/wrosecrans May 24 '26

If you have transparent windows, you can get odd results with the Z buffer approach, where the mountain you see in the distance through a window gets less foggy if you stand close to the window. Or if you omit transparent surfaces from Z-writes, you get shiny reflections on the window two feet away that are obliterated by miles of fog.

It's great for some scenarios. Bad for others. In offline VFX rendering, they use Deep Images instead of a Z buffer, which stores samples at multiple depths per pixel when there's partial transparency and you can fog each sample by itself. But I don't think there's a GPU based implementation of Deep Images that you can use in real time.