Original Post
I've got some shaders for doing per-pixel lighting from point, spot and directional light sources. Currently I do all my lighting calculations in world space: light parameters are specified in world-space by the application, and the vertex shader passes along the interpolated world position and normal to the pixel shader. Everything seems to work fine with this approach.
I want to add support for normal maps next though, which I guess will require doing all the lighting in tangent space instead, and will require me to pass interpolated tangent-space light parameters to the pixel shaders. As a warm-up, before actually using normal maps, I thought I would adjust my existing code to do lighting in object space instead: interpolate local positions and normals instead of world space ones, as well as object space light parameters.
I thought this would be as simple as running the global (as in global shader params) light position and direction through the inverse world matrix in the vertex shader and using these in my lighting calculations instead of the global light params like I currently do. Additionally of course I'm passing along the object space position and normal now without transforming by the world matrix.
Perhaps needless to say, this isn't working. What lighting I can still see appears to be coming from the correct locations but the intensity is very low (which I suppose indicates a problem with the directions). I've made sure to normalize the interpolated light dir in the pixel shader so that can't be the cause.
I haven't ruled out simple typos in the code that could be tripping everything up, but before I spend a lot of time debugging I just wanted to share my story and make sure this is a sound approach I'm taking here (and that I'm going about it correctly).
I'm in a bit of a hurry, but I can post code later if anyone wants to take a look. Thanks for any advice anyone can offer.
I want to add support for normal maps next though, which I guess will require doing all the lighting in tangent space instead, and will require me to pass interpolated tangent-space light parameters to the pixel shaders. As a warm-up, before actually using normal maps, I thought I would adjust my existing code to do lighting in object space instead: interpolate local positions and normals instead of world space ones, as well as object space light parameters.
I thought this would be as simple as running the global (as in global shader params) light position and direction through the inverse world matrix in the vertex shader and using these in my lighting calculations instead of the global light params like I currently do. Additionally of course I'm passing along the object space position and normal now without transforming by the world matrix.
Perhaps needless to say, this isn't working. What lighting I can still see appears to be coming from the correct locations but the intensity is very low (which I suppose indicates a problem with the directions). I've made sure to normalize the interpolated light dir in the pixel shader so that can't be the cause.
I haven't ruled out simple typos in the code that could be tripping everything up, but before I spend a lot of time debugging I just wanted to share my story and make sure this is a sound approach I'm taking here (and that I'm going about it correctly).
I'm in a bit of a hurry, but I can post code later if anyone wants to take a look. Thanks for any advice anyone can offer.