HeightfieldTesselator & Directional Light

Hello,

I have a problem with directional light and the terrain generated by HeightfieldTesselator. It seems the y-axis of the terrain mesh is flipped. I hope the following two screenshots explain my problem:

http://www.dachau.net/users/pfrogner/right.jpg
http://www.dachau.net/users/pfrogner/left.jpg

In the first screenshot the directional light comes from the right ride of the scene (which is the positive y axis). The ball is lighted correctly, while the terrain seems to be lit from the left (negative y axis). In the second screenshot the light comes from the left, and again the ball is lit correctly while the tarrain seems to be lit from the right.

Has anybody else tried to use directional light with HeightfieldTesselator? If so, has there been the same problem? I’m not sure if I my code is right.

One thing I noticed is that when generating a terrain mesh using HeightfieldTesselator.generate( ) it is first located like this:

      ^ +Y
      |
      |
      |
 -----+----------------> +X
      |#########
      |#########
      |#########
      |#########
      |#########
      |         ( +256, -256 )
      |

The origin (pixel 0,0) is at position (0,0,0) in Panda3d coordiantes, and the last pixel (pixel 256,256) is at (256,-256,0) in Panda3d coordinates. At first I would have expected something like this:

      ^ +Y
      |
      |         ( +256, +256 )
      |#########
      |#########
      |#########
      |#########
      |#########
 -----+----------------> +X
      |
      |
      |

But the way Panda3d places the terrain is like most image formats store their data. The first pixel (0,0) is the upper left corner, and the last pixel is
the lower right corner.

When tranforming from Panda3d coordinates to pixel coordinates (for example when setting a new focal point) this means a -1 in the transformation of the y coordinate. Perhaps this is why the lighting seems to come from the wrong side.

Thank in advance,
enn0x

I believe you. It seems very likely indeed that I got the normals upside-down. I’ll fix this in panda3d 1.3.2

I should mention, though, that using vertex lighting in combination with dynamic-LOD terrain produces so-so results. You’re better off with a lightmap or per-pixel lighting.