Texture Coordinate

Started by
5 comments, last by sansured 17 years, 2 months ago
Hi guys, I am using IDirect3DBaseTexture9 structure for my mesh textures.I am wondering about is there a way to get each texture's 3d coordinate in render loop. For example: this is where set textures for effect(shaders) in my render loop

UINT cPasses;
V( g_pEffect->Begin( &cPasses, 0 ) );
for( UINT p = 0; p < cPasses; ++p )
{
 V( g_pEffect->BeginPass( p ) );
ID3DXMesh *pMesh = g_Map.GetMesh();
for( UINT i = 0; i < g_Map.m_dwNumMaterials; ++i )
{
 V( g_pEffect->SetVector( "g_vMatColor", (D3DXVECTOR4*)&g_Map.m_pMaterials.Diffuse ) );
if( g_Map.m_pTextures )
 V( g_pEffect->SetTexture( "DiffuseTexture", g_Map.m_pTextures ) )
else
V( g_pEffect->SetTexture( "DiffuseTexture", g_pDefaultTex ) );

 V( g_pEffect->CommitChanges() );
V( pMesh->DrawSubset( i ) );

}
V( g_pEffect->EndPass() );
}
V( g_pEffect->End() );


In this step before seting the texture i want to get it's 3d coordinate. Does anyone has any idea about how can i get the 3d coordinate ? Thanks.
Advertisement
What do you mean by the "3D coordinate" of the texture? Do you mean that you want to get the position in world space of a particular texel?
NextWar: The Quest for Earth available now for Windows Phone 7.
Yes, i mean that.
I need to get x,y,z coordinate (position) of the texture in the 3D world space.
I don't think there's a particularly fast way to do this. I guess you could iterate through the index buffer, getting the texture co-ordinates of the 3 vertices which make that triangle, then seeing if the texel you want to get is in that triangle. Then transform those vertices into world space and use them to calculate the position of the texel. Also, keep in mind that more than 1 triangle can be mapped to use the same area on the texture. In other words, a single texel can be used multiple times, in multiple positions.

However, I really don't see a reason why you'd want to get the position of a particular texel. Tell us the entire problem, and why you want to get the position of a texel, and maybe we can help you devise a much simpler solution.
NextWar: The Quest for Earth available now for Windows Phone 7.
I have a very very huge mesh and i don't want to render all of the textures in every render loop.It's like a frustum culling what i am trying to do.But i don't want to make a complex frustum culling operation.I guess it would be enough to check textures distance to my camera before rendering and just process textures to close the player can see.
Calculating the positionn of every single texel and doing frustum culling on it is definately going to be slower than, well, anything.

From your post, I don't think you quite understand how this works. When you render your mesh, any vertices outside of the viewing frustum are automatically clipped by Direct3D. If your mesh is completely off the screen, for example, then all the vertices will be clipped and it won't even be touched by the pixel shader. So you don't need to worry about superflous texture lookups when the mesh, or part of it, is off-screen.

However, you might want to look at a technique called "mipmapping". It involves storing precomputed downsampled versions of a texture, and then when it comes to rendering time a mipmap is chosen based on distance from the camera. So objects far away will only sample from a 1x1 texture, while objects very close will sample from the full resolution texture.
NextWar: The Quest for Earth available now for Windows Phone 7.
Thanks for your answer.

This topic is closed to new replies.

Advertisement