Page 1 of 2

Depth with Orthographic Camera

PostPosted: Tue Jul 10, 2018 9:06 am
by DuvE
Hi, one quick question.

Is there a way to somehow hack and make Depth (Depth Blend for example) possible to use with Orthographic Camera?

Re: Depth with Orthographic Camera

PostPosted: Tue Jul 10, 2018 2:21 pm
by Amplify_Borba
Hello!

Orthographic cameras work with depth a little bit differently, but it's possible to access it through the Screen Depth node, which fetches depth values directly from the depth buffer as linear depth values.

Be sure to set the 'Convert To Linear' toggle option in its parameters to Off when working with an Orthographic Camera.

Please let me know if this helps, thanks!

Re: Depth with Orthographic Camera

PostPosted: Wed Jul 11, 2018 8:21 pm
by DuvE
Hi,

I can't get it to work with an Orthographic camera, even when I turn Off the "Convert to Linear" option. Here is the simple case scene in Unity package. Could you take a look, please?

Re: Depth with Orthographic Camera

PostPosted: Thu Jul 12, 2018 1:42 pm
by Amplify_Borba
A simple way to access depth while using an orthographic camera would be through the use of the Camera Depth Fade node, as per the example below:

Image

Do note that if the shader needs to access the depth buffer contents behind the object it is assigned to, then it should not be written into the depth buffer, and for that its Render Queue must be set to be greater than or equal to Transparent.

I'm not entirely sure on the type of effect you want to create, so you'll have to share additional details in order for me to assist any further. I hope that the information and sample shared above help!

Re: Depth with Orthographic Camera

PostPosted: Thu Jul 12, 2018 2:26 pm
by DuvE
Hi,

I wanted to create Depth Fade effects, like one in ForceFields or Soft particles (https://prnt.sc/k5nmhf), it works fine with a perspective camera. But don't work with orthographic, even when I change the "Convert to Linear" setting in a "Depth Fade" node.

PS: Your example works fine, Just tested it. But "Depth Fade" and "Screen Depth" nodes do not work.

Re: Depth with Orthographic Camera

PostPosted: Thu Jul 12, 2018 3:17 pm
by Amplify_Borba
In order for the Depth Fade and Screen Depth nodes to work correctly in a certain object, that object must be written to the depth buffer, so you must make sure to have the ZWrite On and ZTest on Less or Equal.

Another detail to take into consideration is that objects that are marked NOT to cast/receive shadows are also not written into the depth buffer ( independently of the Z options ), so you need to have at least Receive Shadows toggled ON over the output node.

If you need for your object to not cast/receive shadows, then you'll need to go to its mesh renderer component and manually turn them off over there.

Re: Depth with Orthographic Camera

PostPosted: Thu Jul 12, 2018 4:18 pm
by DuvE
Yeah, I've checked all of this. In my case scene, everything has just a standard material and casting/receiving shadows. The problem is - everything (Depth Blend and Scene Depth) works in perspective, but don't work in orthographic and turning Off "Convert to Linear" doesn't help.

Cubes and plane in case scene all using standard material. The project using deferred rendering, but when I turn camera mode to orthographic it switches to Forward, but still render the Depth Texture, so it's ok.

Re: Depth with Orthographic Camera

PostPosted: Thu Jul 12, 2018 5:10 pm
by Amplify_Borba
That's strange, we've tested it on our side and the depth nodes seem to be working as expected with the specifications that we've shared.

Could you please send us a simple sample of an effect working in perspective as you intend, so that we can look into converting it to orthographic?

Re: Depth with Orthographic Camera

PostPosted: Thu Jul 12, 2018 6:02 pm
by DuvE
I've recorded a short video - https://youtu.be/7oe05ZdL6vc

It's a simple Depth Fade or Depth Blend effects, used in many ForceField VFX. I've already done this effects, just want to make it work with the orthographic camera.

Re: Depth with Orthographic Camera

PostPosted: Fri Jul 13, 2018 2:21 pm
by Amplify_Borba
Thank you for the additional details.

From the tests we've ran yesterday, the depth nodes seemed to be working correctly with an Orthographic camera with the parameters that we've shared, including the Depth Fade and the Screen Depth nodes, providing that "Convert To Linear" is Toggled off. You might also have to adjust your camera Far/Near Clip values.

I understand that you want to create that specific effect you've shown in the video in a way that it presents itself the same way in Orthographic as it does in Perspective, however, do note that it's very tricky to achieve a similar visual look between different Projection types, meaning that you'll likely need to run a few additional calculations since depth works differently in each situation.

This Unity thread's discussion might help explain this situation and also provide a few possible workarounds.