Hi guys, found something disturbing.
I am putting together a deferred renderer and hit a nasty issue.
When a pixel has an alpha of zero,it is not written to the depth buffer.
My colour render target is created with a 24bit depth buffer, depth buffer is enabled, and depth clipping on the rasteriser state is enabed, but the depth buffer does not work.
You can see this in this video
After a lot of scratching my head, I realised I was storing the materials specular strength in the alpha channel of the color render target, which is zero for the water at the moment.
So I did an experiment by setting this to 1.
Now the depth buffer works.
I am going to work around this by creating another render target and storing specular data in this.
Want to know what is going on though as I am seeing other issues that don’t make sense. Like even though the specular strength is 0, I still get specular terms in the final image.
This makes me think some alpha blending is going on when I don’t want it to.
What RasterizerState and BlendState are you using exactly. What does your shader look like, does it use clip at all? Depth is checked for all rasterized pixels regardless of their color value, as long as you don’t call clip in the shader.
My rasteriser state just has
stat.CullMode = CullMode.None;
stat.DepthClipEnable = true;
No clipping in the shaders.
I have more data.
Creating the extra render target did not take very long, but I forgot to set the alpha value of the material in the water shader and I got this
You can see the material properties of the aircraft even though it should be depth clipped.
So I changed the alpha value in the water shader
So it is definitely an issue with alpha blending
What about you depth stencil state and blend state?
I did find a point in the code where it was possible that the blendstate may have been changed to alphablend, which would have been a problem but shouldn’t have caused the display in the first video.
If you look at the water in the first video, you can see that the water is interfering with itself.
Since all of these pixels have an alpha of 0, there shouldn’t have been any alpha blending. The nearest pixel should have ended up in the depth buffer.