Author Topic: Lighting issue  (Read 3783 times)

Offline mystara

  • int
  • **
  • Posts: 79
    • View Profile
Lighting issue
« on: July 06, 2007, 10:37:15 pm »
Hello,

I'm having a bit of difficulty adding lighting to a simple hollowed out box that I've made.
The 3DS file can be found at: http://alan.alwebwiz.net/basicroom.3ds
and the light I'm trying to add is: theWorld.addLight(new SimpleVector(54, 0, -228), 50, 50, 100);

(For the curious).

The problem I'm having is that in adding this light, two opposite walls of my cube are lit. The other faces remain entirely unlit, which seems rather confusing to me - or is this how it is supposed to behave?

I've also noticed that in setting the ambient lighting to (25,25,25) the above light source turns from a nice blue to a bright white light (although otherwise the ambient lighting seems to behave). Again, this seems a little strange to me. Should the overall environment not get a little lighter, but the light source remain blue?

Any ideas?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Lighting issue
« Reply #1 on: July 06, 2007, 11:07:41 pm »
Lighting behaviour depends on the lighting mode (i.e. if you are using OpenGL lighting or the legacy one of the old software mode). Outcome also depends on the rgb-scaling and (if software renderer is being used) on the overbright lighting setting. It's also important to know if the light source fades out or not and if the discard distance is set to anything else than -1. So it's difficult to tell, what exactly the problem is in your case. A few screenshots may help.

Offline mystara

  • int
  • **
  • Posts: 79
    • View Profile
Re: Lighting issue
« Reply #2 on: July 07, 2007, 11:13:19 am »
Hi,
Thanks for the reply.

In all the screenshots I've shown below, the following settings are used:

buffer.enableRenderer(IRenderer.RENDERER_OPENGL, IRenderer.MODE_OPENGL);
Config.fadeoutLight = true;
Config.linearDiv = 100;
Config.farPlane = 500;
theWorld.getLights().setOverbrightLighting(Lights.OVERBRIGHT_LIGHTING_DISABLED);
theWorld.getLights().setRGBScale(Lights.RGB_SCALE_2X);
theWorld.setFogging(World.FOGGING_ENABLED);
theWorld.setFogParameters(500, 0, 0, 0);

(Not sure whether fogging has any relevance here or not)

The first screenshot shows what happens when I have discard distance at 350, ambient light at 25, 25, 25 and a single light source:
theWorld.addLight(new SimpleVector(54, 0, -228), 50, 50, 100)
As you can see, the walls on the left and right are lit, but none of the other walls are. Despite the fact that the light source should be in the center of the area (assuming I've placed it correctly)


This second screenshot is another view of the first screenshot


Third screenshot occurs when I then set the discard distance to -1. Suddenly the back wall becomes blue. Although the floor still remains unlit. Again, the distance from the light source to the floor should be much smaller than to the wall with the arches - yet they get lit and the floor does not.


Finally, the fourth screenshot has the ambient light removed. The extra weirdness here (which is also present in the previous shot - albeit less obvious) is that the area between my two arches is not lit in the same way as the arches themselves, which again seems rather odd.


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Lighting issue
« Reply #3 on: July 07, 2007, 01:45:40 pm »
Looks fine to me. The "problem" with setting the discard distance to 350 is, that it decides on the distance to the first vertex of a polygon if it should discard it or not. It's not calculating a weighted average or something. So it can happen that one polygon gets discarded while its neighbor doesn't..i think that this is what happens in your case. The difference in lighting when playing around with ambient setting seems to lie in the different tesselation of the lit sections plus the normals' direction used to calculate the lighting. The lighting is based on vertex normals. A vertex normal is calculated as the weighted average of the face normals of all adjacent polygons. In case of the "corner" for example, the vertex normal will point 45 out of the corner (i.e. almost to the camera in this screenshot). The center-arch-part looks like as if the normal points into another direction which result in different lighting intensity.
To improve quality of vertex lighting, you may increase tesselation (and reduce performance).

Offline mystara

  • int
  • **
  • Posts: 79
    • View Profile
Re: Lighting issue
« Reply #4 on: July 07, 2007, 03:04:28 pm »
Hi,

Forgive my newbishness, but my understanding of tessellation was that involved splitting a complex polygon in to smaller ones.
Is this something that JPCT can do automatically? I've tried various settings with triangles and triangle strips, but it doesn't seem to improve the quality of the lighting.

Or do I need to modify the model?

I'm also still not certain why the floor appears unlit. Even when moving the light source to (54, 80, -228) (a very distance from the floor) the floor is unlit.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Lighting issue
« Reply #5 on: July 07, 2007, 03:42:39 pm »
Yes, it's about splitting the polygon into smaler ones. You have to do this in the modelling software or write your own code to do this (which can get quite complex). There's no build in tesselation stuff in jPCT.
I don't know how large the floor is...its corner may be too dark because they are too far away from the lightsource!? One thing to remember when using vertex lighting is, that no part of a polygon can be brighter than its corners. The lighting is calculated for corners only and then interpolated across the polygon. Once you understand the implications that arise from this fact, you'll better understand why a lit scene looks like it does. If it helps, i can have a closer look on your model on monday.

Offline mystara

  • int
  • **
  • Posts: 79
    • View Profile
Re: Lighting issue
« Reply #6 on: July 08, 2007, 12:25:34 pm »
Hi,

Thanks for your help...

I took my simple model and split the polygons (there are, I think, about 10 in those examples) in to much smaller ones - all hail Blender's split functionality - now if I can only make it work with every Object at once.

And things started improving. The arch is still a bit weird, but I haven't tried splitting that up yet.

One thing that confused me for a while was that the light intensity controls amount of light as well as the shade. So lights of (20, 20, 200) are almost entirely white (with little patches of blue). I still haven't figured out exactly how that works. Suffice to say it is not like the HTML colour tables where the proportions of the numbers control the shade :)

Trial and error seems the way to go :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Lighting issue
« Reply #7 on: July 08, 2007, 12:35:59 pm »
There also a setting called lightMul in Config that has an influence on intensity. Maybe you want to adjust it.