Cubetexture addresssing?
Hellow!
When try to implement the demo done by Humus on "http://www.humus.ca/3D/Water.zip",I got some trouble.
In his demo, it loads the environment map(cube texture) from 6 pictures.For simplicity,I just create a cube texture with the texture tools provided by dx9 sdk.
Things go quite good until the computation of reflection on the water surface,the result is quite different from what I expected.I try many ways to find out the reason,but I failed to do so.
How cubetexture is addressed?
This is the definition of the vertices from my program:
//Room vertices
CUSTOMVERTEX3D vertices[]=
{// x y z texture_coord
{-5, 5, 5, -5, 5, 5},
{ 5, 5, 5, 5, 5, 5},
{-5, -5, 5, -5, -5, 5},
{ 5, -5, 5, 5, -5, 5},
{-5, 5, -5, -5, 5, -5},
{ 5, 5, -5, 5, 5, -5},
{-5, -5, -5, -5, -5, -5},
{ 5, -5, -5, 5, -5, -5}
};
//water surface
CUSTOMVERTEX2D vert[] =
{// x y z texture_coord for bump map
{-5, 0.0f, 5, 0, 1 },//0
{ 5, 0.0f, 5, 1, 1 },//1
{ 5, 0.0f, -5, 1, 0 },//2
{-5, 0.0f, -5, 0, 0 },//3
};
The camera position is:
m_Eye = D3DXVECTOR3(2.0f, 2.0f, -2.0f);
so in the shaders the view vector is computed as:
view_vec = position - camera_pos;
then:
normal = normalize(normal);
view_vec = normalize(vie_vec);
float3 reflVec = reflect(view_vec, normal);
float4 refl = texCUBE(Env, reflVec);
But the result is incorrect.
I finally find out the reason.
It is the function "ID3DXConstantTable::SetFloatArray" that causes the issue.
I used it to set the value in my shader program which is of float3 type,maybe the tpye flaot3 just is not the same as a float array with 3 elements.
So I changed to "IDirect3DDevice9::SetVertexShaderConstantF",then result is very good!
What annoyed type conversion!
It is the function "ID3DXConstantTable::SetFloatArray" that causes the issue.
I used it to set the value in my shader program which is of float3 type,maybe the tpye flaot3 just is not the same as a float array with 3 elements.
So I changed to "IDirect3DDevice9::SetVertexShaderConstantF",then result is very good!
What annoyed type conversion!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement