lighting problem

Started by zsele, October 12, 2012, 03:31:18 PM

Previous topic - Next topic

zsele

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:



i use opengl rendering and it has been added with this code:
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.

EgonOlsen

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.

zsele

yes, but every cube has this texture: http://dl.dropbox.com/u/6900766/stone.jpg
and i think it shuold look like this:http://dl.dropbox.com/u/6900766/light1.png
so i dont understand why have every cube a green and a dark side

EgonOlsen

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.

zsele

hm. Yes I said it's a stupid question:D thanks for your help

Thomas.

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.