Problems with terrain generation

Started by
1 comment, last by Manteau 22 years, 9 months ago
Hi, I''m trying to get some terrain generation code working in DX8. I''ve basically ported the code from OpenGL Game Programming which generates terrain from a 32x32 bitmap lightmap. I can get the terrain to render (sort of) in the view, but it''s just completely black. I''ve tried lighting, ambient lighting, materials, etc, and it just stays black. Other polgygons or x files I import into the scene work fine, so I don''t understand what''s going on. Any ideas? Cheers, Manteau
Advertisement
I would hazard a guess and say that it''s because your vertex normals are facing the wrong way. DX lights only those surfaces that facing the light source, and it uses the VN to determine which way the surface is facing so... if your VN is facing the wrong direction, the surface has no light on it at all. Try changing the order in which you create your polygon vertices...

A....B
. . .
. . .
C....D

You should be using a clock-wise thingy, so you create your vertex data like so:

V1 = A
V2 = B
V3 = C
V4 = D
(if you''re using Triangle Strips, the even numbered triangles are automatically expected to be Anti-clockwise, so the second tri is made from B, C and D)
or
V1=A
V2=B
V3=C
V4=C
V5=B
V6=D
(if you''re using Triangle Lists).

A neat way to check if this is your problem is to put your light-sources ''underneath'' your terrain and then move your camera underneath and look upwards... if you see stuff, then it''s your vector normals pointing the wrong way. If you aren''t using VN''s at all then I think (but I could be wrong) that you will always get a black surface because DX gets sticky about unlit surfaces without them.


I have plenty of talent and vision, I just don''''t give a damn.
'Doing the impossible is kind of fun' - Walt Disney
Thanks.

I tried setting my normals for each vertex to (0,1.0f,0) - (pointing up for the Y axis) and there was no difference however.

I''ve had problems with normals before, and if the normals were wrong, shapes wouldn''t display at all until you rotated them, so maybe this isn''t the problem...

Wouldn''t the ambient light also cause objects to be lit regardless of normals?

Thanks,
Manteau

This topic is closed to new replies.

Advertisement