Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

wxb1

dot3 bumpmapping woes

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

I apologize ahead of time if this is the wrong forum... I''m using dx7 and transforming/lighting my own vertices (not use hardware tnl) and I''m attempting to do dot 3 bumpmapping... For the most part it works except right now in my sample program, on the model I use, a vase, only one side of the model ever gets lit up even though the model is spinning. I also have one point light. The point light is static. But basically the point light seems to be rotating around with the object? To create the light vector I: a) I use the inverse world matrix (from the vase which causes it to spin) to tranform my light into model space. b) I subtract the model space vertex position from the model space light position to get the light vector. c) I the transform the light vector into tangent space and store it into the color value of my vertex... I''ve used two different tangent space creation routines and the problem persists so I don''t think it''s the tangent space routine. But it seems to be the creation of the light vector... but I don''t see anything wrong with light vector either... again if this is the wrong foruom please point me to the right one...

Share this post


Link to post
Share on other sites
Advertisement
I worked with normal maps few months ago. And i remember that i ran this problem too.

Some things don''t fully clear for me. But my version is:

When you set the light, its position is always in the world. So it must not transform. Just pick from the inv. matrix.

The tangent and binormal in model space, so light vec must be transform.

And that is all. Your problem is that some how your light moves in model space. So your light vec calc. is the problem. Get the transormed pos of the vertex then subtract the lightpos. That one will be the light vec.

Other:

Why are you still using Dx7 ?

How can you do normal map in Dx7 ?

Can you show me the tangent calc. routine ?

Share this post


Link to post
Share on other sites
>And that is all. Your problem is that some how your light
>moves in model space. So your light vec calc. is the problem.
>Get the transormed pos of the vertex then subtract the
>lightpos. That one will be the light vec.

Ok.. so transform the vertex and subtract the light position then transform the vector into tangent space... Is this what you think I should do? I''ll give it a try...

>Why are you still using Dx7 ?

I use an old engine which uses dx7... I plan on trying to upgrade it to dx9 one day soon....

>How can you do normal map in Dx7 ?

store the normal map in a texture, store light vector in color of vertex and use the dotproduct3 texture blending stage...

>Can you show me the tangent calc. routine ?

Yes.. I will post it....

Share this post


Link to post
Share on other sites
geBoolean GENESISCC geBody_CreateTangentSpace( const geBody *B )
{
geBody_Index VertexCount = B->XSkinVertexCount;

assert( B != NULL );
assert( geBody_IsValid(B) != GE_FALSE );

if ( B->XSkinTangentSpace ) return GE_FALSE;

if ( !B->XSkinTangentSpace )
{
geBody_TangentSpace **tempTS;
tempTS = (geBody_TangentSpace **) &B->XSkinTangentSpace;
*tempTS = GE_RAM_ALLOCATE_ARRAY ( geBody_TangentSpace, VertexCount );
}

if ( !B->XSkinTangentSpace ) return GE_FALSE;

{
geBody_Index FaceCount = B->SkinFaces[GE_BODY_HIGHEST_LOD].FaceCount;
const geBody_Triangle *SF = B->SkinFaces[GE_BODY_HIGHEST_LOD].FaceArray;
const geBody_XSkinVertex *SV = B->XSkinVertexArray;
const geBody_Normal *SN = B->SkinNormalArray;

memset(B->XSkinTangentSpace,0,sizeof(geBody_TangentSpace) * VertexCount );

{
geBody_TangentSpace *TS = B->XSkinTangentSpace;
geBody_Index i;
geBody_Index j;
geBody_Index k;

for ( i= 0; i < VertexCount; i++ )
{
geBoolean TangentSpaceCreated = GE_FALSE;

for ( j = 0; i < FaceCount; j++ )
{
for ( k = 0; k < 3; k++)
{
if ( i != SF[j].VtxIndex[k] ) continue;

//Compute tangent space for the vertex...

{
geBody_Index v1 = SF[j].VtxIndex[0];
geBody_Index v2 = SF[j].VtxIndex[1];
geBody_Index v3 = SF[j].VtxIndex[2];
const geBody_XSkinVertex *p1 = &SV[v1];
const geBody_XSkinVertex *p2 = &SV[v2];
const geBody_XSkinVertex *p3 = &SV[v3];
geFloat p1U = p1->XU + 10.0f;
geFloat p1V = p1->XV + 10.0f;
geFloat p2U = p2->XU + 10.0f;
geFloat p2V = p2->XV + 10.0f;
geFloat p3U = p3->XU + 10.0f;
geFloat p3V = p3->XV + 10.0f;
geBody_Index n1 = SF[j].NormalIndex[k];
const geBody_Normal *BodyNormal = &SN[n1];
const geVec3d *Normal = &BodyNormal->Normal;
geBody_Index vt = SF[j].VtxIndex[k];
geBody_TangentSpace *TSP1 = &TS[vt];
geVec3d AlignedVector;
geVec3d BaseVector1;
geVec3d BaseVector2;
geVec3d Tangent;
geVec3d Binormal;
geFloat UV[2];

geVec3d_Subtract(&p2->XPoint,&p1->XPoint,&BaseVector1);
geVec3d_Subtract(&p3->XPoint,&p1->XPoint,&BaseVector2);

if ( (p2U == p1U) || (p3U == p1U) )
{
if ( p2U == p1U )
{
UV[0] = ( p1V < p2V ) ? 1.0f : -1.0f;
UV[1] = 0.0f;
}
else if ( p3U == p1U )
{
UV[0] = 0.0f;
UV[1D = ( p1V < p3V ) ? -1.0f : 1.0f;
}
}
9 else
{
UV[0] = -p1U/(p2U-p1U);
UV[1] = -p1U/(p3U-p1U);

if ( UV[0] * UV[1] < 0.0f )
{
UV[0] = -UV[0];
UV[1] = -UV[1];
}
}

geVec3d_Scale(&BaseVector2,UV[1],&BaseVector2);
geVec3d_Scale(&BaseVector1,UV[0],&BaseVector1);
geVec3d_Subtract(&BaseVector2,&BaseVector1,&AlignedVector);

geVec3d_CrossProduct(Normal,&AlignedVector,&Tangent);
geVec3d_CrossProduct(Normal,&Tangent,&Binormal);

if ( ( (p1U-p3U) * (p2V-p3V) ) > ( (p2U-p3U) *(p1V - p3V) ) )
geVec3d_Scale(&Binormal,-1.0f,&Binormal);

geVec3d_Normalize(&Tangent);
geVec3d_Normalize(&Binormal);

geVec3d_Set(&TSP1->T,Tangent.X,Tangent.Y,Tangent.Z);
geVec3d_Set(&TSP1->B,Binormal.X,Binormal.Y,Binormal.Z);
geVec3d_Set(&TSP1->N,Normal->X,Normal->Y,Normal->Z);

TangentSpaceCreated = GE_TRUE;
}

//Compute tangent space for the vertex...

if ( TangentSpaceCreated ) break;
}

if ( TangentSpaceCreated ) break;
}

}
}
}

return GE_TRUE;
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
In d3d lights is transformed by the VIEW matrix (ie the "camera"
They are not transform by the WORLD matrix.

Share this post


Link to post
Share on other sites
Are you sure? the example I based this on certaintly moved the light into model space by transforming it by the inverse model matrix... since tangent space is in model space... I have to get the light into model space don''t I?

Share this post


Link to post
Share on other sites

  • 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!