I've never used the Orthographic projection, but depth effects work...

@Cyanilux
Cyan ✨@Cyanilux
43 views Apr 18, 2024 ~1 min read
Advertisement
1
I've never used the Orthographic projection, but depth effects work slightly differently. I was asked about it on the official Unity discord, and after some research got it working, so might as well share a small thread here too. 🙂 #unity3D #shaders
2
In perspective, the depth buffer is non-linear. The Scene Depth node in shadergraph allows us to specify Linear01 or Eye, which will convert it for us.
(see cyangamedev.wordpress.com/2019/06/01/sce… for more info).
3
But in orthographic, the depth buffer is already linear. The Scene Depth node should be set to Raw to ensure we aren't trying to convert it to linear again! It's between 0-1 so we can use a lerp with the near and far planes to convert it to units.
4
Platforms can also have the depth buffer reversed so that needs to be taken into account. We can calculate the world position from the depth value as seen in the image.

This is based off of the code from @_kzr, hopefully I didn't misinterpret any of it :
github.com/keijiro/DepthI…
Media image
5
From there, we should be able to use the Y coordinate of the depth-reconstructed world position to mask noise for some shoreline effects for example.

(Orthographic stuff is fairly new to me, so hopefully all of these tweets are correct!)
Media image
6
Hey! In case anyone stumbles across this thread, I now have a proper blog post about this Orthographic Depth stuff! It's more in-depth 😄 and includes a depth-difference example as well as the worldspace reconstruction.

🔗 cyangamedev.wordpress.com/2020/03/05/ort…
Actions
What You Can Do
  • Export as PDF or Markdown
  • Batch Export to Notion
  • Bookmark & Highlight
  • Screenshot Tweet
Create Free Account

Includes 7-day Premium trial

Advertisement