Custom fog feature

Greetings! I’m using Unity 2021.3.25f1 + URP.

I’m working on fog effect for my game. Scene is complicated, made of many 3D objects in multiple layers, foreground and background (last one is multi-layered). I want to apply fog to them, with some ability to flexibly tune it.

The default Unity’s fog (which is in “lighting”) seems to be unflexible for such case, because i can’t tune fog settings for each group of objects that I use. It makes me use different cameras for different layers of background to make them correctly interact with Unity’s fog, because in other case different layers can intersect each other. I find it both unoptimized (as far as I understand) and bit uncomfortable to use.

I found obvious that Unity’s fog wasn’t designed to handle such multi-layer solutions, so… I understood how it handles objects (result aspect) and decided to recreate this effect on my own. Linear fog just interpolates basic object’s pixels into solid unlit color. I’m asking for next:

My first approach was to do this with URP’s ShaderGraph, but it seems like it’s impossible to combine lit+unlit rendering in single shader. Is there way to implement this functionality on my own, for example by using Unity’s renderer feature tools, and how to do that if yes? Also, please tell me, is my approach viable with both ShaderGraph or text-based-shaders? I prefer using ShaderGraph, because have no experience in text-based-shader writing.

I’m generally bad at entire graphics aspect, never went beyond ShaderGraph (I mean no experience at text-based-shaders or renderer features), so good advice will help me a lot. Thanks!

you could definitely do this easy peasy in a written hlsl shader. i did this in shader graph some time ago but it was an ugly graph. i’d recommend some combination of a c# script with global variables and an object shader.