Sign in to follow this  
evanofsky

hlsl bumpmapping - screwed up again!

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this