Any way I can get the depth texture in a CanvasItem shader?
Asked Answered
C

4

0

I admit, I don't really understand depth mapping so if there is anything I should know, tell me.

A Spatial shader can use uniform hint_depth_texture but not a CanvasItem, I'm guessing this is because that Spatial shaders operate in 3D and CanvasItem shaders operate in 2D. Is there any alternative method I can use to access the depth texture in a CanvasItem shader?

Cleaves answered 3/11, 2023 at 5:38 Comment(0)
P
0

Cleaves What do you need it for?

Pinard answered 3/11, 2023 at 6:43 Comment(0)
C
0

Pinard Really, I don't know. There's a lot of post processing shaders that can get the depth map (such as a custom HDRP post proc shader in Unity), so I'd guess I want to access it for the same purpose.

For the CanvasItem, I'd guess I'd have it in there just so I don't have to spend any extra polygons. Unless if that somehow bogs down performance.

Cleaves answered 9/11, 2023 at 5:11 Comment(0)
P
0

Cleaves Rendering a 2D rect or a 3D sprite in front of the camera will spend the same amount of polygons.

Pinard answered 9/11, 2023 at 5:28 Comment(0)
U
0

CanvasItems can't read the depth buffer. If you absolutely need it, you can use a screen aligned quad with a shader that renders the depth texture onto a special subviewport, then grab the subviewport's texture for use in your CanvasItem shaders... But if you're doing all that for the sake of post processing then why not just do the post-processing with the screen aligned quad in the first place?

Unrivalled answered 9/11, 2023 at 11:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.