Hello all,
I’m building a first-person game using Panda3d and I have a question about the proper way to do lighting for a multi-layered scene. By multi-layered, I mean (as of now) the scene is all one model when exported from Blender to .egg, but the scene consists of multiple different “layers” of scenery which should cast shadows onto other parts of the scene. For example, there are cliff-walls, which should cast shadows upon the ground. But, they should also cast shadows upon the other cliff-walls.
The problem is that Panda3d doesn’t seem to support self-shading, or the scene being able to cast shadows upon itself. Or at least, I can’t seem to find anything about it. Everyone seems to be trying to avoid self-shading, but I actually want it in this case.
My solution I have in mind is to separate the scene into many objects, which all have their own models, and all come together to create the whole scene – that way they should be able to cast shadows on other parts of the scene, but this seems like a tedious solution, especially considering how many models I will have to split from the main scene model to get a desirable result.
My question is, is there a much better way to do this, without resorting to such brute-force tactics?
Thank you so much in advance, and I look forward to discussing with you and/or hearing what you have to say. Let me know if I can provide any additional information.
edit: by the way, I want to have both dynamic and baked lighting at once. I know I might have to write my own shader for this but I need it for my game, I think. It’s pretty integral to what I have in mind which involves mechanics where the player needs to manipulate light sources to illuminate the environment.
By default, Panda does not attempt to keep a model from shadowing itself. The caveat to this is that it does try to keep fragments/triangles from being their own occluder (and thus causing shadow acne) by rendering back faces instead of front faces. This thread goes more into shadows than you probably wanted to know. If you want to try using front faces for shadow casting, use this snippet from the linked forum thread:
light.setInitialState(a.getInitialState().removeAttrib(CullFaceAttrib))
CullFaceAttrib
is from panda3d.core
, however, I am not entirely sure what a
is supposed to be in this case.
As for light baking, Panda doesn’t really do anything to help or hinder this. I believe the auto shader supports multiple UVs, which is the common way to do light maps. You’ll probably want to bake a lightmap in Blender and then tweak texture stages in code when loading the level (unless the correct information is already described in the EGG file). You’ll want your diffuse, etc using UV1 and your light map being multiplied against the fragment color result (don’t know if there is a way to tell the auto shader to do this) and using UV2.
1 Like
Moguri,
Thanks for the reply. Unfortunately I’m actually quite new to all of this 3D stuff, so I’m having a hard time following what you mean.
By default, Panda does not attempt to keep a model from shadowing itself.

Hm… Actually, it seems that nothing is casting shadows, even if I split them up. I’m calling setShaderAuto() on all the rendered objects and I set setShadowCaster(True,512,512) on the directional light (coming from above and from the front in the above picture). But for some reason the shadows still aren’t working (it looks the same whether that rock is part of the scene or a separate model).
I think I’m actually missing something fundamental here.
EDIT: upon further investigation I’ve discovered that there is a lot more to set up for directional lights to work properly with shadows… I guess I’ve got a lot to do
EDIT 2: Actually, it seems all I needed was to call setNearFar and SetFilmSize on the directional light lens and it seems to be working for almost everything, but it still looks like the rock, of all things, is failing to cast any shadows. But I’ll keep tweaking the values…