Skip to main content
GameDev.net gamedev.net
🔒 Locked

lighting/Normal Problem with my terrian =(

Started by Metric Jul 31, 2002 at 2:37 PM 2 replies 250+ views
Original Post
Metric
Metric
ok well here is a screenshot of what it is doing. yendor.dyndns.org/screen2.jpg here is the code to generate the terrain and apply the normals ReDim HTerrian(((BmpInfo.biHeight * BmpInfo.biWidth) * 6)) As VERTEX For Y = 0 To BmpInfo.biHeight - 2 For X = 0 To BmpInfo.biWidth - 2 HTerrian(i).X = X HTerrian(i).Y = CSng(Pixels(X, Y).rgbBlue / 32) HTerrian(i).Z = Y i = i + 1 HTerrian(i).X = X HTerrian(i).Y = CSng(Pixels(X, Y + 1).rgbBlue / 32) HTerrian(i).Z = Y + 1 i = i + 1 HTerrian(i).X = X + 1 HTerrian(i).Y = CSng(Pixels(X + 1, Y).rgbBlue / 32) HTerrian(i).Z = Y i = i + 1 HTerrian(i).X = X HTerrian(i).Y = CSng(Pixels(X, Y + 1).rgbBlue / 32) HTerrian(i).Z = Y + 1 i = i + 1 HTerrian(i).X = X + 1 HTerrian(i).Y = CSng(Pixels(X + 1, Y + 1).rgbBlue / 32) HTerrian(i).Z = Y + 1 i = i + 1 HTerrian(i).X = X + 1 HTerrian(i).Y = CSng(Pixels(X + 1, Y).rgbBlue / 32) HTerrian(i).Z = Y i = i + 1 Next X Next Y i = 0 For i = 0 To UBound(HTerrian) If numpass = 2 Then numpass = 0 vNorm = GenerateTriangleNormals(HTerrian(i - 2), HTerrian(i - 1), HTerrian(i)) HTerrian(i - 2).nx = vNorm.X HTerrian(i - 2).ny = vNorm.Y HTerrian(i - 2).nz = vNorm.Z HTerrian(i - 1).nx = vNorm.X HTerrian(i - 1).ny = vNorm.Y HTerrian(i - 1).nz = vNorm.Z HTerrian(i).nx = vNorm.X HTerrian(i).ny = vNorm.Y HTerrian(i).nz = vNorm.Z End If numpass = numpass + 1 Next i and here is my NormalCalculater Code Public Function GenerateTriangleNormals(p0 As VERTEX, p1 As VERTEX, p2 As VERTEX) As D3DVECTOR ''//0. Variables required Dim v01 As D3DVECTOR ''Vector from points 0 to 1 Dim v02 As D3DVECTOR ''Vector from points 0 to 2 Dim vNorm As D3DVECTOR ''The final vector ''//1. Create the vectors from points 0 to 1 and 0 to 2 D3DXVec3Subtract v01, MakeVector(p1.X, p1.Y, p1.Z), MakeVector(p0.X, p0.Y, p0.Z) D3DXVec3Subtract v02, MakeVector(p2.X, p2.Y, p2.Z), MakeVector(p0.X, p0.Y, p0.Z) ''//2. Get the cross product D3DXVec3Cross vNorm, v01, v02 ''//3. Normalize this vector D3DXVec3Normalize vNorm, vNorm ''//4. Return the value GenerateTriangleNormals.X = vNorm.X GenerateTriangleNormals.Y = vNorm.Y GenerateTriangleNormals.Z = vNorm.Z End Function I would really appreciate it if you could help =)
Metric
Metric
*Bump*
ProtoPornoPants
ProtoPornoPants
Looking at what you''ve got, it looks like some of your vertex normals are pointing up and some are pointing down.

You need to be careful that both the triangles in each quad are drawn in the same direction (clockwise or counter clockwise - depending on the way your culling is set up). If some are clockwise and come are counter-clockwise (as it looks), then your normal caculation function will make the normals face opposite directions.

Rory.
Metric
Metric
ahh ty thats what it was =).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.