Lighting does not work correctly for small models?

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Andi|xng
Posts: 83
Joined: Thu Mar 24, 2005 10:49 pm
Location: Schrobenhausen, Germany
Contact:

Lighting does not work correctly for small models?

Post by Andi|xng »

I have a strange problem with lighting of small models. I searched for the problem in the forum, but could not find something, so here is my description:

Since I am using the unit "meter" in my game, most objects have only the size of about 2 units. Many models I am using use other units, so I have to scale them down. When I use lighting now, Irrlicht does not "smooth" the light dependent on the angle between the normal vector of the face and the light source - there are only two possibilities: 100% dark or 100% bright.

Is this caused by setScale? If yes, why? It does not make any sense to scale the normals too...?! If not, why does lighting not work for "small meshes"?

If you want to test the problem by yourself, it is very simple:
Just take the SpecialFX-Tutorial source file, then scale the room.3ds-node to 0.01f, 0.01f, 0.01f, and the camera node too (set it to position -0.50f, 0.50f, -1.50f). You will see: only 100% dark or 100% bright - no smoothing...

Any ideas?
Andi|xng
Posts: 83
Joined: Thu Mar 24, 2005 10:49 pm
Location: Schrobenhausen, Germany
Contact:

Post by Andi|xng »

This problem does not only appear with scaled meshes.
Create a small TestSceneNode-box with the width 2 or so... If the light source flies around it in a circle with radius of 10 or so, there is the same problem... If the light source is much further away (500 or so), it works...
Andi|xng
Posts: 83
Joined: Thu Mar 24, 2005 10:49 pm
Location: Schrobenhausen, Germany
Contact:

Post by Andi|xng »

More information:
Since I am using the Java-binding "Jirr", I could only test it with OpenGL and Irrlicht 0.10.
Andi|xng
Posts: 83
Joined: Thu Mar 24, 2005 10:49 pm
Location: Schrobenhausen, Germany
Contact:

Post by Andi|xng »

Here are two screenshots. They are from the exactly same program. The only things that are different are the scaling of the room.3ds (first screenshot: 1f, second screenshot: 0.01f) and the camera position (first screenshot: -50f, 50f, -150f, second screenshot: -0.50f, 0.50f, -1.50f).

Image
Correct "smooth" lighting

Image
Only 100% dark or 100% bright
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Re: Lighting does not work correctly for small models?

Post by niko »

Andi|xng wrote:Is this caused by setScale? If yes, why?
This is because the normals of the mesh are scaled too, when modifying the scale. And if your model has longer normals, it will simply get darker. That's not a bug in the engine, that's just how 3d engines work. However, there should be a new flag in the material structure which should make it possible that normals can be renormalized again, but that's a featues I would have to add to irrlicht.
You could work around this problem by not scaling your scene nodes but modifying the positions of the vertices in your meshes directly.
Andi|xng
Posts: 83
Joined: Thu Mar 24, 2005 10:49 pm
Location: Schrobenhausen, Germany
Contact:

Re: Lighting does not work correctly for small models?

Post by Andi|xng »

niko wrote: This is because the normals of the mesh are scaled too, when modifying the scale. [...] That's not a bug in the engine, that's just how 3d engines work.
I can not understand that. I thought normal vectors are completely independent from the size of the model - they just give information about the orientation of the faces. And I think the size of the faces is irrelevant for the normals...
"that's just how 3d engines work"... Maybe (don't know), but I can not find any example where this makes sense... It has nothing to do with reality?!

Let's say we have a big mirror. We can break it into smaller sharbs as often as we like, all mirror sharbs will work as a mirror like before, they have all the same normal vector...
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Re: Lighting does not work correctly for small models?

Post by niko »

Andi|xng wrote:I can not understand that. I thought normal vectors are completely independent from the size of the model
They need to get transformed by the same transformation matrix and so they get scaled too. But I'm going to add a feature to the next version where this problem will disappear if you like.
Andi|xng
Posts: 83
Joined: Thu Mar 24, 2005 10:49 pm
Location: Schrobenhausen, Germany
Contact:

Re: Lighting does not work correctly for small models?

Post by Andi|xng »

That would be great :) I've also heard from other people that have problems with this, so it would be really useful. Thank you, Niko.
Ishtm
Posts: 37
Joined: Mon May 09, 2005 8:03 pm

Post by Ishtm »

I have a similar problem but i don't know if is the same...
if a put a light and 6 spheres around in all directions y get 2 spheres trough
X axis correctly illuminated and the others wrong. The light isn't work like point light to me, because the 4 spheres wrong illuminated recive light from other sides and not from the point light. I haven't web server so i can't upload the image samples.
Andi|xng
Posts: 83
Joined: Thu Mar 24, 2005 10:49 pm
Location: Schrobenhausen, Germany
Contact:

Post by Andi|xng »

You can mail me the screenshots ( andi.wenger@gmx.de ), then I can upload them.
Andi|xng
Posts: 83
Joined: Thu Mar 24, 2005 10:49 pm
Location: Schrobenhausen, Germany
Contact:

Post by Andi|xng »

Here are the screenshots from Ishtm:

Image

Image
Ishtm
Posts: 37
Joined: Mon May 09, 2005 8:03 pm

Post by Ishtm »

sorry my problem isn't a bug at all!
the normals of the objects aren't transformed with same matrix of vertex.
So i aplied same transformation but without translation and they keep ok.
Andi|xng
Posts: 83
Joined: Thu Mar 24, 2005 10:49 pm
Location: Schrobenhausen, Germany
Contact:

Post by Andi|xng »

As it seems, everything works correct with Irrlicht 0.12.0 now, if I set EMF_NORMALIZE_NORMALS to true. Thank you very much for that feature, Niko :)
Post Reply