# www.jpct.net

## jPCT - a 3d engine for Java => Support => Topic started by: zsele on October 12, 2012, 03:31:18 pm

Title: lighting problem
Post by: zsele on October 12, 2012, 03:31:18 pm
hi

its probably a very stupid question, but i've just started use jpct. ::) So i made a world with cubes and added a (only one!) (green) light point over the red cube, but its look this:

(http://dl.dropbox.com/u/6900766/light.png)

i use opengl rendering and it has been added with this code:
Code: [Select]
`world.addLight(defaultPos[i], defaultColors[i]);`so i have no idea why looks all cube the same or what is this

Thanks and sorry for my and English.
Title: Re: lighting problem
Post by: EgonOlsen on October 12, 2012, 06:24:47 pm
It's totally normal behaviour. If you place a light source in the scene, it will light all objects until you set some attenuation and/or discard distance for it.
Title: Re: lighting problem
Post by: zsele on October 12, 2012, 07:41:59 pm
yes, but every cube has this texture: http://dl.dropbox.com/u/6900766/stone.jpg (http://dl.dropbox.com/u/6900766/stone.jpg)
and i think it shuold look like this:http://dl.dropbox.com/u/6900766/light1.png (http://dl.dropbox.com/u/6900766/light1.png)
so i dont understand why have every cube a green and a dark side
Title: Re: lighting problem
Post by: EgonOlsen on October 12, 2012, 08:05:09 pm
That's how vertex lighting works. The intensity of the light (from black to green in this case) is based on the angle between the vertex normals and the vector from the light to that vertex. The resulting light intensity is then interpolated across the triangle. The vertex normal is calulated as the average of the face normals of the adjacent faces. That means that the vertices with normals pointing towards the light are lit more and the vertices with normals pointing away from the light are lit less.
To get something similar to what you posted, you have to move the light up and set some attenuation. It won't look as perfect as in your image, but at least more like it.
Title: Re: lighting problem
Post by: zsele on October 12, 2012, 08:57:22 pm
hm. Yes I said it's a stupid question:D thanks for your help
Title: Re: lighting problem
Post by: Thomas. on October 12, 2012, 09:07:05 pm
For better results you have to create box in some modelling application, export to the OBJ file and load into your application. And do not forget to check, that you load normals from OBJ file.