hlsl bumpmapping - screwed up again!

Started by
6 comments, last by evanofsky 18 years, 10 months ago
In HLSL, what do I do with the normal I sample from the normal map? I mean, say I have the normal from the vertex shader in world space, and I have the normal from the normal map. What do I do? Do I just add them together and normalize the result? [Edited by - evanofsky on June 4, 2005 5:55:43 PM]
Advertisement
In the VS you use the tangent and binormal of the vertex in order to transform the light position from world space back to model space and get its direction. You pass that direction to the PS.

In the PS, the direction of the light is multiplied with the normal from the normal map. The resulting value is your final shade which is multiplied with the color value.

Luck!
Guimo

Yeah, you'll only use the normal from the vertex shader to help transform your normal map value to a useful space for lighting.

When you have the per-pixel normal from the normal map you can do any lighting calculation you want with it, just like you would with a normal from a vertex in old-style vertex lighting. You have to make sure it is transformed into the correct space with the rest of your lighting information though.
Thanks for the replies. Okay, so I need to generate some kind of tangent matrix in the VS that I multiply the light direction by in the PS. How do I go from "tangent and binormal" to "tangent matrix"?
There is lots of information about normal mapping on the web; off the top of my head, you could look at the "Bumpy Shiny Variations" demo from the NVidia SDK. But there are probably lots of better examples than that.
the shader is fairly easy, but you'll need to precalculate the tangent and normal vectors (the binormal is the cross product of the tangent and normal). This site on the derivation of the matrix is pretty good. You can skip most of the derivation part and just look at the equation for it near the bottom. I can't find the site that has the function already written out.
Aaaaaaaaaaahhhhhhhhhh... I get it now.

It works great! screenies in a little bit. For now, I'm tired.
Okay, so it was working last night, then I started it this morning and it's really screwed up. (Be patient with the slow server!) I have no idea what happened, especially since it was working fine yesterday. I've tried everything. It looks like something's wrong with the tangent/binormal/normal or something. See what you think.

This topic is closed to new replies.

Advertisement