Converted Blender Mesh Lighting Problem

I’ve created a model in Blender which I’ve exported as a .x file and converted to an egg file. I am able to load in the mesh just fine, however, I cannot get it to react correctly to lighting. (The same thing happens in pview). When lighting is enabled, all color is washed out (The material color is yellow). The following image is what it looks like:

www.geocities.com/forsyth_john/duck.jpg

I am using the importexportsuite plug-in found on Blender’s site.

I know that it’s not the code I’m using as I can load the models that come with Panda just fine. Has anyone ran into this problem or have a suggestion?

It looks like the normals have gotten scaled up somehow. This has the effect of scaling the brightness of your lights. When the effective brightness of your lights is greater than 1.0, you get color oversaturation like this.

Panda is supposed to auto-scale the normals to unit length (which is required for lighting to work correctly), but there have been cases in which this fails for one reason or another. Sometimes it’s a faulty driver; sometimes it’s bad logic within Panda; sometimes it’s the user explicitly overriding the normal scaling.

The net color of your lights is less than or equal to 1.0, right?

If you post your .x file somewhere where I can download it, I might be able to determine at what point it’s going wrong.

David

I’ve posted the .x file here: www.geocities.com/forsyth_john/rubberduck.x .

As far as I know, I’m not exceeding the 1.0 limit on lighting.

This is the code I’m using:
dlight = DirectionalLight(‘dlight’)
dlight.setColor(VBase4(1, 0, 0, 1))
dlnp = render.attachNewNode(dlight.upcastToPandaNode())
dlnp.setHpr(0, -100, -100)
render.setLight(dlnp)

Though, again, my code works for other models.

Much appreciative of the help.

Ah, I was mistaken. The problem is not a scaling of normals; the problem was a bug in Panda’s X file converter, which was causing a misinterpretation of the “power” or “shininess” parameter of your material. It was reading this value as 0.0 instead of its proper value of 0.5, which was causing the colors to become oversaturated with the specular highlight color, white.

I will check in a fix to x2egg. In the meantime, you can hand-edit the egg file it produces, and change the line:


  <Scalar> shininess { 0 }

To:


  <Scalar> shininess { 0.5 }

(Or remove the specular component from your material altogether.)

David

Ah, that does help. Thanks.

Changing the specular shininess factor to less than 1.0 fixes the lighting so it isn’t oversaturated. Though, it may be my system, but for some reason, there is still the defined line between shade and light with no gradation. This goes away when specular is taken out.

This particular model doesn’t have very smooth normals. This is largely because the vertices are somewhat irregular and scattered randomly around the model. For a good specular lighting effect, it helps to have a much smoother, uniform mesh, with the vertices evenly distributed in a grid. Having a lot more vertices wouldn’t be bad, either. :slight_smile:

You can also make the specular value larger than 1.0. It can go as large as 128. But still, having any specular effect at all will tend to exaggerate the irregularity of the polygons.

David

From my personal experience, I was never able to get OpenGL speculars to look very good. However, using shaders for speculars looks great.