why is my terrain lighting so jagged?




Hi,

I am trying to calculate the normals for my terrain, and it's nearly
there, it's a big improvement on what I've had, but the lighting is
jagged. There's a picture here:

http://austere3d.gallery.netspace.net.au/Terrain/JAGGED

I loop through the rows/columns and in the loop I do this:

i = VertexIndex + ((row + 1) * Me.LevelOfDetailX + 1) + col
Dim p0 As New Vector3(Main3DEngine.VertexData(i).X,
Main3DEngine.VertexData(i).Y, Main3DEngine.VertexData(i).Z)
i = VertexIndex + ((row + 0) * Me.LevelOfDetailX + 1) + col
Dim p1 As New Vector3(Main3DEngine.VertexData(i).X,
Main3DEngine.VertexData(i).Y, Main3DEngine.VertexData(i).Z)
i = VertexIndex + ((row + 0) * Me.LevelOfDetailX + 1) + col + 1
Dim p2 As New Vector3(Main3DEngine.VertexData(i).X,
Main3DEngine.VertexData(i).Y, Main3DEngine.VertexData(i).Z)
i = VertexIndex + ((row - 1) * Me.LevelOfDetailX + 1) + col
Dim p3 As New Vector3(Main3DEngine.VertexData(i).X,
Main3DEngine.VertexData(i).Y, Main3DEngine.VertexData(i).Z)
i = VertexIndex + ((row - 1) * Me.LevelOfDetailX + 1) + col + 1
Dim p4 As New Vector3(Main3DEngine.VertexData(i).X,
Main3DEngine.VertexData(i).Y, Main3DEngine.VertexData(i).Z)
i = VertexIndex + ((row + 1) * Me.LevelOfDetailX + 1) + col - 1
Dim p5 As New Vector3(Main3DEngine.VertexData(i).X,
Main3DEngine.VertexData(i).Y, Main3DEngine.VertexData(i).Z)
i = VertexIndex + ((row) * Me.LevelOfDetailX + 1) + col - 1
Dim p6 As New Vector3(Main3DEngine.VertexData(i).X,
Main3DEngine.VertexData(i).Y, Main3DEngine.VertexData(i).Z)
n1 = ComputeNormal(p0, p1, p2)
i = VertexIndex + ((row + 0) * Me.LevelOfDetailX + 1) + col
n2 = ComputeNormal(p1, p3, p4)
n3 = ComputeNormal(p1, p4, p2)
n4 = ComputeNormal(p5, p1, p0)
n5 = ComputeNormal(p5, p6, p1)
n6 = ComputeNormal(p6, p3, p1)
n = New Vector3((n1.X + n2.X + n3.X + n4.X + n5.X + n6.X) / 6, (n1.Y +
n2.Y + n3.Y + n4.Y + n5.Y + n6.Y) / 6, (n1.Z + n2.Z + n3.Z + n4.Z +
n5.Z + n6.Z) / 6)
Main3DEngine.VertexData(i).SetNormal(n)

where p1 is the actual vertex I am calculating the normal for.

I'm trying to calculate per-vertex normals, where it is calculated
based upon the surrounding vertices. I know the code is inefficient,
I'm not concerned about those things yet, I just want to get the
normal calculation right, is it obvious to some of you more
experienced folk where I am going wrong?

Thanks in advance,

Richy

ps ComputeNormal is:


Public Function ComputeNormal(ByVal p0 As Vector3, ByVal p1 As
Vector3, ByVal p2 As Vector3) As Vector3

Dim u As Vector3 = p1 - p0
Dim v As Vector3 = p2 - p0
Dim out As Vector3 = Vector3.Cross(u, v)
out.Normalize()
Return out

End Function

.



Relevant Pages

  • Re: why is my terrain lighting so jagged?
    ... I am trying to calculate the normals for my terrain, ... Dim p0 As New Vector3.X, ... where p1 is the actual vertex I am calculating the normal for. ... Public Function ComputeNormal(ByVal p0 As Vector3, ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: Area of freeform shapes
    ... Back in the old days, before electronic calculators, we used to calculate areas adding and subtracting trapezoidal areas as we went in order around the nodes of the polygon. ... Dim Xold As Double ... Dim Yorig As Double ... > Thanks for that but my problem is calculating freeform shapes - someone> could ...
    (microsoft.public.excel.programming)
  • UDF causes #VALUE! error
    ... I have a User Defined Function that is calculating a sum based on the ... contents of other cells. ... Dim cellIndex As Integer ...
    (microsoft.public.excel.worksheet.functions)
  • Matrix Problem
    ... m = m * Matrix.RotationYawPitchRoll(diffX, diffY, 0) ... Dim CameraPos As New Vector3 ... Matrix und Vector3 stammen aus DirectX. ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: Calculating age from Date of Birth
    ... DayDiff = DateDiff ... vba's datediff doesn't work for calculating a ... >> Sub Test() ... > Dim DayDiff As Long ...
    (microsoft.public.word.vba.beginners)