Jump to content
  • Advertisement
Sign in to follow this  
tokaplan

Spherical environment mapping formula

This topic is 4845 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

Anybody knows a formula for calculating texture coordinates for spherical environment mapping? SDK gives one, but it doesn't seem to work very well to me.

Share this post


Link to post
Share on other sites
Advertisement
Try this:


D3DXMATRIX matRes = matWorld * matView;

for( int i = 0; i < NumVertices; i++ )
{
D3DXVECTOR3 N ( pvVertices.nx , pvVertices.ny , pvVertices.nz );

// Checking for back faces
if( N.x*matRes._13 + N.y*matRes._23 + N.z*matRes._33 > 0.0f )
continue;

// Assign the spheremap's texture coordinates
pvVertices.tu = ( 1.0f + ( N.x*matRes._11 + N.y*matRes._21 + N.z*matRes._31 ) ) * 0.5f;
pvVertices.tv = ( 1.0f - ( N.x*matRes._12 + N.y*matRes._22 + N.z*matRes._32 ) ) * 0.5f;
}

Share this post


Link to post
Share on other sites
Hmm.... Thank you, it works very well on large polygons, but on small ones reflection seems to be random and the environment map can not be recognized. May the polygon's size be a problem?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!