

Under the hoodĭepth textures can come directly from the actual depth buffer, If you see artifacts in your depth texture, make sure that the shaders that use it do not write into the Z buffer (use ZWrite Off). In some cases, the depth texture might come directly from the native Z buffer. In particular, using depth texture in an Image Effect often needs special handling on Direct3D + Anti-Aliasing. When implementing complex shaders or Image Effects, keep Rendering Differences Between Platforms in mind. Particularly with multiple effects present on a camera, where each of them needs a depth texture, there’s no good way to automatically “disable” depth texture rendering if you disable the individual effects. That after you disable some effect that needed them, the camera might still continue rendering them. The way that depth textures are requested from the camera ( pthTextureMode) might mean

Tips & TricksĬamera inspector indicates when a camera is rendering a depth or a depth+normals texture.
UNITY TILT SHIFT SHADER GUIDE HOW TO
Returned depth is in 0.1 range.įor examples on how to use the depth and normals texture, please refer to the EdgeDetection image effect in the Shader Replacement example project or Screen Space Ambient Occlusion Image Effect. Unit圜G.cginc include file has a helper function DecodeDepthNormal to decode depth and normal from the encoded pixel value. Normals are encoded using Stereographic projection, and depth is 16 bit value packed into two 8 bit channels.
UNITY TILT SHIFT SHADER GUIDE 32 BIT
This builds a screen-sized 32 bit (8 bit/channel) texture, where view space normals are encoded into R&G channels, and depth is encoded in B&A channels. Note that only “opaque” objects (that which have their materials and shaders setup to use render queue <= 2500) are rendered into the depth texture. If you’re using surface shaders, adding an addshadow directive will make them generate a shadow pass too.Make your shader fallback to some other shader that has a shadow casting pass, or.there’s no shadow caster pass in the shader or any of the fallbacks), then objects using that shader will not show up in the depth texture. So by extension, if a shader does not support shadow casting (i.e. This builds a screen-sized depth texture.ĭepth texture is rendered using the same shader passes as used for shadow caster rendering ( ShadowCaster pass type). DepthTextureMode.DepthNormals: depth and view space normals packed into one texture.DepthTextureMode.Depth: a depth texture.There are two possible depth texture modes:

It is also possible to build similar textures yourself, using Shader Replacement feature.Ĭamera’s depth texture can be turned on using pthTextureMode variable from script. This is a minimalistic G-buffer texture that can be used for post-processing effects or to implement custom lighting models (e.g. A Camera can generate a depth or depth+normals texture.
