Author Topic: lighting problem  (Read 803 times)

Offline IZACIZAC

  • byte
  • *
  • Posts: 19
    • View Profile
lighting problem
« 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.



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?)
« Last Edit: January 21, 2014, 07:29:23 am by IZACIZAC »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: lighting problem
« Reply #1 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 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.

Offline IZACIZAC

  • byte
  • *
  • Posts: 19
    • View Profile
Re: lighting problem
« Reply #2 on: January 21, 2014, 07:39:39 pm »
Oh I see, thanks. Importing then re-exporting from Blender gave it perfect normals
« Last Edit: January 21, 2014, 11:46:39 pm by IZACIZAC »