Hi everybody,
Sorry if this is a stupid question to you, but I really can't figure it out so please help me out.
My understanding of the position output of a vertex shader is that it is a homogeneous 4D vector, so I'm thinking, the following two pieces of codes should have exactly the same results:
PS_OUTPUT vs(PS_INPUT In)
{
PS_OUTPUT Out;
Out.vPos = mul(float4(In.vPos, 1.0f), mtWorldViewProjection);
Out.vTexCoord = In.vTexCoord;
return Out;
}
and
PS_OUTPUT vs(PS_INPUT In)
{
PS_OUTPUT Out;
Out.vPos = mul(float4(In.vPos, 1.0f), mtWorldViewProjection);
Out.vPos /= Out.vPos.w;
Out.vTexCoord = In.vTexCoord;
return Out;
}
The only difference is the additional division by Out.vPos.w which will happen anyway. But this additional instruction changed the look of the texture from "perspective correct" to "perspective incorrect" (I don't know if I'm saying the right way, so here's an image to show what i mean: http://en.wikipedia.org/wiki/File:Perspective_correct_texture_mapping.jpg). Apparently it has something to do with the way the "perspective correction" is performed, but I really don't understand why that additional division would mess anything...
Any idea?
[Edited by - fang on December 4, 2009 7:23:54 AM]