In OpenGL I can specify an ambient color not only for the whole scene (e.g. glLightModelf(GL_LIGHT_MODEL_AMBIENT, …)), but also for a point light (glLightfv(GL_LIGHT0, GL_AMBIENT, …). The difference between the two is that for the point light also the attenuation factor is applied, which is not the case for the global ambient light. I would need that in my program but cannot find any way to that in Panda3d. Is there any way to achieve this also in Panda3d?
This is briefly explained in the first part of this manual page: panda3d.org/manual/index.php/Lighting .
Basically you do what you always do, but call setLight() only on the node you want to be lit. This should work for both ambient- and point lights
@Nemesis: I don’t think that was his question.
@ezander: Panda sets the GL_AMBIENT for point lights always to (0, 0, 0, 1). The ambient component of a light should, as far as I know, be set separately using an additional AmbientLight, which can be applied to specific nodes if you want.
@rdb Right, I could do that. However, I could not have the attenuation factor, I can have for the diffuse and specular components of a point light and that would make for some pretty clumsy code.
Anyway, I figured out now, that it’s simply not possible in panda. E.g. in glGraphicsStateGuardian_src.cxx you can find for point lights
GLP(Lightfv)(id, GL_AMBIENT, black.get_data()); GLP(Lightfv)(id, GL_DIFFUSE, get_light_color(light_color, light_obj)); GLP(Lightfv)(id, GL_SPECULAR, light_obj->get_specular_color().get_data());
and you won’t find any call that uses
GL_AMBIENT with something different from
black.get_data(). I am still wondering, however, why they didn’t put that in (ambient color for point lights is also in Direct3d). Would it be worthwhile to do it myself and send in a patch?
I don’t know, but there’s probably a reason. Does it make sense to add it? Are you sure that the ambient colour is attenuated?
If it does offer a benefit, it would not be difficult to add the functionality.
That’s what the red book says:
(see http://www.glprogramming.com/red/chapter05.html). So I’m pretty sure, that the ambient light is attenuated if it’s originating from a normal light source and not the global light model.
If there’s a reason that this hasn’t been added, I would really like to know that. Especially, as you also say, it wouldn’t be difficult to add it.
I think the reason is, no one’s ever asked for it before. Actually, I didn’t even realize that point light ambient color was attenuated, and I’ve never heard of anyone taking advantage of this before.
But, sure, I’ve got no problem with adding support for this feature.
I would appreciate it if you could file a bug report about this It’s hard for me to keep track of forum threads with all the spam problems going on lately.