Custom DepthNormalTexture pass?

Hi,

Is it possible to create a custom depth/normal pass, for shaders that manipulate vertex positions?

I’m aware of how to create custom ShadowCaster passes, but can’t find any examples of how to do something similar for the DepthNormalsTexture pass - which I need to make SSAO work without major glitches?

(I’ve tried taking a copy of the Hidden/Internal-DepthNormalsTexture built-in shader and putting it in the project - but it still seems to use the built-in version, so I don’t seem to be able to add a new pass/RenderType in there?)

According to the documentation (here and here), Depth is rendered using the ShaderCaster pass as well.

If you have a surface shader with vertex animation, adding an addshadow directive will make Unity generate a shadow pass too. This is commonly used with custom vertex modification, so that shadow casting also gets any procedural vertex animation.

In forward the camera depth texture uses the shadow caster pass. In deferred both the camera depth texture and camera depth normal texture come from the deferred pass.

However the camera depth normal texture for forward is indeed generated using that hidden shader. In previous versions of Unity just dragging it into the asset folder was enough to make it overrides the built in one, but now you have to assign it in the project’s graphics settings.

2 Likes

Does this relate to how meshes drawn with DrawMeshInstanced do not write to CameraDepthNormals with the Forward Renderer? Can I use the Internal-DepthNormalsTexture.shader to force these meshes to draw to the DepthNormalsTexture? Or maybe I can use Internal-DepthNormalsTexture.shader to write to a different texture and then pass that texture into the Post Processing that relies on the DepthNormalsTexture

Thanks for all the explanations everyone, which answers some of my previous questions about depthnormals.

I am rendering with custom clipping, and want the depthnormals pass to respect that clipping (for roberts cross edge detection.)

With Deferred Shading this “just works”
With Forward shading and DepthTextureMode.Depth (i.e. using a depth-only edge detection) this works if I enable shadow pass generation in my clipped surface shader.

I’ve created a custom shader in Internal-DepthNormalsTexture with a tag for my clipped material, but that shader is not being used during replacement and I can’t see where to apply that shader in Graphics Settings in Unity 5.5. The only shader I see an override for there is Hidden/Internal-MotionVectors. What am I missing?

You’re not missing anything really, Unity for some reason doesn’t show it in the inspector anymore. You can still assign it by using the debug inspector though. Just right click on the inspector tab and select debug. It would show a few more things you can override.

Thanks - I did it from a script, and that works, but forgot to update this post. Forgot about debug inspector.