Author Topic: Lighting problem on 2 Object3D side by side  (Read 1940 times)

Offline Pignic

  • byte
  • *
  • Posts: 10
    • View Profile
Lighting problem on 2 Object3D side by side
« on: November 15, 2012, 10:40:55 am »
Hello,

I have a strange light effect when I place two objects side by side as in this image :



My light source :
Code: [Select]
final Light sun = new Light(world);
sun.setIntensity(50, 55, 60);
sun.setDiscardDistance(3000);
sun.setPosition(new SimpleVector(500, 500, 2700));

My config of lights :
Code: [Select]
Config.lightMul = 1;
Config.fadeoutLight = false;
world.getLights().setRGBScale(Lights.RGB_SCALE_2X);
world.setAmbientLight(131, 138, 154);
world.getLights().setOverbrightLighting(Lights.OVERBRIGHT_LIGHTING_DISABLED);

What I put on all the objects to have a lighting effetc :
Code: [Select]
wall.build();
wall.setSpecularLighting(true);
wall.setLighting(Object3D.LIGHTING_ALL_ENABLED);

On this image, there are 6 objects : 3 angles and 3 walls.

Can anyone help me or tell me if I forgot some parameters ?

Thanks and best regards.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Lighting problem on 2 Object3D side by side
« Reply #1 on: November 15, 2012, 09:09:56 pm »
That's normal behaviour. Lighting is based on the vertex normals, which are based on an average of the surface normals of adjacent polygon of the same object. For example:



As you can see, the two normals n1 and n2 point in different directions. If you move these objects closer together, the difference in lighting that this causes will be noticable. See that n1 points towards the light, i.e. the vertex will be lit pretty well, while n2 points to the side, which makes that vertex less bright.
You can minimize this effect by increasing the polygon count of the objects. You can also try to model the objects in a modeller with different normals assigned and use the beta version of jPCT, which supports loading of normals from OBJ format. However, this might help in the case shown above but it won't in your case, because you can combine the objects in so many different ways that it's impossible to setup the normals in a way that they always fit.
I would go with more polygons first and see if it looks good enough.