# z value equal w value ?

This topic is 3172 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I write a little shader in DX9 HLSL. I use VS.NET 2003&DX Shader Debug to debug the shader. The render result is right(Color). But i find the vertex position's z and w component is equal. what is the problem? It's the Vertex shader code struct VS_INPUT { float3 pos : POSITION; float2 tex : TEXCOORD; }; struct VS_OUTPUT { float4 pos : POSITION; float2 tex : TEXCOORD; }; VS_OUTPUT vs_main(VS_INPUT vs_in) { VS_OUTPUT vs_out = (VS_OUTPUT)0; vs_out.pos = mul(float4(vs_in.pos, 1.0f), matWVP); vs_out.tex = vs_in.tex; return vs_out; } The matWVP below: D3DXMATRIX matWVP = m_matWorld * (*fpc.GetViewMatrix()) * (*fpc.GetProjMatrix()); hr = m_lpEffect->SetMatrix("matWVP", &matWVP); ------------ The m_matWorld is identity matrix, fpc is CFirstPersonCamera

##### Share on other sites
No, z is the depth. While w (Im not sure what is it but) is something related with homogeneous coordinates.

In homogeneous coordinates, a coordinate is represented by v = (x, y, z, w), a vector is represented by v = (x, y, z, 0) and a point is represented by v = (x, y, z, 1);

So z != w

:)

But in some cases Z VALUE CAN BE THE SAME AS W VALUE

##### Share on other sites
Is this, formula D3DXMATRIX matWVP = m_matWorld * (*fpc.GetViewMatrix()) * (*fpc.GetProjMatrix());each matrix as follows：
m_matWorld is identity matrix。
(*fpc.GetViewMatrix()) matrix is this:
1.0000000|0.00000000|0.00000000|0.00000000
0.0000000|0.94868100|-0.3162346|0.00000000
0.0000000|0.31623462|0.94868100|0.00000000
0.0000000|0.00228119|316.227780|1.00000000
(*fpc.GetProjMatrix()) matrix as follows：
1.8106600|0.00000000|0.00000000|0.00000000
0.0000000|2.41421340|0.00000000|0.00000000
0.0000000|0.00000000|1.00003340|1.00000000
0.0000000|0.00000000|-0.1000033|0.00000000
The view, projection matrix above are set by CFirstPersonCamera's SetViewParams,SetProjParams
vFrom = D3DXVECTOR3(0.0f, 100.0f, -300.0f);
vTo = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
g_fpcMain.SetViewParams(&vFrom, &vTo);
g_fpcMain.SetProjParams(D3DX_PI/4, pBackBufferSurfaceDesc->Width/(float)pBackBufferSurfaceDesc->Height, 0.1f, 3000.0f);
====================================================
In short，the result matWVP(the matrix be passed into vertex shader) is:
1.8106600|0.00000000|0.00000000|0.00000000
0.0000000|2.29031850|-0.3162451|-0.31623462
0.0000000|0.76345783|0.94871265|0.94868100
0.0000000|0.00550728|316.138340|316.22778
==============================================
==============================================
After passed into vertex shader, the matrix as below:
[0]{ x=1.81066, y=0, z=0, w=0 } float4
[1]{ x=0, y=2.29032, z=0.763458, w=0.00550728 } float4
[2]{ x=0, y=-0.316245, z=0.948713, w=316.138 } float4
[3]{ x=0, y=-0.316235, z=0.948681, w=316.228 } float4
-----------------------------------------------
The key is, if input a vertex iPos = {-100, 0, 100, 1}
Operational Results that use mul operator are oPos = { -181.066, 76.3513, 411.01, 411.096 }. That is: input vertex DotProduct Each line of the matWVP matrix.
-------------
If we only calculate z and w component of output vertex, is this:
new_z = old_x*0 + old_y*-0.316245 + old_z*0.948713 + old_w*316.138
new_w = old_x*0 + old_y*-0.316235 + old_z*0.948681 + old_w*316.228
We find that the last two lines of matWVP matrix are so alike, so ,
regardless input vertex value, the output vertex' z and w component
are same！

I really don't know what's the error. Although the render result is correct.

##### Share on other sites
Wait, 411.01 isn't the same as 411.096... It's close, but not equal.
Quote:
 the render result is correct
So... what is the problem you're trying to solve?

##### Share on other sites
After applying the projection matrix, the computed depth value of a point is pos.z / pos.w. The range of these values is typically 0 to 1, where 0 is close to the near clipping plane and 1 close to the far clipping plane. Because of the nature of the projection space, and because people often choose to set their near clipping plane very nearby, this value tends to be close to 1 a lot, in other words, far away. If it is almost 1, then pos.z / pos.w is close to 1, so the z component must be almost as large as the w component.

##### Share on other sites
Quote:
Original post by Hodgman
Wait, 411.01 isn't the same as 411.096... It's close, but not equal.
Quote:
 the render result is correct
So... what is the problem you're trying to solve?

...if i want to do some application(for example shadow map), i worried the z/w value is not correct. because all pixel's z/w near to 1......

##### Share on other sites
Quote:
 Original post by Ignifexwhere 0 is close to the near clipping plane and 1 close to the far clipping plane.

thank you...
but my far clipping plane is 3000.0f. the vertex coordinate is only 100.0f........the distance may be large...

1. 1
2. 2
Rutin
21
3. 3
A4L
15
4. 4
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633742
• Total Posts
3013638
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!