Jump to content
  • Advertisement
Sign in to follow this  
sansured

Texture Coordinate

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!