What will the following two commented functions do? Will they break things? Could they be useful?

float4 VS(float3 pos: POSITION) : POSITION

{

float4 hPos = mul(worldViewProj,float4(pos, 1.0));

{

float4 hPos = mul(worldViewProj,float4(pos, 1.0));

// OPTION A:

//hPos /= hPos.w;

//hPos /= hPos.w;

// OPTION B:

//hPos.z *= hPos.w / farPlaneViewZ;

//hPos.z *= hPos.w / farPlaneViewZ;

return hPos;

}Answer: They will screw with your perspective interpolation in different ways.

Option A just gives the non-homogeneous space coordinates to the pipeline. It will effectively disable perspective interpolation on your texcoords, and I can't find much use for such a thing :)

Option B is more tricky. If you do the math, you'll find out that it will force the Z-buffer to contain a linear depth value, as the Z-buffer stores z/w, and z ranges from 0 to far after the projection, so by multiplying by w and dividing by far, we get the resulting z/w to be z/far.

Interestingly, it won't screw with texture coordinates as it does not touch w, so it could be really useful.

There is a problem though, that at first I overlooked untill I received a detailed mail from one of my coworkers explaining my naivete. Now z is not linear anymore when interpolated in screenspace. and that could cause all sorts of artifacts where the z on your triangles does not lie on a plane anymore... But in some cases can indeed work fine, if your objects are tassellated enough and you don't get parallel walls close to each other... Shadowmaps for your characters for example...

**: some interesting documents that I've found around...**

*Update*This is basically the same idea as the trick "B" but going into yet another space. The article fails to account for the errors the system introduces, but in the comments you can read basically the same conclusions that I wrote here:

This is an analysis that suggest to invert the z with floating point buffers, that is a very common practice. It does make sense in terms of precision but it's really required by hi-z, because of the way it works.

And last but not least, this article shows the effects of triangle orientation on the z-fighting: http://research.microsoft.com/apps/pubs/default.aspx?id=79213