I followed tutorial from: "light house 3d" and I can't seem to figure out the displacement part. It isn't very clear.
Here is what the tutorial said to do for displacement:
Quote: "The Displacement Factor
Another issue of this algorithm, is by how much we should displace the terrain heights at each iteration. The simplest solution is to consider the displacement a constant at every iteration. Another approach is to decrease the height displacement at each iteration without letting it reach zero. We could drop linearly the displacement factor from iteration 1 to iteration n, and then just keep it constant for iterations greater than n. For instance, to decrease the height displacement linearly as the number of iterations increases we could write in pseudo code:
if ( i < n )
dispi = disp0 + (iterationsDone / n) ( dispn - disp0)
else
dispi = dispn
where
disp0 is the initial displacement
dispi is the displacement for iteration i
dispn is the displacement for iteration n
Special care must be taken when choosing the value n, as well as dispn. If dispn is much smaller than disp0 then the value of n should be sufficiently large, otherwise the displacement factor will decay too fast and the initial iterations will leave significant marks on the terrain. In this case if n is not large enough then the faults created by the first iterations will be visible regardeless of how many iterations we run. "
FaultFormation(Size, Iterations):
- Size = Size of Image
- Iterations = How many passes the algorithm makes
Function FaultFormation(Size, Iterations)
Dim Height(Size, Size) As Float
DispMax# = 01.0
SubDisp# = (DispMax# / Iterations)
For Iter = 1 To Iterations
` Two Random Points
X1 = RND(Size) : Y1 = RND(Size)
X2 = RND(Size) : Y2 = RND(Size)
` The displacement factor isn't working... :(
`decrease?
Displacement# = Displacement# - SubDisp#
`Displacement# = DispMax# - (DispMax# / Iterations) * Iter
` Doesn't work:
`Displacement# = 0.1 - (0.1 * Iter / Iterations)
`If (i < n)
`Displacement# = disp0 + (Iter / n) (dispn - disp0)
`Else
`Displacement# = dispn
`EndIf
For X = 0 To Size - 1
For Y = 0 To Size - 1
If ((X2 - X1) * (Y - Y1) - (Y2 - Y1) * (X - X1)) > 0
Height(X, Y) = Height(X, Y) + Displacement#
If Height(X, Y) > 1.0 Then Height(X, Y) = 1.0
Else
Height(X, Y) = Height(X, Y) - Displacement#
If Height(X, Y) > 1.0 Then Height(X, Y) = 1.0
EndIf
Next Y
Next X
Next Iter
For X = 0 To Size - 1
For Y = 0 To Size - 1
H# = Height(X, Y) * 255.0
Dot X, Y, RGB(H#, H#, H#)
Next Y
Next X
EndFunction
What I need help with:
The determinate is suppose to remove or add by a certain amount. I don't understand how to calculate the determinate. Check the quote on how to calculate the determinate. I need help figuring out what the quote is telling me about calculating the determinate. It is a bit confusing.
Fault Formation Resources:
http://www.lighthouse3d.com/opengl/terrain/index.php3?fault
http://www.m3xbox.com/GPU_blog/?p=10
Any help is appreciated.
DigitalFury