When underwater (= in a Post Process Volume), I’d like to have some kind of “fog” for the density of dirt in the water.
I tried using SceneDepth in a Post Process Material and applying this in the PP Volume as a Blendable.
Unfortunately, my screen becomes black.
My Blendable looks like this:
Hey, your depth is going to go way over 300, which means you need to clamp the value before using it as a lerp alpha.
Also, I would suggest using the material function “exponential density” instead of just dividing depth by 300, since that will use the same formula as actual fog. You’d hook it up exactly the same, but might need to swap the order of pins on the final lerp.
Ah I definitely overlooked that that said, you still want to clamp the lerp alpha, otherwise the lerp will overshoot the white and instead start projecting the difference between scene color and your fog color. Could get very bright or corrupted looking.
I already noticed this.
I got another problem.
Because I’m using SceneDepth only, everything that’s outside of the water becomes covered, too.
Is there a solution for this?
I’m not sure if that’s what I want.
When underwater and looking towards the surface, the PP will continue, making the outside look the same as if it is underwater. You know what I mean?
I’d like to have “filter” or simply make the PP stop when reaching the Surface
You can access the world position of the scene in a PP material just by placing the WorldPosition node. Then just take the B channel and subtract your water Z. Then either divide by a scalar or use ceil and clamp.
if you need to bound the effect in a box not just along Z, you could use the function BoxMask.
Nope, you would use the results of the box mask as another alpha after your existing Lerp to control where to disable the effect. Also with 0 extents the box will be 0 sized so you won’t see anything.
So, BoxMask looks ugly, if you think about it and is not suited what I want to achieve. For smaller waters this suits.
What I want to achieve is something like in Source Engine(taken from Gary’s Mod):
As You can see, When in Water, youo see the fog. Everything that’s above water is not affected by the Fog. But in the distance you can see that the Fog is still applied.
Scene Depth doesn’t seem to be suited for what I want at all.
thats pretty easy, you just do MIN operation on scene depth, and ray length to the water plane.
Length to waterplane can be calculated like:
(WaterZ - CameraPosition.Z) / CameraVector.Z
Then you just do a Min with that and SceneDepth.
I also suggest you use ExponentialDensity and not just a linear blend, since a linear blend will look very artificial.
FWIW this is the same thing I originally suggested (bounding by Z), and BoxMask was only a suggestion if you need a box like a fish tank or something where you can see out.
It looks correct, just a little low. Rather than doing that extents stuff, just specify the Z. measure it by placing a light or something and reading the details panel. also ABS of cameraZ just to be safe.