Skip to main content
gamedev.net
🔒 Locked

Global Normal Maps

Started by xerodsm 5 replies 800+ views
Original Post
xerodsm
xerodsm
I have been using 3D Studio Max to bake some normal maps and there is an option in max to bake them into world coordinates. Well I tried that, but now I'm having problems writing my GLSL frag and vert files. For some reason I can't seem to get the light_direction variable right. Other than that, I can just read in the normal information straight from the texture map and have the normals instantly. I'm wondering what the easiest way to get the exact vector from the light to a certain fragment so that I can dot that vector with my normal information and do the mapping that way. If not, is there any good way to use a world coordinate normal map? I also realize that they will only work for static objects but that's not a problem.
xerodsm
xerodsm
Maybe I'm not making myself very clear. Here's a pic of the texture map I'm using and then a pic of what the object looks like when it's rendered using the normal map as a diffuse map in the application.

http://filebox.vt.edu/users/rengle/stuff/normmap.jpg

http://filebox.vt.edu/users/rengle/stuff/normsphere.jpg
MARS_999
MARS_999
Links are broken
Jerax
Jerax
Pass the world space position of the light to the vertex shader. Use that to calculate the light vector at each vertex. Pass that to the fragment shader (as a texture co-ord). Each fragment will then get an interpolated light vector from the 3 verts that make up it's triangle. Because it's interpolated it'll probably not be unit length so you should normalise it using either a normalisation cube map or fragment shader arithmetic. You can then dot the light vector with your normal from the normal map and you have your lighting value.
xerodsm
xerodsm
Quote:
Original post by MARS_999
Links are broken


That's weird. What does it say? They seem to be working for me.
xerodsm
xerodsm
When I send it the light value it seems to work a bit better. But when I rotate around the sphere that is normal mapped, with my point light attached to the camera, it seems to make the light on the sphere rotate like a plane spinning instead of rotating with me, which makes me think somehow something is reversed. Any ideas?
xerodsm
xerodsm
Problem solved. My coordinates were mixed up since 3D Studio Max and OpenGL have different y and z axis. Thanks.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.