Spherical environment mapping formula
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.
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;}
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?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement