- Home /
Change vertex shader positions on camera depth texture
I have a vertex shader that changes the position of an object's vertices according to some maths. I also have a camera with a depth texture turned on: camera.depthTextureMode = DepthTextureMode.Depth;
For effects using the depth buffer such as sun shafts, the normal vertex positions are used (not the changes I made in the vertex shader). I presume this is because the camera depth uses a different shader. Is there a way to customise that for my shader so the adjusted vertex positions are maintained in the camera depth texture?
I tried writing to fragment depth in the fragment shader with an output struct rather than just colour, but that didn't help. Any ideas?
I'm also having this issue. You can download the built-in shaders used by Unity and add a copy of the camera-depthtexture.shader into your project. The shader uses the 'RenderType' tag of your custom shader to deter$$anonymous$$e which subshader of camera-depthtexture.shader is used to replace your custom shader when writing to the depth texture.
Looking at the other sub shaders, its probably pretty easy to figure out what you need to do for your own (copy the vertex distortion from your custom vertex shader, etc)
The only issue I'm currently having with this is that it only works in the editor window, and when you build the project it just uses the original depthtexture shader.
frustrating.