why is my terrain lighting so jagged?
- From: "Richy" <movieknight@xxxxxxxxx>
- Date: 8 Mar 2007 00:44:55 -0800
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
.
- Follow-Ups:
- Re: why is my terrain lighting so jagged?
- From: Richy
- Re: why is my terrain lighting so jagged?
- Prev by Date: setting and accessing pixel and vertex shader constants
- Next by Date: Re: why is my terrain lighting so jagged?
- Previous by thread: setting and accessing pixel and vertex shader constants
- Next by thread: Re: why is my terrain lighting so jagged?
- Index(es):
Relevant Pages
|