shwhjw
07-20-2011, 08:29 AM
Hi,
I'm fairly new to GLSL, and have been following the set of .pdf tutorials by TyphoonLabs. I've had no problems until now; although it is a small one, the maths should work (in my mind) but computer says no...
I am on the directional light tutorial in chapter 3 (located here (http://www.opengl.org/sdk/docs/tutorials/TyphoonLabs/Chapter_3.pdf)), and do not quite understand something in the vertex shader:
varying vec4 diffuse;
void main()
{
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
vec3 normal = gl_Normal;
// directional light direction = its position
vec3 lightVector = normalize(gl_LightSource[0].position.xyz);
// nxDir will be the multiplier in the range of [0,1]
// to act as the diffuse scalar.
float nxDir = max(0.0, dot(normal, lightVector));
diffuse = gl_LightSource[0].diffuse * nxDir;
}
Whether the light's z position is positive (0,0,1) or negative (0,0,-1), the teapot model is always lit from the bottom. As the light's position is normalised to give the direction, I would have thought it would change?
http://img833.imageshack.us/img833/3729/teapot.png
Another thing is, if the vector is being normalised, surely the lighting shouldn't change at all by just changing the z value (e.g. from -1.0 to -0.5) as it's still pointing in the same direction, the unit vector should too? Yet there are changes.
I'm having to use ShaderMaker as the OpenGL Shader Designer would crash on startup, but surely that wouldn't affect something as trivial as this!
Any ideas? Thanks in advance,
Simon,
I'm fairly new to GLSL, and have been following the set of .pdf tutorials by TyphoonLabs. I've had no problems until now; although it is a small one, the maths should work (in my mind) but computer says no...
I am on the directional light tutorial in chapter 3 (located here (http://www.opengl.org/sdk/docs/tutorials/TyphoonLabs/Chapter_3.pdf)), and do not quite understand something in the vertex shader:
varying vec4 diffuse;
void main()
{
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
vec3 normal = gl_Normal;
// directional light direction = its position
vec3 lightVector = normalize(gl_LightSource[0].position.xyz);
// nxDir will be the multiplier in the range of [0,1]
// to act as the diffuse scalar.
float nxDir = max(0.0, dot(normal, lightVector));
diffuse = gl_LightSource[0].diffuse * nxDir;
}
Whether the light's z position is positive (0,0,1) or negative (0,0,-1), the teapot model is always lit from the bottom. As the light's position is normalised to give the direction, I would have thought it would change?
http://img833.imageshack.us/img833/3729/teapot.png
Another thing is, if the vector is being normalised, surely the lighting shouldn't change at all by just changing the z value (e.g. from -1.0 to -0.5) as it's still pointing in the same direction, the unit vector should too? Yet there are changes.
I'm having to use ShaderMaker as the OpenGL Shader Designer would crash on startup, but surely that wouldn't affect something as trivial as this!
Any ideas? Thanks in advance,
Simon,