GLSL: specular for point lights?
I'm trying to setup a basic lighting shader to just mimic the fixed functionality, as a basis to build from. I've got two lights in it, but for the sake of simplicity, I've scaled it back to a single point light with just a specular component. This doesn't produce what I expect, which leads me to suspect that something is afoot with my half vector.
fillLightDir is the vector from the vertex to the point light's position, and it is correct. (When I render just the diffuse component, I get the expected result.)
I guess my culprit is the calculation of the half-vector. I tried using the one calculated by GLSL in gl_LightSource[i].halfvector, but that is off as well. (I suppose it only works for directional lights?)
I have an orthographic projection setup, the camera is never translated, although I do translate and rotate the objects that are being rendered. Is it then correct to take the eye vector as -worldVertex (the vertex' position in world-space)? My reasoning is that it is (cameraPosition - worldVertex), where cameraPosition is vec3(0)...
Any insight would be appreciated!
Code:
if (nDotLFill > 0.0)
{
vec3 eyeVector = -worldVertex;
vec3 halfVector = normalize (eyeVector + fillLightDir);
float nDotHVFill = max (dot (normal, halfVector), 0.0);
fillSpecular = vec3 (pow (nDotHVFill, gl_FrontMaterial.shininess));
}
gl_FrontColor = vec4 (fillSpecular, gl_FrontMaterial.diffuse.a);
fillLightDir is the vector from the vertex to the point light's position, and it is correct. (When I render just the diffuse component, I get the expected result.)
I guess my culprit is the calculation of the half-vector. I tried using the one calculated by GLSL in gl_LightSource[i].halfvector, but that is off as well. (I suppose it only works for directional lights?)
I have an orthographic projection setup, the camera is never translated, although I do translate and rotate the objects that are being rendered. Is it then correct to take the eye vector as -worldVertex (the vertex' position in world-space)? My reasoning is that it is (cameraPosition - worldVertex), where cameraPosition is vec3(0)...
Any insight would be appreciated!

Not directly helpful, but if you're going to be doing GLSL stuff, a copy of the Orange Book is a very helpful thing to have on-hand! It includes a comprehensive reference, as well as a substantial number of useful examples.
The Cg book you can download from NVidia is also helpful -- not that the syntax is identical, but the shader concepts are of course the same.
The Cg book you can download from NVidia is also helpful -- not that the syntax is identical, but the shader concepts are of course the same.
Yeah, I have the OB, but the point light sample doesn't work for me. I think it has to do with the order in which I transform the vertices and the lights. I'm going to restructure and reorder my transforms and see if it works better. Thanks, though!

I've found this tool very useful: http://developer.3dlabs.com/downloads/shadergen/
It can generate glsl code for specific fixed pipeline functionality.
It can generate glsl code for specific fixed pipeline functionality.
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
Wonky specular in reflections | TomorrowPlusX | 4 | 4,333 |
Jun 1, 2008 05:55 AM Last Post: Weebull |
|
Lighting a sphere with OpenGL lights (normals wrong?) | cecilkorik | 3 | 10,871 |
Dec 27, 2007 02:40 PM Last Post: _ibd_ |
|
Lights, Camera, Action... and textures | BlueAvian | 1 | 3,092 |
Jun 28, 2003 06:16 PM Last Post: Feanor |
|
lights and fog | ghettotek | 5 | 5,034 |
Feb 9, 2003 10:32 AM Last Post: Mark Levin |