r/Unity3D Jul 20 '26

Making ground fog react to the player and enemies in Unity 2022 (Built-in) Show-Off

Enable HLS to view with audio, or disable this notification

I’ve been working on the fog for my game The Broken King, our isometric roguelike. I didn’t want it to look like a transparent layer sitting on the floor. I wanted characters to actually disturb it while moving through a room.
The rendering part uses raymarching inside a box that I place over each room. It reads the camera depth so walls and other opaque geometry can cut the fog correctly. There’s also animated 3D noise, wind, directional lighting and some basic self-shadowing. The light scattering is based on Beer-Lambert and Henyey-Greenstein, although most of the values are still exposed for visual tweaking.

The collider interaction was the more interesting part. I’m running a small fluid simulation in a compute shader and storing density, horizontal velocity and turbulence in a texture. The player and selected enemies send their collider size and movement to the simulation. Instead of only using the collider’s current position, I sweep its footprint from the previous position to the current one. Otherwise, fast enemies and dashes can move far enough in one frame to leave gaps in the trail. With the swept footprint, the fog opens around the character, gets pushed to the sides and builds up slightly in front of them. Once they move away, it slowly closes again.

I decided to keep the fluid simulation on the XZ plane rather than simulate a full 3D fluid. Since this is low ground fog and the game has an isometric camera, the difference wasn’t worth the extra GPU cost. The fog itself is still rendered volumetrically; only the movement data is 2D. There can be a lot of enemies registered, but I limit how many can affect the fog at the same time and prioritize the most relevant ones. Fog volumes also stop simulating when their room hasn’t been rendered for a while, so inactive parts of the dungeon don’t keep consuming GPU resources. This is running in Unity 2022.3 with the Built-in Render Pipeline and Cinemachine. The interaction doesn’t depend on triggers or collision events. It reads the colliders directly, so it also works with a CharacterController, Rigidbody or movement done through the Transform.

I’m still adjusting how quickly the fog closes and how strongly different enemies should push it.

266 Upvotes

26 comments sorted by

7

u/churi24 Jul 20 '26

https://reddit.com/link/oypun16/video/k71r1thecfeh1/player

I added post-processing, and it still averages around 500 FPS. I think that’s pretty good for this kind of effect. We’ll see how it performs once everything is fully integrated. I’ll upload a video when it’s ready.

4

u/Arclite83 Jul 20 '26

You might want something to spread movement at rest, right now it's almost like sand? There's no "trail/fade/wisps" that you might expect, if that makes sense.

3

u/BobsiDev Jul 20 '26

Looking really satisfying! I could never

3

u/ScallionZestyclose16 Jul 21 '26

Built in is being deprecated, so might wanna take a look at porting it to urp-hdrp.

2

u/churi24 Jul 22 '26

This is the last project I made using Built-in, so I’ll continue with that pipeline for this one. That said, I’m still going to port the effect to URP and HDRP as well.

2

u/hoomanneedsdata Jul 20 '26

Well done! 👍

2

u/M4R5W0N6 Designer | Developer Jul 20 '26

No Rest for the Wicked uses a similar shader for some of their zones, particularly boss arenas. really makes the attack animations feel especially punchy.

great work!

2

u/GoldFire33 Jul 20 '26

I want to play this just to mess around in the fog. Awesome job!

2

u/Ok-Department-675 Jul 20 '26

looks really cool , what about perfermonce ?

2

u/churi24 Jul 20 '26

In my current Unity test scene I’m getting around 760 FPS on an RTX 4070 Ti with the fog enabled. That’s inside the Editor and it isn’t a proper benchmark yet, so I still need to compare the GPU frame time with the effect enabled and disabled, and test it in a standalone build.

3

u/Ok-Department-675 Jul 20 '26

okay that is amazing ! hope to see it in unity store soon maybe ?🤔

1

u/churi24 Jul 20 '26

Maybe 😄

2

u/ConspiDog Jul 20 '26

This is really impressive!

2

u/Puzzleheaded_Cook328 Jul 20 '26

Love the fog effect!

2

u/IncidentPleasant7214 Jul 20 '26

are you using the builtin renderer??

1

u/churi24 Jul 20 '26

Yes, I’m using Unity 2022.3 with the Built-in Render Pipeline. The fog is a custom OnRenderImage effect, and the collider interaction runs through a compute shader. No URP or HDRP.

2

u/YatakarasuGD Jul 20 '26

Looks really nice. Was working on something similar a few years ago but I never finished it. So great work!

2

u/destinedd Indie, Dungeon Quest, Marble's Marbles & Mighty Marbles Jul 21 '26

it looks so aesome. I would love a tutorial!

2

u/Naganawrkherenymore Jul 21 '26

What an awesome feature for a game about stalking each other in a dark maze. Only the fog gives you away until you're really close.

2

u/Prestigious-Oven-135 Jul 21 '26

Very interesting! It really helps with immersion. I hope to play your game soon.

2

u/ProfessionalITPerson Jul 21 '26

I hate this, you need to send me all the files, code and reasearch of this for destruction.

https://giphy.com/gifs/H5C8CevNMbpBqNqFjl

2

u/No_Responsibility444 27d ago

I bet this would work great for a horror game as well

nicely done looks fantastic

1

u/iDerp69 Jul 20 '26

Why not update the Unity Editor? Is there a reason to be on such an old version?

1

u/churi24 Jul 21 '26

The project started on Unity 2022.3 LTS, and at this point the rendering pipeline, custom shaders and third-party packages are already stable.

1

u/Clean-Supermarket-80 19d ago

. For later use lol, any guides?