SpartanzNeverDie
SpartanzNeverDie

Reputation: 1

Unity Shader Graph: how to combine lit and unlit rendering in one single shader (is it possible)? Custom (individual per object) fog effect

I'm using Unity 2021.3 (URP). I'm using ShaderGraph.

I'm working on custom fog effect, agile and individual for each 3D lit object of some category. I want to be able to turn some part of lit-shader-based object into unlit, by some factor [0...1].

I want next thing: when fog factor for pixel is 0 (min), we clearly see part of object (rendered like lit). When factor is 1 (max), pixel is expected to be totally filled with fog fixed fog color (rendered like unlit!). In short, I want to implement some transition between lit and unlit rendering in single shader, that's my main problem.

In context of implementing entire desired feature (not only lit<->unlit smooth transition), in total, I tried:

  1. Default Unity fog (lighting section). Found it too inflexible for my case, because I work with complicated scene with multiple layers (cameras) and lots of objects in different positions, and I want my objects to have individually customized fog effects. Unity default fog is one setting for entire scene, even correct positioning makes setup of objects very difficult and inflexible.
  2. Searching for other solutions. After all, became interested with topic of lit/unlit rendering combining. Now I see other solutions not so elegant.

I understand, that this case is possibly all about post-processing/overlapping original lit object's surface with some unlit/working with Unity URP's RendererFeatures, but I'm generally new to work with graphics, so it all is difficult for me (I mean I progress hardly and slowly in advanced rendering mechanisms). I already spent several days working on this feature, didn't find understandable solution, and gonna continue my attempts to implement the desired fog feature with different, more difficult ways, BUT... But now I'm obsessed with perspective of transition "lit->unlit" in single shader, and so I ask this question here :)

Upvotes: 0

Views: 1052

Answers (1)

armegalo
armegalo

Reputation: 23

Interesting. I had a similar requirement, except the "fog" would actually render the skybox behind as if becoming transparent, but without other transparent objects collecting behind it and distorting the illusion.

In the end I found this tutorial that helped me code a basic lit shader. I then fed that into an unlit shadergraph and lerped between that and the skybox texture based on distance.

I had to use a huge sphere for my actual skybox because unity's skybox and my shader didn't quite match up - some distortion or other. But it works quite well. As you can see...

Upvotes: 0

Related Questions