www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: IZACIZAC on January 20, 2014, 11:12:09 pm

Title: lighting problem
Post by: IZACIZAC on January 20, 2014, 11:12:09 pm
Hi, I have a textured model and a light in my scene

Code: [Select]
level.compileAndStrip();
l = new Light(world);
l.setAttenuation(800);
l.setIntensity(200, 200, 200);

my light follows my camera
l.setPosition(camera.cam.getPosition());


I found though that because I was using one single poly for a huge wall, when I went near the center the wall lost all light, presumably because of how vertex lighting works, no light reached any of the corners.

(http://i.imgur.com/K0KGYh3.png)

So I split my wall into several individual peices (seperated by the beams running either way). attenuation is set to -1 in this screenshot. The result was fine for the middle parts, but the bottom and top row seem to be working the opposite way? Points nearest the camera, and so light source, are darkest?

(Also, does JPCT triangulate models when you load one in?)
Title: Re: lighting problem
Post by: EgonOlsen on January 21, 2014, 07:49:33 am
That's also caused by the way in which vertex lighting works. It calculates the light's intensity based angle between the vertex normal and the vector from the vertex to the light. The vertex normal is usally calculated when calling build() based on the average of the surface normals of adjacent faces. Depending on the structure of the mesh, this can look sub-optimal in some cases. If you have normals assigned (or calculated) in your modelling program, you can export as OBJ and set http://www.jpct.net/doc/com/threed/jpct/Config.html#useNormalsFromOBJ (http://www.jpct.net/doc/com/threed/jpct/Config.html#useNormalsFromOBJ) to true before loading the file. That will skip jPCT's own calculation and use the normals from the file instead.

Edit:

Quote
Also, does JPCT triangulate models when you load one in?
Nope, it doesn't.
Title: Re: lighting problem
Post by: IZACIZAC on January 21, 2014, 07:39:39 pm
Oh I see, thanks. Importing then re-exporting from Blender gave it perfect normals