GLSL: specular for point lights?

Oldtimer
Posts: 834
Joined: 2002.09
Post: #1
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.

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! Smile
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
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.
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #3
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! Smile
Quote this message in a reply
Apprentice
Posts: 13
Joined: 2006.10
Post: #4
I've found this tool very useful: http://developer.3dlabs.com/downloads/shadergen/
It can generate glsl code for specific fixed pipeline functionality.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Wonky specular in reflections TomorrowPlusX 4 2,942 Jun 1, 2008 05:55 AM
Last Post: Weebull
  Lighting a sphere with OpenGL lights (normals wrong?) cecilkorik 3 8,135 Dec 27, 2007 02:40 PM
Last Post: _ibd_
  Lights, Camera, Action... and textures BlueAvian 1 2,339 Jun 28, 2003 06:16 PM
Last Post: Feanor
  lights and fog ghettotek 5 3,654 Feb 9, 2003 10:32 AM
Last Post: Mark Levin