Static lighting with GL_COLOR_ARRAY

Started by
22 comments, last by Megelan 19 years, 7 months ago
Again I've forgotten to ask something ^^
In case of a positional light source (point light) not
only the direction is important also the position should
play a role in the above calculation. But I can't the
a factor there which has something to do with the position
or have I missed something ? =|

I know my light source for the terrain is not positional
cause it's the sun and not a point light but would be nice
to know also the computation if
1. global light-model ambient is present
2. directional light source (ambient and diffuse) is present
3. positional light source (ambient and diffuse) is present

This should be the last thing I need to know about this
static lighting stuff with vertex colors...I hope *g*
Thx =)
Advertisement
The equation is the same for directional(infinite)lights like the sun and for point lights.The difference is that,while for the sun the Light vector is fixed,for point lights you have to calculate it:

L=normalize(Light_pos-Vertex_pos);

All of the vectors I mentioned in this post and my earlier ones will be in world coordinates,of course.
Well, in mikeman's post there's the light vector L, which points in the direction of the light source. If you have a directional source, all vertices would have the same L, but in the case of a positional one you would calculate different ones for each vertex (as light position - vertex position).
Quote:Original post by mikeman
The equation is the same for directional(infinite)lights like the sun and for point lights.The difference is that,while for the sun the Light vector is fixed,for point lights you have to calculate it:

L=normalize(Light_pos-Vertex_pos);


And how do I determine in case of directional light the
Light Vector L ? I mean I only have the position of the
directional light source and also OpenGL does not want
any direction vector so how does OpenGL compute directional
light without any direction vector just with the position ?
It must be a constant vector but I don't have one.

For the point lights, I think there must be another difference,
cause the attenuation is needed. I do not only need the
direction I also need the distance in the computation or
I won't be able to get any attenuation ?

Isn't it like this that the directional light source stuff has
also to be computed with L= normalize(Light_pos-Vertex_pos)
like the point light but the point light also has attenuation
and the directional has not ?

Well I just read in MSDN:
-----------------------------------------------------
The position is transformed by the modelview matrix when glLight is called (just as if it were a point), and it is stored in eye coordinates. If the w component of the position is 0.0, the light is treated as a directional source. Diffuse and specular lighting calculations take the lights direction, but not its actual position, into account, and attenuation is disabled. Otherwise, diffuse and specular lighting calculations are based on the actual location of the light in eye coordinates, and attenuation is enabled.
-----------------------------------------------------

So your right, directional light does not care about the
position but how is the Lightvector L computed ? I don't
have any direction I only have the position =|

And to the point lights, I also need the attenuation in
the computation =/

[Edited by - Megelan on August 26, 2004 2:53:50 PM]
If you supply the position with a zero w-coordinate, OpenGL interprets the light as directional (with the position you gave as the direction.)
A directional light doesn't have any attenuation (attenuation=1 in the below equation.)
For a positional light, multiply the light contribution by attenuation=1/(c+l*d+q^2)
Here c is constant, l is linear and q is quadratic attenuation.
d is the distance between the light's position and the vertex.

Expanding on the earlier post:
Diff=(L dot N)*(Ld*Md);
Ambient=(Ma*La);
Globalambient=Global ambient multiplied by material ambient.
VertexColor=GlobalAmbient+attenuation*(Diff+Ambient);
Quote:Original post by TomasH
If you supply the position with a zero w-coordinate, OpenGL interprets the light as directional (with the position you gave as the direction.)
A directional light doesn't have any attenuation (attenuation=1 in the below equation.)
For a positional light, multiply the light contribution by attenuation=1/(c+l*d+q^2)
Here c is constant, l is linear and q is quadratic attenuation.
d is the distance between the light's position and the vertex.

Expanding on the earlier post:
Diff=(L dot N)*(Ld*Md);
Ambient=(Ma*La);
Globalambient=Global ambient multiplied by material ambient.
VertexColor=GlobalAmbient+attenuation*(Diff+Ambient);


ah ok =))) Thank you very much.
And how is the fixed LightVector L computed for directional
light ? OpenGL computes it if the w-coordinate is zero which
indicates directional light as you already mentioned. But
how is this fixed L computed if it's the same for ALL
vertices ? =/
Oh, sorry, I wasn't very clear there.
If you supply (x,y,z,0) to OpenGL, as a light position, OpenGL will interpret it as a direction - i.e. that L is (x,y,z) for that light.
Quote:Original post by Megelan

And how do I determine in case of directional light the
Light Vector L ? I mean I only have the position of the
directional light source and also OpenGL does not want
any direction vector so how does OpenGL compute directional
light without any direction vector just with the position ?


Directional lights don't have position,all they got is direction.And the direction is not computed,you just supply it.In your case(the sun),the direction would be parallel to the y-axis.I think it is:LightVector=(0,1,0).
Quote:Original post by TomasH
Oh, sorry, I wasn't very clear there.
If you supply (x,y,z,0) to OpenGL, as a light position, OpenGL will interpret it as a direction - i.e. that L is (x,y,z) for that light.


ahhhhhhhhhhhhh yes of course that's it !!!! =D

Thank you so much ! You both helped me a lot :)
With this knowledge I'll try tomorrow to write
a function which returns me the desired vertex color
for given global light parameters, positional and
directional light sources.
Quote:Original post by TomasH
For a positional light, multiply the light contribution by attenuation=1/(c+l*d+q^2)
Here c is constant, l is linear and q is quadratic attenuation.
d is the distance between the light's position and the vertex.


I'm just implementing the whole static lighting stuff
and recognized a little error in the attenuation.
It has to be

attenuation= 1 / (c + l*d + q*d^2)

:)

This topic is closed to new replies.

Advertisement