Archived

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

wxb1

dot3 bumpmapping

Recommended Posts

I would appreciate any help that any one can give... I followed information I''v got from the powervr site and another site regarding generating the tangent space... I''ve followed it to letter but the results are not correct. I''ve got two problems. I''ll discuss the first one. Basically the light is rotating with the object that has normal map texture... I''ve tried different variations of the following code but nothing has worked as of yet... I surely would like some insight into my problem as I am not a math guru... void GENESISCC geBody_SetVertexColorDot3( geVec3d LightPosition, const geXForm3d *Mdl2WldXFA, const geBody *B, int16 VertexIndex, geFloat *ColorDot3,const geCamera *Camera ) { geBoolean NewLightPosition = GE_FALSE; geBoolean NewMsLightPosition = GE_FALSE; geBoolean NewMdl2Wld = GE_FALSE; geBoolean NewV = GE_FALSE; geBoolean NewTgt2Mdl = GE_FALSE; geBoolean NewB = GE_FALSE; static geBody_Index BoneIndex; static geVec3d Position; static geVec3d msLightPosition; static geVec3d tsLightPosition; static geVec3d tempv; static geVec3d v; static geXForm3d Mdl2Wld; static geXForm3d Mdl2Tgt; static geXForm3d invWld2Mdl; static const geBody *tempB; const geBody_TangentSpace *Mdl2TgtTS; const geBody_XSkinVertex *XVA; if ( !B->XSkinTangentSpace ) return; Mdl2TgtTS = B->XSkinTangentSpace; XVA = B->XSkinVertexArray; NewB = ( B != tempB ); { BoneIndex = -1; geVec3d_Clear(&Position); geVec3d_Clear(&msLightPosition); geVec3d_Clear(&tsLightPosition); geVec3d_Clear(&tempv); geVec3d_Clear(&v); geXForm3d_SetIdentity(&Mdl2Wld); geXForm3d_SetIdentity(&Mdl2Tgt); geXForm3d_SetIdentity(&invWld2Mdl); tempB = B; } //1. Compute model space light vector // a. Get light position NewLightPosition = (!geVec3d_Compare(&Position,&LightPosition,0.05f)); // if ( NewLightPosition ) geVec3d_Set(&Position,LightPosition.X, LightPosition.Y,LightPosition.Z); // b. Compute model space NewMdl2Wld = ( BoneIndex != XVA[VertexIndex].BoneIndex ); { BoneIndex = XVA[VertexIndex].BoneIndex; geXForm3d_Copy(&Mdl2WldXFA[BoneIndex],&Mdl2Wld); geXForm3d_GetTranspose (&Mdl2Wld,&invWld2Mdl); } NewMsLightPosition = ( NewLightPosition || NewMdl2Wld ); { geXForm3d_Transform (&invWld2Mdl, &Position, &msLightPosition); } // c. multiply model space by the vertex NewV = ( !geVec3d_Compare(&tempv,&XVA[VertexIndex].XPoint,0.05f) ); { geVec3d_Set(&tempv,XVA[VertexIndex].XPoint.X, XVA[VertexIndex].XPoint.Y,XVA[VertexIndex].XPoint.Z); geVec3d_Set(&v,tempv.X, tempv.Y,tempv.Z); geVec3d_Subtract(&msLightPosition,&v,&msLightPosition); geVec3d_Normalize(&msLightPosition); } NewTgt2Mdl = ( NewV ); { Mdl2Tgt.AX = Mdl2TgtTS[VertexIndex].T.X; Mdl2Tgt.AY = Mdl2TgtTS[VertexIndex].T.Y; Mdl2Tgt.AZ = Mdl2TgtTS[VertexIndex].T.Z; Mdl2Tgt.BX = Mdl2TgtTS[VertexIndex].N.X; Mdl2Tgt.BY = Mdl2TgtTS[VertexIndex].N.Y; Mdl2Tgt.BZ = Mdl2TgtTS[VertexIndex].N.Z; Mdl2Tgt.CX = Mdl2TgtTS[VertexIndex].B.X; Mdl2Tgt.CY = Mdl2TgtTS[VertexIndex].B.Y; Mdl2Tgt.CZ = Mdl2TgtTS[VertexIndex].B.Z; } //2. Compute tangent space light vector if ( NewTgt2Mdl || NewMsLightPosition) { // TODO: Does the matrix have to be orthogonal? geXForm3d_TransformNoOrthogonal (&Mdl2Tgt, &msLightPosition, &tsLightPosition); } //3. Convert light vector to color ColorDot3[0] = tsLightPosition.X * 127.5f + 127.5f; ColorDot3[1] = tsLightPosition.Y * 127.5f + 127.5f; ColorDot3[2] = tsLightPosition.Z * 127.5f + 127.5f; ColorDot3[3] = 0; }

Share this post


Link to post
Share on other sites
Ok I''ll try...

//1. Compute model space light vector

// a. Compute model space transform...
ModelSpaceBoneMatrix = Inverse(WorldSpaceBoneMatrixArray[BoneIndex]);

ModelSpaceLightPosition = WorldSpaceLightPosition * ModelSpaceBoneMatrix

// c. multiply model space by the vertex
ModelSpaceLightVector = ModelSpaceLightPosition - ModelSpaceVertexArray[VertexIndex];
ModelSpaceLightVector = Normalize(ModelSpaceLightVector);

//2. Compute tangent space light vector
TangetSpaceLightVector = ModelSpaceLightVector * TangentSpaceMatrixArray[VertexIndex];

//3. Convert light vector to color
ColorR = TangetSpaceLightVector.X * 127.5f + 127.5f;
ColorG = TangetSpaceLightVector.Y * 127.5f + 127.5f;
ColorB = TangetSpaceLightVector.Z * 127.5f + 127.5f;
ColorA = 0;

Share this post


Link to post
Share on other sites