Archived

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

laeuchli

Dot3 problems

Recommended Posts

Dear All, I'm having problems getting Dot3 working properly in my Dx8 engine. Here are the steps I'm taking. For my object, I load the mesh, generate the normals with D3DXComputeNormals, then generate tangent space with nVidia's CreateBasisVectors. After this, for each object, I translate the light position into object space just as is done in the nVidia examples: D3DXVECTOR3 lighpos(LightPos[0],LightPos[i][1],LightPos[i][2]); D3DXVECTOR3 lightDirection; //in world space D3DXVec3Normalize(&lightDirection, &lighpos); D3DXMATRIX world2obj; D3DXMatrixInverse(&world2obj, 0, &matWorld); D3DXVECTOR3 lightDirectionInObjectSpace; D3DXVec3TransformNormal(&lightDirectionInObjectSpace, &lightDirection, &world2obj); lightDirectionInObjectSpace=-lightDirectionInObjectSpace; // shader math requires that the light direction vector points towards the light. cgshad->SetParamValue(lightindex[i],&lightDirectionInObjectSpace); Afterward, I then use these two cg shaders to perform the lighting calcuations: VertO Out; float4 position=In.pos; float3x3 objToTangentSpace; objToTangentSpace[0][0]=In.tex1.x; objToTangentSpace[1][0]=In.tex1.y; objToTangentSpace[2][0]=In.tex1.z; objToTangentSpace[0][1]=In.tex2.x; objToTangentSpace[1][1]=In.tex2.y; objToTangentSpace[2][1]=In.tex2.z; objToTangentSpace[0][2]=In.tex3.x; objToTangentSpace[1][2]=In.tex3.y; objToTangentSpace[2][2]=In.tex3.z; float3 lightpos=mul(objToTangentSpace,light1.xyz); Out.pos = mul(ModelViewMatrix,In.pos); Out.dif.x=light1.x; Out.dif.y=light1.y; Out.dif.z=light1.z; Out.tex = In.tex; Out.tex1= In.tex; Out.tex2= .5*lightpos+.5; return Out; Pix Out; float4 color=(tex2D(BaseTexture,In.tex)); float4 normal=2*tex2D(NormalTexture,In.tex1)-.5; float4 lightvec=2*In.tex2-.5; Out.dif = color*((dot(normal,lightvec)));//tex2D(BaseTexture, In.tex)+normal; return Out; The problem is, that the lighting just isn't right. I have a cube, and some sides of the cube that can't both be light at the same time are, and other problems of that nature. Can anyone give me a hand, or at least a hint? Thanks, Jesse [edited by - laeuchli on March 5, 2003 4:37:28 AM]

Share this post


Link to post
Share on other sites