Problems with depth buffer

Hello,

I’ve been working with PlayCanvas for a few weeks playing around with shaders in general and everything seems to run smoothly except for the Depth Buffer. I have browsed the forums and saw many different things being said about it like using :

this.entity.camera.requestDepthMap();
scope.resolve("uDepthBuffer) = this.depthMap; in the shader settings
this.needsDepthBuffer = true; …

None of them seemed to output a proper map, I never managed to see once a clear depthBuffer. A lot of projects supposed to work good with depth buffer are shared online, but all those that claimed to work are either in “error 404” either when you start them with the editor (therefore using the latest version of playcavnas) the depthBuffer simply doesn’t work.

Is it actually possible to use the Depth Buffer in playcanvas or did that functionality get removed from the engine ?

Thanks a lot,

Paul

It’s completely useable, here’s a good example:
http://playcanvas.github.io/#/graphics/post-effects

It uses depth for post-effects … you might need to see the post effect script to see the details.

And also it uses some simple debug shader to display the depth texture in the corner.

Since you mentioned that you were unable to find a working project on playcanvas, I remembered this project that uses the depth buffer and still appears to work in the editor:

https://playcanvas.com/project/753116/overview/outline-post-process

Unfortunately, my working knowledge of working with shaders is shallow at best.

Thanks for your reply =)

Unfortunately this one doesn’t use depthbuffer :S
There might be however a getLinearDepth function in the shader that I’ll try

Thanks for your reply,

I have seen that one however it is not a project but a precompiled render, it uses depthBuffer with a version that is not stated and there is no access to the actual code of the post-effect, only generic code that says something like “apply post-effect to the sphere” without actually showing the code of the effect

This is the debug shader the post-effect uses in the link I provided (which uses depth buffer for both depth of field as well as Screen Space Ambient Occlusion.

This renders the depth texture in the corner itself:

Thanks a lot !

I’m still unable to invoke depthBuffer in my own shaders for some odd reasons but at least now I got a start to dig with, the effect seems to be working when importing the whole post effect

EDIT : Actually the effect only works halfway (tested on a brand new project), anything given in getLinearDepth renders nothing, by visualizing the depth you only get a black screen

force webgl1 on your project, run debug mode of the engine and capture the frame with SpectorJS. Then see what happens. You should see in webgl1 rendering to depth (we do separate pass for this), and its stored in RGBA format, so you can see it in the screenshots there.
Webgl2 uses the actual depth buffer and spector JS does not show you the image, so that is less convenient when debugging.

also note that the debug shader I shared needs to have that “#define GL2” in it - make sure your one does as well (on WebGL2 platforms only of course)