Page 1 of 1

Orthographic depth

PostPosted: Tue Feb 19, 2019 4:17 am
by empika
Hi there,

I'm trying to recreate a toon water shader that uses depth for the water colour and edge foam but I'm having some issues using it with an orthographic camera.

https://roystan.net/articles/toon-water.html https://github.com/IronWarrior/ToonWate ... ter.shader

When in perspective mode it looks like the depth texture is getting fetched correctly

Image

The rear plane is actually angles underneath the water, and the tilemap underneath that has a missing tile hence the large dar square.

However in orthographic mode it looks like the depth map needs some kind of transform done to it, rather than the plane of water having a linear color it fades in the z axis when there is nothing underneath it.

Image

I've read a couple of posts on here that say I should not convert the depth texture to linear (as it already is linear), I am also adjusting the clipping planes to bring the texture resolution up. I've also tried adding some controls to my shader to adjust the clipping plane and depth but I still think the problem lies in the Z axis.

Here's my node graph:

Image

Any advice on how to get this working in orthographic perspective?

Many thanks,
Edd

Re: Orthographic depth

PostPosted: Tue Feb 19, 2019 7:16 am
by empika
With help from the folks in the Unity discord I got this working:

Image

I switched to using the 0-1 depth space, and then remapped that to the clipping planes. The most important part was subtracting the surface depth from the remapped screen depth rather than the screenPos.w.

Re: Orthographic depth

PostPosted: Tue Feb 19, 2019 2:03 pm
by Amplify_Borba
Hello, thank you for sharing your findings with us, we really appreciate it!