#### Archived

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

# dot3 lighting with vertex shader

This topic is 5870 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''ve been working on my dot3 lighting for over a week and I am confused on what format my vectors should be set: I''m trying to rotate my light into texture space. Are the tangent vectors supposed to be reletive to the vertex? For example, if the vertex is at 10,10,10, would an appropreate tangent vector be 11,10,10 or should it be 1,0,0. The same question goes for the normal about the normal? I''ve tried both ways, and my light shows up looking strange. If someone could post a tangent vector generator, and the appropriate dot3 vertex shader so I could compare mine with, that would be great. Thanks -Fred

##### Share on other sites
You''re talkinf about tangent vectors. What kind of lighting exactly are you trying to achieve ? Simple diffuse and specular normally do not require tangent vectors, just a simple dotproduct. Bump mapping is different, of course, are you trying to do the vertex setup for a per-pixel DOT3 bumpmapper ?

Normals are specified as relative direction vectors. So are tangent / binormal vectors. The position of the connecting vertex is not important for it''s normal, but it is used to calculate the light incidence ray. So (1,0,0) would be a valid normal for a point at (10,10,10).

If you could outline your lighting concept (equations), then I could perhaps be of some more help.

/ Yann

##### Share on other sites
I''m trying to do dot3 bumpmapping with diffuse and specular.

I ran my shader through the nvidia shader debugger, I''ll walk through one of my vertices:

Note, this object is my terrain, so the world transform is 0,0,0.

My vertex (v0) is at -55.0, 0, -50.0
My normal (v1) is -55.0, 1.0, -50.0
My Tangent (v3) is 1.0, 0.0, 0.0
My Binormal (v4) is 0.0, 0.0, -1.0
My Light (c12) is at 0.0, 1.0, 0.0
My Camera (c13) is at 0.0, 20.0, -30.0

For clarity, I''m just ignoring the normal that was supplied in the stream, and i''m calculating a new normal via cross product between v3 and v4.

From here, I get the half angle from the light to the camera, normalize it, transform it with my tangent vectors:

dp3 r8.x,r3,r2
dp3 r8.y,r4,r2
dp3 r8.z,r5,r2

where r3 is the tangent, r4 is the binormal, r5 is the normal, and r2 is the normalized half angle.

then I scale it to [0..1]
mad oD1.xyz, r8, c20, c20 //c20 is 0.5, 0.5, 0.5, 0.5

then do the exact same thing with the light, and store the result in 0D0:

dp3 r8.x, r3, c12
dp3 r8.y, r4, c12
dp3 r8.z, r5, c12

mad oD0.xyz, r8.xyz, c20, c20.

Any obvious problems there?

• 16
• 9
• 13
• 41
• 15