Depth with Orthographic Camera

Node-based Shader Editor

Depth with Orthographic Camera

Postby DuvE » Tue Jul 10, 2018 9:06 am

Hi, one quick question.

Is there a way to somehow hack and make Depth (Depth Blend for example) possible to use with Orthographic Camera?
DuvE
 
Posts: 43
Joined: Thu Nov 23, 2017 6:46 pm

Re: Depth with Orthographic Camera

Postby Amplify_Borba » Tue Jul 10, 2018 2:21 pm

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!
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Depth with Orthographic Camera

Postby DuvE » Wed Jul 11, 2018 8:21 pm

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?
Attachments
case.unitypackage
Case scene to fix depth with an orthographic camera
(136.08 KiB) Downloaded 587 times
DuvE
 
Posts: 43
Joined: Thu Nov 23, 2017 6:46 pm

Re: Depth with Orthographic Camera

Postby Amplify_Borba » Thu Jul 12, 2018 1:42 pm

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!
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Depth with Orthographic Camera

Postby DuvE » Thu Jul 12, 2018 2:26 pm

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.
DuvE
 
Posts: 43
Joined: Thu Nov 23, 2017 6:46 pm

Re: Depth with Orthographic Camera

Postby Amplify_Borba » Thu Jul 12, 2018 3:17 pm

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.
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Depth with Orthographic Camera

Postby DuvE » Thu Jul 12, 2018 4:18 pm

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.
DuvE
 
Posts: 43
Joined: Thu Nov 23, 2017 6:46 pm

Re: Depth with Orthographic Camera

Postby Amplify_Borba » Thu Jul 12, 2018 5:10 pm

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?
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Depth with Orthographic Camera

Postby DuvE » Thu Jul 12, 2018 6:02 pm

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.
DuvE
 
Posts: 43
Joined: Thu Nov 23, 2017 6:46 pm

Re: Depth with Orthographic Camera

Postby Amplify_Borba » Fri Jul 13, 2018 2:21 pm

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.
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Next

Return to Amplify Shader Editor

Who is online

Users browsing this forum: Bing [Bot] and 48 guests