I am really wondered what the hell tex2Dproj have done.(My Eng is poor.......)
For example: I want to find a point in 3Dspace where it will be drawn on my screen(or maybe a texture) by UV coordinate.
First i should transform the coordinate;
float4 vPtInProjSpace = vPtInObjSpace * matWorld * matView * matProj;
Then i want to use tex2Dproj to help me find the pixel drawn by that point.
float4 color = tex2Dproj( sShadowMap, vPtInProjSpace );
Of course this way is totally wrong, but i know how to do it by tex2D:
float2 vTexCoord = float2( vPtInObjSpace.x / vPtInObjSpace.w / 2 + 0.5, (- vPtInObjSpace.y) / vPtInObjSpace.w / 2 + 0.5 );
float4 color = tex2D( sShadowMap, vTexCoord );
And this works well.
Luckily i find the right way by using tex2Dproj in this sample:
float fTexOffs = 0.5 + (0.5 / (float)SHADOW_MAP_SIZE);
D3DXMATRIX matTexAdj( 0.5f, 0.0f, 0.0f, 0.0f,
0.0f, -0.5f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
fTexOffs, fTexOffs, 0.0f, 1.0f );
float4 color = tex2Dproj( sShadowMap, vPtInProjSpace * matTexAdj);
So there is my question: what the matTexAdj is ? and how tex2Dproj works ?
Anyone give me a hand T_T