Does anyone know how the source engine calculate its depth values? There's three depth buffers, hardware depth, shader depth and another high precision depth buffer. I'm interested in writing to the hardware depth, but my depth range is different than the game's depth range.
No clue why this is happening as I have the exact same view matrix and projection matrix, but here's some relevant code:
float3 viewParticlePosition = NudgeParticleByNormal(input.Center.xyz, normal);
PS_OUTPUT output = (PS_OUTPUT)0;
output.DepthCol = float4(normal, GetViewLinearDepth(viewParticlePosition));
That is how I'm writing depth, which is stored in the alpha component of output.DepthCol. I'm calculating the depth for a position in view space, and while the depth looks fine to me, in game it has an odd artifact where the particles can be seen through walls in a sawtooth-esque pattern, and I've found out that my depth range isn't exactly the same as the game, but I dont know why.
artifact has been attached as a gif
After I render my depth, I run a shader in D3D9 (game's rendering api) which writes to SV_Depth like so:
output.Depth = depth.a;
feel like im out of options in terms of asking a more general question since other people have noted the strange behavior of source's depth calculation. It appears to be related to packing depth information into a cheap depth format as the shader depth is pretty limited.
Right now I'm calculating depth, GetViewLinearDepth (experimental name), by projecting the view space position and taking the value of clip.z / clip.w;