I need a shader for deferred rendering that writes only to the normals buffer, without any color. In other words, it should only output to RT2 of the G-Buffer.
The reason for this is that I need an invisible object that still affects other shaders that consider depth / normals (occlusion, DOF, etc.) for some experimental effects.
I’ve tried the following, but as soon as I add the alpha tag, nothing is written to the normal buffer, even with the ZWrite flags.
I don’t think what you’re trying to do is possible with a surface shader to begin with, so you’ll want to use a vert/frag shader.
Now for that it’ll actually be easier than you think. You should be able to find any existing depth only / depth mask shader and add:
Tags { “LightMode” = “Deferred” }
I haven’t tried it, but I’m pretty sure that’ll “just work” and do exactly what you’re asking for. I’m just not sure if it’ll result in what you think it will.
That’s not the depth buffer, that’s the normals buffer. And yes, messing with the rendering is exactly what’s going to happen when you do this, even if you’re modifying the normals buffer.
You’re right, sorry, I updated the wording. I believe the rendering “artifacts” I would get are actually what I’m looking for. Do you have an idea as to how I could write to the normals buffer?
Didn’t work. I’m assuming this happens because with no ZWrite, it doesn’t know how to order the renderer in the normals buffer. We’d need ZWrite only for RT2 then… if that makes sense?
The queue might not actually do anything if you just change it in the shader:
And you can’t just do Zwrite for a single render target and not another. The depth buffer is a global thing and the deferred rendering path makes a copy of the global depth buffer, unlike forward which generates it as a separate scene pass.