I’m having some issues with DirectionalLight and I’m not sure if it’s the light or my normal generation that’s the problem. I generate a normal for each vetex based on 8 surrounding points. I have the following code for generating a normal for each vertex:
public Vector3f calculateNormal(float x, float y, float z) {
// We'll add/subtract this to/from x and z to find our surrounding 8 points
int vectorCalcRadius = scale;
// Points
Point3f a = new Point3f(x, y, z),
b =
new Point3f(
x,
terrain.getY(x, (z + vectorCalcRadius)),
z + vectorCalcRadius),
c =
new Point3f(
x + vectorCalcRadius,
terrain.getY(
(x + vectorCalcRadius),
(z + vectorCalcRadius)),
z + vectorCalcRadius),
d =
new Point3f(
x + vectorCalcRadius,
terrain.getY((x + vectorCalcRadius), z),
z),
e =
new Point3f(
x + vectorCalcRadius,
terrain.getY(
(x + vectorCalcRadius),
(z - vectorCalcRadius)),
z - vectorCalcRadius),
f =
new Point3f(
x,
terrain.getY(x, (z - vectorCalcRadius)),
z - vectorCalcRadius),
g =
new Point3f(
x - vectorCalcRadius,
terrain.getY(
(x - vectorCalcRadius),
(z - vectorCalcRadius)),
z - vectorCalcRadius),
h =
new Point3f(
x - vectorCalcRadius,
terrain.getY((x - vectorCalcRadius), z),
z),
i =
new Point3f(
x - vectorCalcRadius,
terrain.getY(
(x - vectorCalcRadius),
(z + vectorCalcRadius)),
z + vectorCalcRadius);
// Co-planar vectors
Vector3f ab = new Vector3f(),
ac = new Vector3f(),
ad = new Vector3f(),
ae = new Vector3f(),
af = new Vector3f(),
ag = new Vector3f(),
ah = new Vector3f(),
ai = new Vector3f();
ab.sub(a, b);
ac.sub(a, c);
ad.sub(a, d);
ae.sub(a, e);
af.sub(a, f);
ag.sub(a, g);
ah.sub(a, h);
ai.sub(a, i);
// Surface normal vectors
Vector3f bc = new Vector3f(),
cd = new Vector3f(),
de = new Vector3f(),
ef = new Vector3f(),
fg = new Vector3f(),
gh = new Vector3f(),
hi = new Vector3f(),
ib = new Vector3f();
bc.cross(ab, ac);
cd.cross(ac, ad);
de.cross(ad, ae);
ef.cross(ae, af);
fg.cross(af, ag);
gh.cross(ag, ah);
hi.cross(ah, ai);
ib.cross(ai, ab);
bc.normalize();
cd.normalize();
de.normalize();
ef.normalize();
fg.normalize();
gh.normalize();
hi.normalize();
ib.normalize();
// Normalized sum of vectors
Vector3f n = new Vector3f();
n.add(bc);
n.add(cd);
n.add(de);
n.add(ef);
n.add(fg);
n.add(gh);
n.add(hi);
n.add(ib);
n.normalize();
return n;
}
as for the light…
DirectionalLight dlight = new DirectionalLight();
dlight.setDirection(new Vector3f(1.f, -1.f, 1.f));
and as for the material on the object…
Material mat = new Material();
mat.setDiffuseColor(1.f, 1.f, 1.f);
mat.setAmbientColor(0.7f, 0.7f, 0.7f);
mat.setLightingEnable(true);
The result is close but as you’ll see there are some issues. Notice the big white splotches on certain points in the terrain? What’s up with that?
See the white on the mountain in the foreground and the chain in the background.
http://www.janusresearch.com/~michael.wright/projects/npst/terrain_lighting_test_02.png
Closeup on the chain…
http://www.janusresearch.com/~michael.wright/projects/npst/terrain_lighting_test_01.png
Any thoughts?

