Download

Need guidance with PostProcess Blendable

Hi there:

I’d like to do the following:

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:
6d840f5d980af7f95f841891065195f8e5e234d7.jpeg

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.

Thanks for your help.
The Problem was PixelDepth. I needed to use SceneDepth. :slight_smile:

Ah I definitely overlooked that :slight_smile: 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?
ab5e128b20d99d4c2e4c8c2dfaf2b9f5dd42e460.jpeg

Sure, you can build your own depth threshold and replace the alpha with 0.

Try doing something like:
ceil(SceneDepth - 50k)

then do clamp and 1-x. This means it returns 1 for any depth less than 50,000 and 0 for any depth past that.

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.

Can you explain the setup with BoxMask?
Is this correct?
Unbenannt.JPG

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.

Thank you very much. It works :slight_smile:

As you have done, I would like you to tell me, how did you do it?
please.

You simply set the Domain to Post Process and add the Material as a Blendable in your Post Process Volume :slight_smile:

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):
e08d3f3d74e67c95e2d15a2fd34e2166d3b0d36a.jpeg

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.

Thank you for you trying to help me, but the result is very strange:
a788bab673fb2a036859c7ea952bb51afe508746.jpeg

c6f086ed8a71d97178020568fcbeee0625302c0e.jpeg

I guess I can reuse my BoxParameters by simply using XYZ of Parameter, Camera and CameraVector, So I can have something like a fish tank, too :stuck_out_tongue:

I’ll change this later :slight_smile:

The problem is the same thing I mentioned in my first post in this thread. You are using an unclamped value in a lerp alpha.

You also need to move your Depth divide AFTER the min, otherwise you will skew the results and it will be like you did the inverse on the top plane.

also, maybe take the ABS of the CameraVector.Z just incase its negative.

Still not working correctly.
8ce2b30c0d460d521c689f9f12445f19705540eb.jpeg
Unbenannt.JPG

I tested and divided the Box Extent.Z by 2.
I get this result:
Unbenannt2.JPG

It looks upside down to me.

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.

it looks a bit better:

to me it looks like it is doing the Water.z - Camera.z stuff for both directions.