Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '/*
- ' * OpenSimplex Noise in FreeBASIC.
- ' * by Kurt Spencer
- ' *
- ' * v1.1 (October 5, 2014)
- ' * - Added 2D and 4D implementations.
- ' * - Proper gradient sets for all dimensions, from a
- ' * dimensionally-generalizable scheme with an actual
- ' * rhyme and reason behind it.
- ' * - Removed default permutation array in favor of
- ' * default seed.
- ' * - Changed seed-based constructor to be independent
- ' * of any particular randomization library, so results
- ' * will be the same when ported to other languages.
- ' */
- type OpenSimplexNoise extends INoise
- Public:
- Declare Constructor()
- Declare Constructor(seed As LongInt)
- Declare Destructor()
- Declare Function noise(x As Double ,y As double) As Double
- Declare Function noise(x As Double ,y As Double, z As double) As Double
- Declare Function noise(x As Double ,y As double, z As Double, w As Double) As Double
- Private:
- Declare Function fastfloor(x As double) As Integer
- Declare Function extrapolate2(xsb As Integer, ysb As Integer, dx As Double, dy As Double) As Double
- Declare Function extrapolate3(xsb As Integer, ysb As Integer, zsb As Integer, dx As Double, dy As Double, dz As Double)As Double
- Declare Function extrapolate4(xsb As integer, ysb As Integer, zsb As Integer, wsb As Integer, dx As Double, dy As Double, dz As Double, dw As Double)As Double
- dim as double STRETCH_CONSTANT_2D = -0.211324865405187 ''(1/sqr(2+1)-1)/2
- dim As double SQUISH_CONSTANT_2D = 0.366025403784439 ''(sqr(2+1)-1)/2
- dim As double STRETCH_CONSTANT_3D = -1.0 / 6.0 ''(1/sqr(3+1)-1)/3
- dim As double SQUISH_CONSTANT_3D = 1.0 / 3.0 ''(sqr(3+1)-1)/3
- dim As double STRETCH_CONSTANT_4D = -0.138196601125011 ''(1/sqr(4+1)-1)/4
- dim As double SQUISH_CONSTANT_4D = 0.309016994374947 ''(sqr(4+1)-1)/4
- dim As double NORM_CONSTANT_2D = 47
- dim As double NORM_CONSTANT_3D = 103
- dim As double NORM_CONSTANT_4D = 30
- dim as uLongint DEFAULT_SEED = 0
- Dim As Short Ptr perm
- Dim As Short ptr permGradIndex3D
- ''Gradients for 2D. They approximate the directions to the
- ''vertices of an octagon from the center.
- Dim As byte gradients2D(8,2) = {_
- {5, 2}, {2, 5},_
- {-5, 2}, {-2, 5},_
- {5, -2}, {2, -5},_
- {-5, -2}, {-2, -5} _
- }
- ''Gradients for 3D. They approximate the directions to the
- ''vertices of a rhombicuboctahedron from the center, skewed so
- ''that the triangular and square facets can be inscribed inside
- ''circles of the same radius.
- Dim As byte gradients3D(24,3) = {_
- {-11, 4, 4}, { -4, 11, 4}, { -4, 4, 11},_
- {11, 4, 4}, { 4, 11, 4}, { 4, 4, 11},_
- {-11, -4, 4}, { -4, -11, 4}, { -4, -4, 11},_
- {11, -4, 4}, {4, -11, 4}, {4, -4, 11},_
- {-11, 4, -4}, { -4, 11, -4}, {-4, 4, -11},_
- {11, 4, -4}, {4, 11, -4}, { 4, 4, -11},_
- {-11, -4, -4}, {-4, -11, -4}, {-4, -4, -11},_
- {11, -4, -4}, {4, -11, -4}, { 4, -4, -11} _
- }
- ''Gradients for 4D. They approximate the directions to the
- ''vertices of a disprismatotesseractihexadecachoron from the center,
- ''skewed so that the tetrahedral and cubic facets can be inscribed inside
- ''spheres of the same radius.
- Dim As Byte gradients4D(64,4) = {_
- {3, 1, 1, 1}, { 1, 3, 1, 1}, { 1, 1, 3, 1}, { 1, 1, 1, 3},_
- {-3, 1, 1, 1}, { -1, 3, 1, 1}, { -1, 1, 3, 1}, { -1, 1, 1, 3},_
- {3, -1, 1, 1}, { 1, -3, 1, 1}, { 1, -1, 3, 1}, { 1, -1, 1, 3},_
- {-3, -1, 1, 1}, { -1, -3, 1, 1}, { -1, -1, 3, 1}, { -1, -1, 1, 3},_
- {3, 1, -1, 1}, { 1, 3, -1, 1}, { 1, 1, -3, 1}, { 1, 1, -1, 3},_
- {-3, 1, -1, 1}, { -1, 3, -1, 1}, { -1, 1, -3, 1}, { -1, 1, -1, 3},_
- {3, -1, -1, 1}, { 1, -3, -1, 1}, { 1, -1, -3, 1}, { 1, -1, -1, 3},_
- {-3, -1, -1, 1}, { -1, -3, -1, 1}, { -1, -1, -3, 1}, { -1, -1, -1, 3},_
- {3, 1, 1, -1}, {1, 3, 1, -1}, { 1, 1, 3, -1}, { 1, 1, 1, -3},_
- {-3, 1, 1, -1}, {-1, 3, 1, -1}, { -1, 1, 3, -1}, { -1, 1, 1, -3},_
- {3, -1, 1, -1}, {1, -3, 1, -1}, { 1, -1, 3, -1}, { 1, -1, 1, -3},_
- {-3, -1, 1, -1}, {-1, -3, 1, -1}, { -1, -1, 3, -1}, { -1, -1, 1, -3},_
- {3, 1, -1, -1}, {1, 3, -1, -1}, { 1, 1, -3, -1}, { 1, 1, -1, -3},_
- {-3, 1, -1, -1}, { -1, 3, -1, -1}, { -1, 1, -3, -1}, { -1, 1, -1, -3},_
- {3, -1, -1, -1}, { 1, -3, -1, -1}, { 1, -1, -3, -1}, { 1, -1, -1, -3}, _
- {-3, -1, -1, -1}, {-1, -3, -1, -1}, { -1, -1, -3, -1}, { -1, -1, -1, -3} _
- }
- End type
- Constructor OpenSimplexNoise()
- Dim seed As ULongInt=DEFAULT_SEED
- perm = new Short[256]
- permGradIndex3D = new Short[256]
- Dim As Short Ptr source = new Short[256]
- for i As Integer=0 To 255
- source[i] = i
- next
- seed = seed * 6364136223846793005ull + 1442695040888963407ull
- seed = seed * 6364136223846793005ull + 1442695040888963407ull
- seed = seed * 6364136223846793005ull + 1442695040888963407ull
- for i As Integer=255 To 0 Step -1
- seed = seed * 6364136223846793005ull + 1442695040888963407ull
- Dim As integer r = Int((seed + 31) Mod (i + 1))
- if (r < 0) Then
- r += (i + 1)
- EndIf
- perm[i] = source[r]
- permGradIndex3D[i] = Cast(Short,((perm[i] Mod (24)) ))
- source[r] = source[i]
- Next
- Delete [] source
- source=0
- End Constructor
- ''Initializes the class using a permutation array generated from a 64-bit seed.
- ''Generates a proper permutation (i.e. doesn't merely perform N successive pair swaps on a base array)
- ''Uses a simple 64-bit LCG.
- Constructor OpenSimplexNoise(seed As LongInt)
- perm = new short[256]
- permGradIndex3D = new short[256]
- Dim As Short Ptr source = new short[256]
- for i As UInteger=0 To 255
- source[i] = i
- next
- seed = seed * 6364136223846793005ull + 1442695040888963407ull
- seed = seed * 6364136223846793005ull + 1442695040888963407ull
- seed = seed * 6364136223846793005ull + 1442695040888963407ull
- for i As Integer=255 To 0 Step -1
- seed = seed * 6364136223846793005ull + 1442695040888963407ull
- Dim As integer r = Int((seed + 31) Mod (i + 1))
- if (r < 0) Then
- r += (i + 1)
- EndIf
- perm[i] = source[r]
- permGradIndex3D[i] = cast(short,((perm[i] Mod (24)) ))
- source[r] = source[i]
- Next
- Delete [] source
- source=0
- End Constructor
- Destructor OpenSimplexNoise()
- Delete [] perm
- perm=0
- Delete [] permGradIndex3D
- permGradIndex3D=0
- End Destructor
- Function OpenSimplexNoise.fastfloor(x As double) As Integer
- return IIf(x>=0,Int(x) , Int(x-1))
- End Function
- Function OpenSimplexNoise.extrapolate2(xsb As Integer, ysb As Integer, dx As Double, dy As Double) As Double
- Dim As integer index = perm[(perm[xsb and &hFF] + ysb) and &hFF] Mod 8
- return gradients2D(index,0) * dx + gradients2D(index,1) * dy
- End Function
- Function OpenSimplexNoise.extrapolate3(xsb As Integer, ysb As Integer, zsb As Integer, dx As Double, dy As Double, dz As Double)As Double
- Dim As integer index = permGradIndex3D[(perm[(perm[xsb And &hFF] + ysb) And &hFF] + zsb) And &hFF] Mod 24
- return gradients3D(index,0) * dx + gradients3D(index,1) * dy + gradients3D(index, 2) * dz
- End Function
- Function OpenSimplexNoise.extrapolate4(xsb As integer, ysb As Integer, zsb As Integer, wsb As Integer, dx As Double, dy As Double, dz As Double, dw As Double)As Double
- Dim As integer index = perm[(perm[(perm[(perm[xsb And &hFF] + ysb) And &hFF] + zsb) and &hFF] + wsb) And &hFF] Mod 64
- return gradients4D(index,0) * dx + gradients4D(index , 1) * dy + gradients4D(index , 2) * dz + gradients4D(index , 3) * dw
- End function
- ''2D OpenSimplex Noise.
- function OpenSimplexNoise.noise(x As Double ,y As double) As Double
- ''Place input coordinates onto grid.
- Dim As Double stretchOffset = (x + y) * STRETCH_CONSTANT_2D
- Dim As Double xs = x + stretchOffset
- Dim As Double ys = y + stretchOffset
- ''Floor to get grid coordinates of rhombus (stretched square) super-cell origin.
- Dim As Integer xsb = fastFloor(xs)
- Dim As Integer ysb = fastFloor(ys)
- ''Skew out to get actual coordinates of rhombus origin. We'll need these later.
- Dim As Double squishOffset = (xsb + ysb) * SQUISH_CONSTANT_2D
- Dim As Double xb = xsb + squishOffset
- Dim As Double yb = ysb + squishOffset
- ''Compute grid coordinates relative to rhombus origin.
- Dim As Double xins = xs - xsb
- Dim As Double yins = ys - ysb
- ''Sum those together to get a value that determines which region we're in.
- Dim As Double inSum = xins + yins
- ''Positions relative to origin point.
- Dim As Double dx0 = x - xb
- Dim As Double dy0 = y - yb
- ''We'll be defining these inside the next block and using them afterwards.
- Dim As Double dx_ext, dy_ext
- Dim As Integer xsv_ext, ysv_ext
- Dim As Double value = 0
- ''Contribution (1,0)
- Dim As Double dx1 = dx0 - 1.0 - SQUISH_CONSTANT_2D
- Dim As Double dy1 = dy0 - 0.0 - SQUISH_CONSTANT_2D
- Dim As Double attn1 = 2.0 - (dx1 * dx1) - (dy1 * dy1)
- if (attn1 > 0.0) Then
- attn1 *= attn1
- value += (attn1 * attn1) * extrapolate2(xsb + 1, ysb + 0, dx1, dy1)
- EndIf
- ''Contribution (0,1)
- Dim As Double dx2 = dx0 - 0.0 - SQUISH_CONSTANT_2D
- Dim As Double dy2 = dy0 - 1.0 - SQUISH_CONSTANT_2D
- Dim As Double attn2 = 2.0 - dx2 * dx2 - dy2 * dy2
- if (attn2 > 0) Then
- attn2 *= attn2
- value += (attn2 * attn2) * extrapolate2(xsb + 0, ysb + 1, dx2, dy2)
- endif
- if (inSum <= 1.0) then ''We're inside the triangle (2-Simplex) at (0,0)
- Dim As Double zins = 1.0 - inSum
- if ((zins > xins) or (zins > yins)) then ''(0,0) is one of the closest two triangular vertices
- if (xins > yins) Then
- xsv_ext = xsb + 1.0
- ysv_ext = ysb - 1.0
- dx_ext = dx0 - 1.0
- dy_ext = dy0 + 1.0
- else
- xsv_ext = xsb - 1.0
- ysv_ext = ysb + 1.0
- dx_ext = dx0 + 1.0
- dy_ext = dy0 - 1.0
- EndIf
- Else ''(1,0) and (0,1) are the closest two vertices.
- xsv_ext = xsb + 1.0
- ysv_ext = ysb + 1.0
- dx_ext = dx0 - 1.0 - 2.0 * SQUISH_CONSTANT_2D
- dy_ext = dy0 - 1.0 - 2.0 * SQUISH_CONSTANT_2D
- EndIf
- else ''We're inside the triangle (2-Simplex) at (1,1)
- Dim As Double zins = 2.0 - inSum
- if ((zins < xins) or (zins < yins)) Then ''(0,0) is one of the closest two triangular vertices
- if (xins > yins) Then
- xsv_ext = xsb + 2.0
- ysv_ext = ysb + 0.0
- dx_ext = dx0 - 2.0 - 2.0 * SQUISH_CONSTANT_2D
- dy_ext = dy0 + 0.0 - 2.0 * SQUISH_CONSTANT_2D
- Else
- xsv_ext = xsb + 0.0
- ysv_ext = ysb + 2.0
- dx_ext = dx0 + 0.0 - 2.0 * SQUISH_CONSTANT_2D
- dy_ext = dy0 - 2.0 - 2.0 * SQUISH_CONSTANT_2D
- endif
- else ''(1,0) and (0,1) are the closest two vertices.
- dx_ext = dx0
- dy_ext = dy0
- xsv_ext = xsb
- ysv_ext = ysb
- EndIf
- xsb += 1.0
- ysb += 1.0
- dx0 = dx0 - 1.0 - 2.0 * SQUISH_CONSTANT_2D
- dy0 = dy0 - 1.0 - 2.0 * SQUISH_CONSTANT_2D
- EndIf
- ''Contribution (0,0) or (1,1)
- Dim As Double attn0 = 2.0 - dx0 * dx0 - dy0 * dy0
- if (attn0 > 0.0) Then
- attn0 *= attn0
- value += (attn0 * attn0) * extrapolate2(xsb, ysb, dx0, dy0)
- EndIf
- ''Extra Vertex
- Dim As Double attn_ext = 2.0 - dx_ext * dx_ext - dy_ext * dy_ext
- if (attn_ext > 0.0)Then
- attn_ext *= attn_ext
- value += (attn_ext * attn_ext) * extrapolate2(xsv_ext, ysv_ext, dx_ext, dy_ext)
- endif
- value/=NORM_CONSTANT_2D
- return value
- End Function
- ''3D OpenSimplex Noise.
- Function OpenSimplexNoise.noise(x As Double ,y As Double, z As double) As Double
- ''Place input coordinates on simplectic honeycomb.
- Dim As Double stretchOffset = (x + y + z) * STRETCH_CONSTANT_3D
- Dim As Double xs = x + stretchOffset
- Dim As Double ys = y + stretchOffset
- Dim As Double zs = z + stretchOffset
- ''Floor to get simplectic honeycomb coordinates of rhombohedron (stretched cube) super-cell origin.
- Dim As integer xsb = fastFloor(xs)
- Dim As Integer ysb = fastFloor(ys)
- Dim As Integer zsb = fastFloor(zs)
- ''Skew out to get actual coordinates of rhombohedron origin. We'll need these later.
- Dim As Double squishOffset = (xsb + ysb + zsb) * SQUISH_CONSTANT_3D
- Dim As Double xb = xsb + squishOffset
- Dim As Double yb = ysb + squishOffset
- Dim As Double zb = zsb + squishOffset
- ''Compute simplectic honeycomb coordinates relative to rhombohedral origin.
- Dim As Double xins = xs - xsb
- Dim As Double yins = ys - ysb
- Dim As Double zins = zs - zsb
- ''Sum those together to get a value that determines which region we're in.
- Dim As Double inSum = xins + yins + zins
- ''Positions relative to origin point.
- Dim As Double dx0 = x - xb
- Dim As Double dy0 = y - yb
- Dim As Double dz0 = z - zb
- ''We'll be defining these inside the next block and using them afterwards.
- Dim As Double dx_ext0, dy_ext0, dz_ext0
- Dim As Double dx_ext1, dy_ext1, dz_ext1
- Dim As Integer xsv_ext0, ysv_ext0, zsv_ext0
- Dim As Integer xsv_ext1, ysv_ext1, zsv_ext1
- Dim As Double value = 0
- if (inSum <= 1) Then ''We're inside the tetrahedron (3-Simplex) at (0,0,0)
- ''Determine which two of (0,0,1), (0,1,0), (1,0,0) are closest.
- Dim As Byte aPoint = &h01
- Dim As Double aScore = xins
- Dim As Byte bPoint = &h02
- Dim As Double bScore = yins
- if (aScore >= bScore And zins > bScore) Then
- bScore = zins
- bPoint = &h04
- elseif (aScore < bScore and zins > aScore) Then
- aScore = zins
- aPoint = &h04
- endif
- ''Now we determine the two lattice points not part of the tetrahedron that may contribute.
- ''This depends on the closest two tetrahedral vertices, including (0,0,0)
- Dim As Double wins = 1 - inSum
- if (wins > aScore Or wins > bScore) Then ''(0,0,0) is one of the closest two tetrahedral vertices.
- Dim As Byte c = iif(bScore > aScore , bPoint , aPoint) ''Our other closest vertex is the closest out of a and b.
- if ((c and &h01) = 0) Then
- xsv_ext0 = xsb - 1
- xsv_ext1 = xsb
- dx_ext0 = dx0 + 1
- dx_ext1 = dx0
- Else
- xsv_ext0 = xsv_ext1 = xsb + 1
- dx_ext0 = dx_ext1 = dx0 - 1
- endif
- if ((c and &h02) = 0) Then
- ysv_ext0 = ysv_ext1 = ysb
- dy_ext0 = dy_ext1 = dy0
- if ((c and &h01) = 0) Then
- ysv_ext1 -= 1
- dy_ext1 += 1
- Else
- ysv_ext0 -= 1
- dy_ext0 += 1
- endif
- Else
- ysv_ext0 = ysv_ext1 = ysb + 1
- dy_ext0 = dy_ext1 = dy0 - 1
- EndIf
- if ((c and &h04) = 0) then
- zsv_ext0 = zsb
- zsv_ext1 = zsb - 1
- dz_ext0 = dz0
- dz_ext1 = dz0 + 1
- Else
- zsv_ext0 = zsv_ext1 = zsb + 1
- dz_ext0 = dz_ext1 = dz0 - 1
- EndIf
- Else ''(0,0,0) is not one of the closest two tetrahedral vertices.
- Dim As Byte c = aPoint And bPoint'cast(Byte,(aPoint or bPoint)) ''Our two extra vertices are determined by the closest two.
- if ((c and &h01) = 0) Then
- xsv_ext0 = xsb
- xsv_ext1 = xsb - 1
- dx_ext0 = dx0 - 2 * SQUISH_CONSTANT_3D
- dx_ext1 = dx0 + 1 - SQUISH_CONSTANT_3D
- Else
- xsv_ext0 = xsv_ext1 = xsb + 1
- dx_ext0 = dx0 - 1 - 2 * SQUISH_CONSTANT_3D
- dx_ext1 = dx0 - 1 - SQUISH_CONSTANT_3D
- EndIf
- if ((c and &h02) = 0) Then
- ysv_ext0 = ysb
- ysv_ext1 = ysb - 1
- dy_ext0 = dy0 - 2 * SQUISH_CONSTANT_3D
- dy_ext1 = dy0 + 1 - SQUISH_CONSTANT_3D
- Else
- ysv_ext0 = ysv_ext1 = ysb + 1
- dy_ext0 = dy0 - 1 - 2 * SQUISH_CONSTANT_3D
- dy_ext1 = dy0 - 1 - SQUISH_CONSTANT_3D
- EndIf
- if ((c and &h04) = 0) Then
- zsv_ext0 = zsb
- zsv_ext1 = zsb - 1
- dz_ext0 = dz0 - 2 * SQUISH_CONSTANT_3D
- dz_ext1 = dz0 + 1 - SQUISH_CONSTANT_3D
- Else
- zsv_ext0 = zsv_ext1 = zsb + 1
- dz_ext0 = dz0 - 1 - 2 * SQUISH_CONSTANT_3D
- dz_ext1 = dz0 - 1 - SQUISH_CONSTANT_3D
- endif
- endif
- ''Contribution (0,0,0)
- Dim As Double attn0 = 2 - dx0 * dx0 - dy0 * dy0 - dz0 * dz0
- if (attn0 > 0) Then
- attn0 *= attn0
- value += attn0 * attn0 * extrapolate3(xsb + 0, ysb + 0, zsb + 0, dx0, dy0, dz0)
- endif
- ''Contribution (1,0,0)
- Dim As Double dx1 = dx0 - 1 - SQUISH_CONSTANT_3D
- Dim As Double dy1 = dy0 - 0 - SQUISH_CONSTANT_3D
- Dim As Double dz1 = dz0 - 0 - SQUISH_CONSTANT_3D
- Dim As Double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1
- if (attn1 > 0) Then
- attn1 *= attn1
- value += attn1 * attn1 * extrapolate3(xsb + 1, ysb + 0, zsb + 0, dx1, dy1, dz1)
- EndIf
- ''Contribution (0,1,0)
- Dim As Double dx2 = dx0 - 0 - SQUISH_CONSTANT_3D
- Dim As Double dy2 = dy0 - 1 - SQUISH_CONSTANT_3D
- Dim As Double dz2 = dz1
- Dim As Double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2
- if (attn2 > 0) Then
- attn2 *= attn2
- value += attn2 * attn2 * extrapolate3(xsb + 0, ysb + 1, zsb + 0, dx2, dy2, dz2)
- EndIf
- ''Contribution (0,0,1)
- Dim As Double dx3 = dx2
- Dim As Double dy3 = dy1
- Dim As Double dz3 = dz0 - 1 - SQUISH_CONSTANT_3D
- Dim As Double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3
- if (attn3 > 0) Then
- attn3 *= attn3
- value += attn3 * attn3 * extrapolate3(xsb + 0, ysb + 0, zsb + 1, dx3, dy3, dz3)
- EndIf
- ElseIf (inSum >= 2) Then ''We're inside the tetrahedron (3-Simplex) at (1,1,1)
- ''Determine which two tetrahedral vertices are the closest, out of (1,1,0), (1,0,1), (0,1,1) but not (1,1,1).
- Dim As Byte aPoint = &h06
- Dim As Double aScore = xins
- Dim As Byte bPoint = &h05
- Dim As Double bScore = yins
- if (aScore <= bScore And zins < bScore) Then
- bScore = zins
- bPoint = &h03
- elseif (aScore > bScore And zins < aScore) Then
- aScore = zins
- aPoint = &h03
- endif
- ''Now we determine the two lattice points not part of the tetrahedron that may contribute.
- ''This depends on the closest two tetrahedral vertices, including (1,1,1)
- Dim As Double wins = 3 - inSum
- if (wins < aScore Or wins < bScore) Then ''(1,1,1) is one of the closest two tetrahedral vertices.
- Dim As uByte c = iif(bScore < aScore , bPoint , aPoint) ''Our other closest vertex is the closest out of a and b.
- if ((c and &h01) <> 0) then
- xsv_ext0 = xsb + 2
- xsv_ext1 = xsb + 1
- dx_ext0 = dx0 - 2 - 3 * SQUISH_CONSTANT_3D
- dx_ext1 = dx0 - 1 - 3 * SQUISH_CONSTANT_3D
- Else
- xsv_ext0 = xsv_ext1 = xsb
- dx_ext0 = dx_ext1 = dx0 - 3 * SQUISH_CONSTANT_3D
- EndIf
- if ((c and &h02) <> 0) Then
- ysv_ext0 = ysv_ext1 = ysb + 1
- dy_ext0 = dy_ext1 = dy0 - 1 - 3 * SQUISH_CONSTANT_3D
- if ((c and &h01) <> 0) Then
- ysv_ext1 += 1
- dy_ext1 -= 1
- Else
- ysv_ext0 += 1
- dy_ext0 -= 1
- EndIf
- Else
- ysv_ext0 = ysv_ext1 = ysb
- dy_ext0 = dy_ext1 = dy0 - 3 * SQUISH_CONSTANT_3D
- endif
- if ((c and &h04) <> 0) Then
- zsv_ext0 = zsb + 1
- zsv_ext1 = zsb + 2
- dz_ext0 = dz0 - 1 - 3 * SQUISH_CONSTANT_3D
- dz_ext1 = dz0 - 2 - 3 * SQUISH_CONSTANT_3D
- Else
- zsv_ext0 = zsv_ext1 = zsb
- dz_ext0 = dz_ext1 = dz0 - 3 * SQUISH_CONSTANT_3D
- EndIf
- Else ''(1,1,1) is not one of the closest two tetrahedral vertices.
- Dim As Byte c = aPoint And bPoint'cast(byte,(aPoint And bPoint)) ''Our two extra vertices are determined by the closest two.
- if ((c and &h01) <> 0) Then
- xsv_ext0 = xsb + 1
- xsv_ext1 = xsb + 2
- dx_ext0 = dx0 - 1 - SQUISH_CONSTANT_3D
- dx_ext1 = dx0 - 2 - 2 * SQUISH_CONSTANT_3D
- Else
- xsv_ext0 = xsv_ext1 = xsb
- dx_ext0 = dx0 - SQUISH_CONSTANT_3D
- dx_ext1 = dx0 - 2 * SQUISH_CONSTANT_3D
- EndIf
- if ((c and &h02) <> 0) Then
- ysv_ext0 = ysb + 1
- ysv_ext1 = ysb + 2
- dy_ext0 = dy0 - 1 - SQUISH_CONSTANT_3D
- dy_ext1 = dy0 - 2 - 2 * SQUISH_CONSTANT_3D
- Else
- ysv_ext0 = ysv_ext1 = ysb
- dy_ext0 = dy0 - SQUISH_CONSTANT_3D
- dy_ext1 = dy0 - 2 * SQUISH_CONSTANT_3D
- EndIf
- if ((c and &h04) <> 0) Then
- zsv_ext0 = zsb + 1
- zsv_ext1 = zsb + 2
- dz_ext0 = dz0 - 1 - SQUISH_CONSTANT_3D
- dz_ext1 = dz0 - 2 - 2 * SQUISH_CONSTANT_3D
- Else
- zsv_ext0 = zsv_ext1 = zsb
- dz_ext0 = dz0 - SQUISH_CONSTANT_3D
- dz_ext1 = dz0 - 2 * SQUISH_CONSTANT_3D
- EndIf
- endif
- ''Contribution (1,1,0)
- Dim As Double dx3 = dx0 - 1 - 2 * SQUISH_CONSTANT_3D
- Dim As Double dy3 = dy0 - 1 - 2 * SQUISH_CONSTANT_3D
- Dim As Double dz3 = dz0 - 0 - 2 * SQUISH_CONSTANT_3D
- Dim As Double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3
- if (attn3 > 0) Then
- attn3 *= attn3
- value += attn3 * attn3 * extrapolate3(xsb + 1, ysb + 1, zsb + 0, dx3, dy3, dz3)
- EndIf
- ''Contribution (1,0,1)
- Dim As Double dx2 = dx3
- Dim As Double dy2 = dy0 - 0 - 2 * SQUISH_CONSTANT_3D
- Dim As Double dz2 = dz0 - 1 - 2 * SQUISH_CONSTANT_3D
- Dim As Double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2
- if (attn2 > 0) Then
- attn2 *= attn2
- value += attn2 * attn2 * extrapolate3(xsb + 1, ysb + 0, zsb + 1, dx2, dy2, dz2)
- EndIf
- ''Contribution (0,1,1)
- Dim As Double dx1 = dx0 - 0 - 2 * SQUISH_CONSTANT_3D
- Dim As Double dy1 = dy3
- Dim As Double dz1 = dz2
- Dim As Double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1
- if (attn1 > 0) Then
- attn1 *= attn1
- value += attn1 * attn1 * extrapolate3(xsb + 0, ysb + 1, zsb + 1, dx1, dy1, dz1)
- endif
- ''Contribution (1,1,1)
- dx0 = dx0 - 1 - 3 * SQUISH_CONSTANT_3D
- dy0 = dy0 - 1 - 3 * SQUISH_CONSTANT_3D
- dz0 = dz0 - 1 - 3 * SQUISH_CONSTANT_3D
- Dim As Double attn0 = 2 - dx0 * dx0 - dy0 * dy0 - dz0 * dz0
- if (attn0 > 0) Then
- attn0 *= attn0
- value += attn0 * attn0 * extrapolate3(xsb + 1, ysb + 1, zsb + 1, dx0, dy0, dz0)
- EndIf
- Else ''We're inside the octahedron (Rectified 3-Simplex) in between.
- Dim As Double aScore
- Dim As Byte aPoint
- Dim As boolean aIsFurtherSide=FALSE
- Dim As Double bScore
- Dim As Byte bPoint
- Dim As boolean bIsFurtherSide=FALSE
- ''Decide between point (0,0,1) and (1,1,0) as closest
- Dim As Double p1 = xins + yins
- if (p1 > 1) Then
- aScore = p1 - 1
- aPoint = &h03
- aIsFurtherSide = TRUE
- Else
- aScore = 1 - p1
- aPoint = &h04
- aIsFurtherSide = FALSE
- EndIf
- ''Decide between point (0,1,0) and (1,0,1) as closest
- Dim As Double p2 = xins + zins
- if (p2 > 1) Then
- bScore = p2 - 1
- bPoint = &h05
- bIsFurtherSide = TRUE
- else
- bScore = 1 - p2
- bPoint = &h02
- bIsFurtherSide = FALSE
- EndIf
- ''The closest out of the two (1,0,0) and (0,1,1) will replace the furthest out of the two decided above, if closer.
- Dim As Double p3 = yins + zins
- if (p3 > 1) Then
- Dim As Double score = p3 - 1
- if (aScore <= bScore And aScore < score) Then
- aScore = score
- aPoint = &h06
- aIsFurtherSide = TRUE
- elseif (aScore > bScore And bScore < score) Then
- bScore = score
- bPoint = &h06
- bIsFurtherSide = TRUE
- EndIf
- Else
- Dim As Double score = 1 - p3
- if (aScore <= bScore And aScore < score) Then
- aScore = score
- aPoint = &h01
- aIsFurtherSide = FALSE
- ElseIf (aScore > bScore And bScore < score) Then
- bScore = score
- bPoint = &h01
- bIsFurtherSide = FALSE
- EndIf
- endif
- ''Where each of the two closest points are determines how the extra two vertices are calculated.
- if (aIsFurtherSide = bIsFurtherSide) Then
- if (aIsFurtherSide) Then ''Both closest points on (1,1,1) side
- ''One of the two extra points is (1,1,1)
- dx_ext0 = dx0 - 1 - 3 * SQUISH_CONSTANT_3D
- dy_ext0 = dy0 - 1 - 3 * SQUISH_CONSTANT_3D
- dz_ext0 = dz0 - 1 - 3 * SQUISH_CONSTANT_3D
- xsv_ext0 = xsb + 1
- ysv_ext0 = ysb + 1
- zsv_ext0 = zsb + 1
- ''Other extra point is based on the shared axis.
- Dim As Byte c = aPoint And bPoint'cast(byte,(aPoint And bPoint))
- if ((c and &h01) <> 0) Then
- dx_ext1 = dx0 - 2 - 2 * SQUISH_CONSTANT_3D
- dy_ext1 = dy0 - 2 * SQUISH_CONSTANT_3D
- dz_ext1 = dz0 - 2 * SQUISH_CONSTANT_3D
- xsv_ext1 = xsb + 2
- ysv_ext1 = ysb
- zsv_ext1 = zsb
- elseif ((c and &h02) <> 0) Then
- dx_ext1 = dx0 - 2 * SQUISH_CONSTANT_3D
- dy_ext1 = dy0 - 2 - 2 * SQUISH_CONSTANT_3D
- dz_ext1 = dz0 - 2 * SQUISH_CONSTANT_3D
- xsv_ext1 = xsb
- ysv_ext1 = ysb + 2
- zsv_ext1 = zsb
- Else
- dx_ext1 = dx0 - 2 * SQUISH_CONSTANT_3D
- dy_ext1 = dy0 - 2 * SQUISH_CONSTANT_3D
- dz_ext1 = dz0 - 2 - 2 * SQUISH_CONSTANT_3D
- xsv_ext1 = xsb
- ysv_ext1 = ysb
- zsv_ext1 = zsb + 2
- EndIf
- Else''Both closest points on (0,0,0) side
- ''One of the two extra points is (0,0,0)
- dx_ext0 = dx0
- dy_ext0 = dy0
- dz_ext0 = dz0
- xsv_ext0 = xsb
- ysv_ext0 = ysb
- zsv_ext0 = zsb
- ''Other extra point is based on the omitted axis.
- Dim As Byte c = aPoint And bPoint'cast(byte,(aPoint or bPoint))
- if ((c and &h01) = 0) Then
- dx_ext1 = dx0 + 1 - SQUISH_CONSTANT_3D
- dy_ext1 = dy0 - 1 - SQUISH_CONSTANT_3D
- dz_ext1 = dz0 - 1 - SQUISH_CONSTANT_3D
- xsv_ext1 = xsb - 1
- ysv_ext1 = ysb + 1
- zsv_ext1 = zsb + 1
- ElseIf ((c and &h02) = 0) then
- dx_ext1 = dx0 - 1 - SQUISH_CONSTANT_3D
- dy_ext1 = dy0 + 1 - SQUISH_CONSTANT_3D
- dz_ext1 = dz0 - 1 - SQUISH_CONSTANT_3D
- xsv_ext1 = xsb + 1
- ysv_ext1 = ysb - 1
- zsv_ext1 = zsb + 1
- Else
- dx_ext1 = dx0 - 1 - SQUISH_CONSTANT_3D
- dy_ext1 = dy0 - 1 - SQUISH_CONSTANT_3D
- dz_ext1 = dz0 + 1 - SQUISH_CONSTANT_3D
- xsv_ext1 = xsb + 1
- ysv_ext1 = ysb + 1
- zsv_ext1 = zsb - 1
- EndIf
- EndIf
- Else ''One point on (0,0,0) side, one point on (1,1,1) side
- Dim As Byte c1, c2
- if (aIsFurtherSide) Then
- c1 = aPoint
- c2 = bPoint
- Else
- c1 = bPoint
- c2 = aPoint
- endif
- ''One contribution is a permutation of (1,1,-1)
- if ((c1 and &h01) = 0) Then
- dx_ext0 = dx0 + 1 - SQUISH_CONSTANT_3D
- dy_ext0 = dy0 - 1 - SQUISH_CONSTANT_3D
- dz_ext0 = dz0 - 1 - SQUISH_CONSTANT_3D
- xsv_ext0 = xsb - 1
- ysv_ext0 = ysb + 1
- zsv_ext0 = zsb + 1
- elseif ((c1 and &h02) = 0) Then
- dx_ext0 = dx0 - 1 - SQUISH_CONSTANT_3D
- dy_ext0 = dy0 + 1 - SQUISH_CONSTANT_3D
- dz_ext0 = dz0 - 1 - SQUISH_CONSTANT_3D
- xsv_ext0 = xsb + 1
- ysv_ext0 = ysb - 1
- zsv_ext0 = zsb + 1
- Else
- dx_ext0 = dx0 - 1 - SQUISH_CONSTANT_3D
- dy_ext0 = dy0 - 1 - SQUISH_CONSTANT_3D
- dz_ext0 = dz0 + 1 - SQUISH_CONSTANT_3D
- xsv_ext0 = xsb + 1
- ysv_ext0 = ysb + 1
- zsv_ext0 = zsb - 1
- endif
- ''One contribution is a permutation of (0,0,2)
- dx_ext1 = dx0 - 2 * SQUISH_CONSTANT_3D
- dy_ext1 = dy0 - 2 * SQUISH_CONSTANT_3D
- dz_ext1 = dz0 - 2 * SQUISH_CONSTANT_3D
- xsv_ext1 = xsb
- ysv_ext1 = ysb
- zsv_ext1 = zsb
- if ((c2 and &h01) <> 0) Then
- dx_ext1 -= 2
- xsv_ext1 += 2
- elseif ((c2 and &h02) <> 0) Then
- dy_ext1 -= 2
- ysv_ext1 += 2
- Else
- dz_ext1 -= 2
- zsv_ext1 += 2
- EndIf
- endif
- ''Contribution (1,0,0)
- Dim As Double dx1 = dx0 - 1 - SQUISH_CONSTANT_3D
- Dim As Double dy1 = dy0 - 0 - SQUISH_CONSTANT_3D
- Dim As Double dz1 = dz0 - 0 - SQUISH_CONSTANT_3D
- Dim As Double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1
- if (attn1 > 0) Then
- attn1 *= attn1
- value += attn1 * attn1 * extrapolate3(xsb + 1, ysb + 0, zsb + 0, dx1, dy1, dz1)
- EndIf
- ''Contribution (0,1,0)
- Dim As Double dx2 = dx0 - 0 - SQUISH_CONSTANT_3D
- Dim As Double dy2 = dy0 - 1 - SQUISH_CONSTANT_3D
- Dim As Double dz2 = dz1
- Dim As Double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2
- if (attn2 > 0) Then
- attn2 *= attn2
- value += attn2 * attn2 * extrapolate3(xsb + 0, ysb + 1, zsb + 0, dx2, dy2, dz2)
- EndIf
- ''Contribution (0,0,1)
- Dim As Double dx3 = dx2
- Dim As Double dy3 = dy1
- Dim As Double dz3 = dz0 - 1 - SQUISH_CONSTANT_3D
- Dim As Double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3
- if (attn3 > 0) Then
- attn3 *= attn3
- value += attn3 * attn3 * extrapolate3(xsb + 0, ysb + 0, zsb + 1, dx3, dy3, dz3)
- EndIf
- ''Contribution (1,1,0)
- Dim As Double dx4 = dx0 - 1 - 2 * SQUISH_CONSTANT_3D
- Dim As Double dy4 = dy0 - 1 - 2 * SQUISH_CONSTANT_3D
- Dim As Double dz4 = dz0 - 0 - 2 * SQUISH_CONSTANT_3D
- Dim As Double attn4 = 2 - dx4 * dx4 - dy4 * dy4 - dz4 * dz4
- if (attn4 > 0) Then
- attn4 *= attn4
- value += attn4 * attn4 * extrapolate3(xsb + 1, ysb + 1, zsb + 0, dx4, dy4, dz4)
- EndIf
- ''Contribution (1,0,1)
- Dim As Double dx5 = dx4
- Dim As Double dy5 = dy0 - 0 - 2 * SQUISH_CONSTANT_3D
- Dim As Double dz5 = dz0 - 1 - 2 * SQUISH_CONSTANT_3D
- Dim As Double attn5 = 2 - dx5 * dx5 - dy5 * dy5 - dz5 * dz5
- if (attn5 > 0) Then
- attn5 *= attn5
- value += attn5 * attn5 * extrapolate3(xsb + 1, ysb + 0, zsb + 1, dx5, dy5, dz5)
- EndIf
- ''Contribution (0,1,1)
- Dim As Double dx6 = dx0 - 0 - 2 * SQUISH_CONSTANT_3D
- Dim As Double dy6 = dy4
- Dim As Double dz6 = dz5
- Dim As Double attn6 = 2 - dx6 * dx6 - dy6 * dy6 - dz6 * dz6
- if (attn6 > 0) Then
- attn6 *= attn6
- value += attn6 * attn6 * extrapolate3(xsb + 0, ysb + 1, zsb + 1, dx6, dy6, dz6)
- endif
- EndIf
- ''First extra vertex
- Dim As Double attn_ext0 = 2 - dx_ext0 * dx_ext0 - dy_ext0 * dy_ext0 - dz_ext0 * dz_ext0
- if (attn_ext0 > 0) then
- attn_ext0 *= attn_ext0
- value += attn_ext0 * attn_ext0 * extrapolate3(xsv_ext0, ysv_ext0, zsv_ext0, dx_ext0, dy_ext0, dz_ext0)
- EndIf
- ''Second extra vertex
- Dim As Double attn_ext1 = 2 - dx_ext1 * dx_ext1 - dy_ext1 * dy_ext1 - dz_ext1 * dz_ext1
- if (attn_ext1 > 0) Then
- attn_ext1 *= attn_ext1
- value += attn_ext1 * attn_ext1 * extrapolate3(xsv_ext1, ysv_ext1, zsv_ext1, dx_ext1, dy_ext1, dz_ext1)
- EndIf
- value/=NORM_CONSTANT_3D
- return value
- End Function
- ''4D OpenSimplex Noise.
- Function OpenSimplexNoise.noise(x As Double ,y As double, z As Double, w As Double) As Double
- ''Place input coordinates on simplectic honeycomb.
- Dim As Double stretchOffset = (x + y + z + w) * STRETCH_CONSTANT_4D
- Dim As Double xs = x + stretchOffset
- Dim As Double ys = y + stretchOffset
- Dim As Double zs = z + stretchOffset
- Dim As Double ws = w + stretchOffset
- ''Floor to get simplectic honeycomb coordinates of rhombo-hypercube super-cell origin.
- Dim As Integer xsb = fastFloor(xs)
- Dim As Integer ysb = fastFloor(ys)
- Dim As Integer zsb = fastFloor(zs)
- Dim As Integer wsb = fastFloor(ws)
- ''Skew out to get actual coordinates of stretched rhombo-hypercube origin. We'll need these later.
- Dim As Double squishOffset = (xsb + ysb + zsb + wsb) * SQUISH_CONSTANT_4D
- Dim As Double xb = xsb + squishOffset
- Dim As Double yb = ysb + squishOffset
- Dim As Double zb = zsb + squishOffset
- Dim As Double wb = wsb + squishOffset
- ''Compute simplectic honeycomb coordinates relative to rhombo-hypercube origin.
- Dim As Double xins = xs - xsb
- Dim As Double yins = ys - ysb
- Dim As Double zins = zs - zsb
- Dim As Double wins = ws - wsb
- ''Sum those together to get a value that determines which region we're in.
- Dim As Double inSum = xins + yins + zins + wins
- ''Positions relative to origin point.
- Dim As Double dx0 = x - xb
- Dim As Double dy0 = y - yb
- Dim As Double dz0 = z - zb
- Dim As Double dw0 = w - wb
- ''We'll be defining these inside the next block and using them afterwards.
- Dim As Double dx_ext0, dy_ext0, dz_ext0, dw_ext0
- Dim As Double dx_ext1, dy_ext1, dz_ext1, dw_ext1
- Dim As Double dx_ext2, dy_ext2, dz_ext2, dw_ext2
- Dim As Integer xsv_ext0, ysv_ext0, zsv_ext0, wsv_ext0
- Dim As Integer xsv_ext1, ysv_ext1, zsv_ext1, wsv_ext1
- Dim As Integer xsv_ext2, ysv_ext2, zsv_ext2, wsv_ext2
- Dim As Double value = 0
- if (inSum <= 1) Then ''We're inside the pentachoron (4-Simplex) at (0,0,0,0)
- ''Determine which two of (0,0,0,1), (0,0,1,0), (0,1,0,0), (1,0,0,0) are closest.
- Dim As Byte aPoint = &h01
- Dim As Double aScore = xins
- Dim As Byte bPoint = &h02
- Dim As Double bScore = yins
- if (aScore >= bScore And zins > bScore) Then
- bScore = zins
- bPoint = &h04
- elseif (aScore < bScore And zins > aScore) Then
- aScore = zins
- aPoint = &h04
- EndIf
- if (aScore >= bScore And wins > bScore) Then
- bScore = wins
- bPoint = &h08
- ElseIf (aScore < bScore And wins > aScore) then
- aScore = wins
- aPoint = &h08
- endif
- ''Now we determine the three lattice points not part of the pentachoron that may contribute.
- ''This depends on the closest two pentachoron vertices, including (0,0,0,0)
- Dim As Double uins = 1 - inSum
- if (uins > aScore Or uins > bScore) Then ''(0,0,0,0) is one of the closest two pentachoron vertices.
- Dim As Byte c = iif(bScore > aScore , bPoint , aPoint) ''Our other closest vertex is the closest out of a and b.
- if ((c and &h01) = 0) Then
- xsv_ext0 = xsb - 1
- xsv_ext1 = xsv_ext2 = xsb
- dx_ext0 = dx0 + 1
- dx_ext1 = dx_ext2 = dx0
- Else
- xsv_ext0 = xsv_ext1 = xsv_ext2 = xsb + 1
- dx_ext0 = dx_ext1 = dx_ext2 = dx0 - 1
- EndIf
- if ((c and &h02) = 0) Then
- ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb
- dy_ext0 = dy_ext1 = dy_ext2 = dy0
- if ((c and &h01) = &h01) Then
- ysv_ext0 -= 1
- dy_ext0 += 1
- Else
- ysv_ext1 -= 1
- dy_ext1 += 1
- EndIf
- Else
- ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb + 1
- dy_ext0 = dy_ext1 = dy_ext2 = dy0 - 1
- EndIf
- if ((c and &h04) = 0) Then
- zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb
- dz_ext0 = dz_ext1 = dz_ext2 = dz0
- if ((c and &h03) <> 0) Then
- if ((c and &h03) = &h03) Then
- zsv_ext0 -= 1
- dz_ext0 += 1
- Else
- zsv_ext1 -= 1
- dz_ext1 += 1
- EndIf
- Else
- zsv_ext2 -= 1
- dz_ext2 += 1
- EndIf
- Else
- zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb + 1
- dz_ext0 = dz_ext1 = dz_ext2 = dz0 - 1
- EndIf
- if ((c and &h08) = 0) Then
- wsv_ext0 = wsv_ext1 = wsb
- wsv_ext2 = wsb - 1
- dw_ext0 = dw_ext1 = dw0
- dw_ext2 = dw0 + 1
- Else
- wsv_ext0 = wsv_ext1 = wsv_ext2 = wsb + 1
- dw_ext0 = dw_ext1 = dw_ext2 = dw0 - 1
- EndIf
- Else ''(0,0,0,0) is not one of the closest two pentachoron vertices.
- Dim As Byte c = cast(Byte,(aPoint or bPoint)) ''Our three extra vertices are determined by the closest two.
- if ((c and &h01) = 0) Then
- xsv_ext0 = xsv_ext2 = xsb
- xsv_ext1 = xsb - 1
- dx_ext0 = dx0 - 2 * SQUISH_CONSTANT_4D
- dx_ext1 = dx0 + 1 - SQUISH_CONSTANT_4D
- dx_ext2 = dx0 - SQUISH_CONSTANT_4D
- Else
- xsv_ext0 = xsv_ext1 = xsv_ext2 = xsb + 1
- dx_ext0 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D
- dx_ext1 = dx_ext2 = dx0 - 1 - SQUISH_CONSTANT_4D
- EndIf
- if ((c and &h02) = 0) Then
- ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb
- dy_ext0 = dy0 - 2 * SQUISH_CONSTANT_4D
- dy_ext1 = dy_ext2 = dy0 - SQUISH_CONSTANT_4D
- if ((c and &h01) = &h01) Then
- ysv_ext1 -= 1
- dy_ext1 += 1
- Else
- ysv_ext2 -= 1
- dy_ext2 += 1
- EndIf
- Else
- ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb + 1
- dy_ext0 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D
- dy_ext1 = dy_ext2 = dy0 - 1 - SQUISH_CONSTANT_4D
- EndIf
- if ((c and &h04) = 0) Then
- zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb
- dz_ext0 = dz0 - 2 * SQUISH_CONSTANT_4D
- dz_ext1 = dz_ext2 = dz0 - SQUISH_CONSTANT_4D
- if ((c and &h03) = &h03) Then
- zsv_ext1 -= 1
- dz_ext1 += 1
- Else
- zsv_ext2 -= 1
- dz_ext2 += 1
- EndIf
- Else
- zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb + 1
- dz_ext0 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D
- dz_ext1 = dz_ext2 = dz0 - 1 - SQUISH_CONSTANT_4D
- EndIf
- if ((c and &h08) = 0) Then
- wsv_ext0 = wsv_ext1 = wsb
- wsv_ext2 = wsb - 1
- dw_ext0 = dw0 - 2 * SQUISH_CONSTANT_4D
- dw_ext1 = dw0 - SQUISH_CONSTANT_4D
- dw_ext2 = dw0 + 1 - SQUISH_CONSTANT_4D
- Else
- wsv_ext0 = wsv_ext1 = wsv_ext2 = wsb + 1
- dw_ext0 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D
- dw_ext1 = dw_ext2 = dw0 - 1 - SQUISH_CONSTANT_4D
- EndIf
- endif
- ''Contribution (0,0,0,0)
- Dim As Double attn0 = 2 - dx0 * dx0 - dy0 * dy0 - dz0 * dz0 - dw0 * dw0
- if (attn0 > 0) Then
- attn0 *= attn0
- value += attn0 * attn0 * extrapolate4(xsb + 0, ysb + 0, zsb + 0, wsb + 0, dx0, dy0, dz0, dw0)
- EndIf
- ''Contribution (1,0,0,0)
- Dim As Double dx1 = dx0 - 1 - SQUISH_CONSTANT_4D
- Dim As Double dy1 = dy0 - 0 - SQUISH_CONSTANT_4D
- Dim As Double dz1 = dz0 - 0 - SQUISH_CONSTANT_4D
- Dim As Double dw1 = dw0 - 0 - SQUISH_CONSTANT_4D
- Dim As Double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1 - dw1 * dw1
- if (attn1 > 0) Then
- attn1 *= attn1
- value += attn1 * attn1 * extrapolate4(xsb + 1, ysb + 0, zsb + 0, wsb + 0, dx1, dy1, dz1, dw1)
- EndIf
- ''Contribution (0,1,0,0)
- Dim As Double dx2 = dx0 - 0 - SQUISH_CONSTANT_4D
- Dim As Double dy2 = dy0 - 1 - SQUISH_CONSTANT_4D
- Dim As Double dz2 = dz1
- Dim As Double dw2 = dw1
- Dim As Double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2 - dw2 * dw2
- if (attn2 > 0) Then
- attn2 *= attn2
- value += attn2 * attn2 * extrapolate4(xsb + 0, ysb + 1, zsb + 0, wsb + 0, dx2, dy2, dz2, dw2)
- EndIf
- ''Contribution (0,0,1,0)
- Dim As Double dx3 = dx2
- Dim As Double dy3 = dy1
- Dim As Double dz3 = dz0 - 1 - SQUISH_CONSTANT_4D
- Dim As Double dw3 = dw1
- Dim As Double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3 - dw3 * dw3
- if (attn3 > 0) Then
- attn3 *= attn3
- value += attn3 * attn3 * extrapolate4(xsb + 0, ysb + 0, zsb + 1, wsb + 0, dx3, dy3, dz3, dw3)
- EndIf
- ''Contribution (0,0,0,1)
- Dim As Double dx4 = dx2
- Dim As Double dy4 = dy1
- Dim As Double dz4 = dz1
- Dim As Double dw4 = dw0 - 1 - SQUISH_CONSTANT_4D
- Dim As Double attn4 = 2 - dx4 * dx4 - dy4 * dy4 - dz4 * dz4 - dw4 * dw4
- if (attn4 > 0) Then
- attn4 *= attn4
- value += attn4 * attn4 * extrapolate4(xsb + 0, ysb + 0, zsb + 0, wsb + 1, dx4, dy4, dz4, dw4)
- EndIf
- Elseif (inSum >= 3) Then ''We're inside the pentachoron (4-Simplex) at (1,1,1,1)
- ''Determine which two of (1,1,1,0), (1,1,0,1), (1,0,1,1), (0,1,1,1) are closest.
- Dim As Byte aPoint = &h0E
- Dim As Double aScore = xins
- Dim As Byte bPoint = &h0D
- Dim As Double bScore = yins
- if (aScore <= bScore And zins < bScore) Then
- bScore = zins
- bPoint = &h0B
- ElseIf (aScore > bScore And zins < aScore) then
- aScore = zins
- aPoint = &h0B
- EndIf
- if (aScore <= bScore And wins < bScore) Then
- bScore = wins
- bPoint = &h07
- ElseIf (aScore > bScore And wins < aScore) then
- aScore = wins
- aPoint = &h07
- EndIf
- ''Now we determine the three lattice points not part of the pentachoron that may contribute.
- ''This depends on the closest two pentachoron vertices, including (0,0,0,0)
- Dim As Double uins = 4 - inSum
- if (uins < aScore Or uins < bScore) Then ''(1,1,1,1) is one of the closest two pentachoron vertices.
- Dim As Byte c = iif(bScore < aScore , bPoint , aPoint) ''Our other closest vertex is the closest out of a and b.
- if ((c and &h01) <> 0) Then
- xsv_ext0 = xsb + 2
- xsv_ext1 = xsv_ext2 = xsb + 1
- dx_ext0 = dx0 - 2 - 4 * SQUISH_CONSTANT_4D
- dx_ext1 = dx_ext2 = dx0 - 1 - 4 * SQUISH_CONSTANT_4D
- Else
- xsv_ext0 = xsv_ext1 = xsv_ext2 = xsb
- dx_ext0 = dx_ext1 = dx_ext2 = dx0 - 4 * SQUISH_CONSTANT_4D
- EndIf
- if ((c and &h02) <> 0) Then
- ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb + 1
- dy_ext0 = dy_ext1 = dy_ext2 = dy0 - 1 - 4 * SQUISH_CONSTANT_4D
- if ((c and &h01) <> 0) Then
- ysv_ext1 += 1
- dy_ext1 -= 1
- Else
- ysv_ext0 += 1
- dy_ext0 -= 1
- EndIf
- Else
- ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb
- dy_ext0 = dy_ext1 = dy_ext2 = dy0 - 4 * SQUISH_CONSTANT_4D
- EndIf
- if ((c and &h04) <> 0) Then
- zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb + 1
- dz_ext0 = dz_ext1 = dz_ext2 = dz0 - 1 - 4 * SQUISH_CONSTANT_4D
- if ((c and &h03) <> &h03) Then
- if ((c and &h03) = 0) Then
- zsv_ext0 += 1
- dz_ext0 -= 1
- Else
- zsv_ext1 += 1
- dz_ext1 -= 1
- EndIf
- Else
- zsv_ext2 += 1
- dz_ext2 -= 1
- EndIf
- Else
- zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb
- dz_ext0 = dz_ext1 = dz_ext2 = dz0 - 4 * SQUISH_CONSTANT_4D
- EndIf
- if ((c and &h08) <> 0) Then
- wsv_ext0 = wsv_ext1 = wsb + 1
- wsv_ext2 = wsb + 2
- dw_ext0 = dw_ext1 = dw0 - 1 - 4 * SQUISH_CONSTANT_4D
- dw_ext2 = dw0 - 2 - 4 * SQUISH_CONSTANT_4D
- Else
- wsv_ext0 = wsv_ext1 = wsv_ext2 = wsb
- dw_ext0 = dw_ext1 = dw_ext2 = dw0 - 4 * SQUISH_CONSTANT_4D
- EndIf
- Else ''(1,1,1,1) is not one of the closest two pentachoron vertices.
- Dim As Byte c = cast(Byte,(aPoint And bPoint)) ''Our three extra vertices are determined by the closest two.
- if ((c and &h01) <> 0) Then
- xsv_ext0 = xsv_ext2 = xsb + 1
- xsv_ext1 = xsb + 2
- dx_ext0 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D
- dx_ext1 = dx0 - 2 - 3 * SQUISH_CONSTANT_4D
- dx_ext2 = dx0 - 1 - 3 * SQUISH_CONSTANT_4D
- Else
- xsv_ext0 = xsv_ext1 = xsv_ext2 = xsb
- dx_ext0 = dx0 - 2 * SQUISH_CONSTANT_4D
- dx_ext1 = dx_ext2 = dx0 - 3 * SQUISH_CONSTANT_4D
- EndIf
- if ((c and &h02) <> 0) Then
- ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb + 1
- dy_ext0 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D
- dy_ext1 = dy_ext2 = dy0 - 1 - 3 * SQUISH_CONSTANT_4D
- if ((c and &h01) <> 0) Then
- ysv_ext2 += 1
- dy_ext2 -= 1
- Else
- ysv_ext1 += 1
- dy_ext1 -= 1
- EndIf
- Else
- ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb
- dy_ext0 = dy0 - 2 * SQUISH_CONSTANT_4D
- dy_ext1 = dy_ext2 = dy0 - 3 * SQUISH_CONSTANT_4D
- EndIf
- if ((c and &h04) <> 0) Then
- zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb + 1
- dz_ext0 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D
- dz_ext1 = dz_ext2 = dz0 - 1 - 3 * SQUISH_CONSTANT_4D
- if ((c and &h03) <> 0) Then
- zsv_ext2 += 1
- dz_ext2 -= 1
- Else
- zsv_ext1 += 1
- dz_ext1 -= 1
- EndIf
- Else
- zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb
- dz_ext0 = dz0 - 2 * SQUISH_CONSTANT_4D
- dz_ext1 = dz_ext2 = dz0 - 3 * SQUISH_CONSTANT_4D
- EndIf
- if ((c and &h08) <> 0) Then
- wsv_ext0 = wsv_ext1 = wsb + 1
- wsv_ext2 = wsb + 2
- dw_ext0 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D
- dw_ext1 = dw0 - 1 - 3 * SQUISH_CONSTANT_4D
- dw_ext2 = dw0 - 2 - 3 * SQUISH_CONSTANT_4D
- Else
- wsv_ext0 = wsv_ext1 = wsv_ext2 = wsb
- dw_ext0 = dw0 - 2 * SQUISH_CONSTANT_4D
- dw_ext1 = dw_ext2 = dw0 - 3 * SQUISH_CONSTANT_4D
- EndIf
- endif
- ''Contribution (1,1,1,0)
- Dim As Double dx4 = dx0 - 1 - 3 * SQUISH_CONSTANT_4D
- Dim As Double dy4 = dy0 - 1 - 3 * SQUISH_CONSTANT_4D
- Dim As Double dz4 = dz0 - 1 - 3 * SQUISH_CONSTANT_4D
- Dim As Double dw4 = dw0 - 3 * SQUISH_CONSTANT_4D
- Dim As Double attn4 = 2 - dx4 * dx4 - dy4 * dy4 - dz4 * dz4 - dw4 * dw4
- if (attn4 > 0) Then
- attn4 *= attn4
- value += attn4 * attn4 * extrapolate4(xsb + 1, ysb + 1, zsb + 1, wsb + 0, dx4, dy4, dz4, dw4)
- EndIf
- ''Contribution (1,1,0,1)
- Dim As Double dx3 = dx4
- Dim As Double dy3 = dy4
- Dim As Double dz3 = dz0 - 3 * SQUISH_CONSTANT_4D
- Dim As Double dw3 = dw0 - 1 - 3 * SQUISH_CONSTANT_4D
- Dim As Double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3 - dw3 * dw3
- if (attn3 > 0) Then
- attn3 *= attn3
- value += attn3 * attn3 * extrapolate4(xsb + 1, ysb + 1, zsb + 0, wsb + 1, dx3, dy3, dz3, dw3)
- EndIf
- ''Contribution (1,0,1,1)
- Dim As Double dx2 = dx4
- Dim As Double dy2 = dy0 - 3 * SQUISH_CONSTANT_4D
- Dim As Double dz2 = dz4
- Dim As Double dw2 = dw3
- Dim As Double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2 - dw2 * dw2
- if (attn2 > 0) Then
- attn2 *= attn2
- value += attn2 * attn2 * extrapolate4(xsb + 1, ysb + 0, zsb + 1, wsb + 1, dx2, dy2, dz2, dw2)
- EndIf
- ''Contribution (0,1,1,1)
- Dim As Double dx1 = dx0 - 3 * SQUISH_CONSTANT_4D
- Dim As Double dz1 = dz4
- Dim As Double dy1 = dy4
- Dim As Double dw1 = dw3
- Dim As Double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1 - dw1 * dw1
- if (attn1 > 0) Then
- attn1 *= attn1
- value += attn1 * attn1 * extrapolate4(xsb + 0, ysb + 1, zsb + 1, wsb + 1, dx1, dy1, dz1, dw1)
- EndIf
- ''Contribution (1,1,1,1)
- dx0 = dx0 - 1 - 4 * SQUISH_CONSTANT_4D
- dy0 = dy0 - 1 - 4 * SQUISH_CONSTANT_4D
- dz0 = dz0 - 1 - 4 * SQUISH_CONSTANT_4D
- dw0 = dw0 - 1 - 4 * SQUISH_CONSTANT_4D
- Dim As Double attn0 = 2 - dx0 * dx0 - dy0 * dy0 - dz0 * dz0 - dw0 * dw0
- if (attn0 > 0) Then
- attn0 *= attn0
- value += attn0 * attn0 * extrapolate4(xsb + 1, ysb + 1, zsb + 1, wsb + 1, dx0, dy0, dz0, dw0)
- EndIf
- ElseIf (inSum <= 2) then ''We're inside the first dispentachoron (Rectified 4-Simplex)
- Dim As Double aScore
- Dim As Byte aPoint
- Dim As boolean aIsBiggerSide = TRUE
- Dim As Double bScore
- Dim As Byte bPoint
- Dim As boolean bIsBiggerSide = TRUE
- ''Decide between (1,1,0,0) and (0,0,1,1)
- if (xins + yins > zins + wins) Then
- aScore = xins + yins
- aPoint = &h03
- Else
- aScore = zins + wins
- aPoint = &h0C
- EndIf
- ''Decide between (1,0,1,0) and (0,1,0,1)
- if (xins + zins > yins + wins) Then
- bScore = xins + zins
- bPoint = &h05
- Else
- bScore = yins + wins
- bPoint = &h0A
- EndIf
- ''Closer between (1,0,0,1) and (0,1,1,0) will replace the further of a and b, if closer.
- if (xins + wins > yins + zins) Then
- Dim As Double score = xins + wins
- if (aScore >= bScore And score > bScore) Then
- bScore = score
- bPoint = &h09
- ElseIf (aScore < bScore And score > aScore) then
- aScore = score
- aPoint = &h09
- EndIf
- Else
- Dim As Double score = yins + zins
- if (aScore >= bScore And score > bScore) Then
- bScore = score
- bPoint = &h06
- ElseIf (aScore < bScore And score > aScore) then
- aScore = score
- aPoint = &h06
- EndIf
- EndIf
- ''Decide if (1,0,0,0) is closer.
- Dim As Double p1 = 2 - inSum + xins
- if (aScore >= bScore And p1 > bScore) Then
- bScore = p1
- bPoint = &h01
- bIsBiggerSide = FALSE
- ElseIf (aScore < bScore And p1 > aScore) then
- aScore = p1
- aPoint = &h01
- aIsBiggerSide = FALSE
- EndIf
- ''Decide if (0,1,0,0) is closer.
- Dim As Double p2 = 2 - inSum + yins
- if (aScore >= bScore And p2 > bScore) Then
- bScore = p2
- bPoint = &h02
- bIsBiggerSide = FALSE
- ElseIf (aScore < bScore And p2 > aScore) Then
- aScore = p2
- aPoint = &h02
- aIsBiggerSide = FALSE
- EndIf
- ''Decide if (0,0,1,0) is closer.
- Dim As Double p3 = 2 - inSum + zins
- if (aScore >= bScore And p3 > bScore) Then
- bScore = p3
- bPoint = &h04
- bIsBiggerSide = FALSE
- elseif (aScore < bScore And p3 > aScore) Then
- aScore = p3
- aPoint = &h04
- aIsBiggerSide = FALSE
- EndIf
- ''Decide if (0,0,0,1) is closer.
- Dim As Double p4 = 2 - inSum + wins
- if (aScore >= bScore And p4 > bScore) Then
- bScore = p4
- bPoint = &h08
- bIsBiggerSide = FALSE
- ElseIf (aScore < bScore And p4 > aScore) then
- aScore = p4
- aPoint = &h08
- aIsBiggerSide = FALSE
- endif
- ''Where each of the two closest points are determines how the extra three vertices are calculated.
- if (aIsBiggerSide = bIsBiggerSide) Then
- if (aIsBiggerSide) then ''Both closest points on the bigger side
- Dim As Byte c1 = Cast(Byte,(aPoint or bPoint))
- Dim As Byte c2 = cast(Byte,(aPoint And bPoint))
- if ((c1 and &h01) = 0) Then
- xsv_ext0 = xsb
- xsv_ext1 = xsb - 1
- dx_ext0 = dx0 - 3 * SQUISH_CONSTANT_4D
- dx_ext1 = dx0 + 1 - 2 * SQUISH_CONSTANT_4D
- Else
- xsv_ext0 = xsv_ext1 = xsb + 1
- dx_ext0 = dx0 - 1 - 3 * SQUISH_CONSTANT_4D
- dx_ext1 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D
- EndIf
- if ((c1 and &h02) = 0) Then
- ysv_ext0 = ysb
- ysv_ext1 = ysb - 1
- dy_ext0 = dy0 - 3 * SQUISH_CONSTANT_4D
- dy_ext1 = dy0 + 1 - 2 * SQUISH_CONSTANT_4D
- Else
- ysv_ext0 = ysv_ext1 = ysb + 1
- dy_ext0 = dy0 - 1 - 3 * SQUISH_CONSTANT_4D
- dy_ext1 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D
- endif
- if ((c1 and &h04) = 0) Then
- zsv_ext0 = zsb
- zsv_ext1 = zsb - 1
- dz_ext0 = dz0 - 3 * SQUISH_CONSTANT_4D
- dz_ext1 = dz0 + 1 - 2 * SQUISH_CONSTANT_4D
- Else
- zsv_ext0 = zsv_ext1 = zsb + 1
- dz_ext0 = dz0 - 1 - 3 * SQUISH_CONSTANT_4D
- dz_ext1 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D
- EndIf
- if ((c1 and &h08) = 0) Then
- wsv_ext0 = wsb
- wsv_ext1 = wsb - 1
- dw_ext0 = dw0 - 3 * SQUISH_CONSTANT_4D
- dw_ext1 = dw0 + 1 - 2 * SQUISH_CONSTANT_4D
- Else
- wsv_ext0 = wsv_ext1 = wsb + 1
- dw_ext0 = dw0 - 1 - 3 * SQUISH_CONSTANT_4D
- dw_ext1 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D
- endif
- ''One combination is a permutation of (0,0,0,2) based on c2
- xsv_ext2 = xsb
- ysv_ext2 = ysb
- zsv_ext2 = zsb
- wsv_ext2 = wsb
- dx_ext2 = dx0 - 2 * SQUISH_CONSTANT_4D
- dy_ext2 = dy0 - 2 * SQUISH_CONSTANT_4D
- dz_ext2 = dz0 - 2 * SQUISH_CONSTANT_4D
- dw_ext2 = dw0 - 2 * SQUISH_CONSTANT_4D
- if ((c2 and &h01) <> 0) Then
- xsv_ext2 += 2
- dx_ext2 -= 2
- ElseIf ((c2 and &h02) <> 0) Then
- ysv_ext2 += 2
- dy_ext2 -= 2
- ElseIf ((c2 and &h04) <> 0) then
- zsv_ext2 += 2
- dz_ext2 -= 2
- Else
- wsv_ext2 += 2
- dw_ext2 -= 2
- endif
- Else ''Both closest points on the smaller side
- ''One of the two extra points is (0,0,0,0)
- xsv_ext2 = xsb
- ysv_ext2 = ysb
- zsv_ext2 = zsb
- wsv_ext2 = wsb
- dx_ext2 = dx0
- dy_ext2 = dy0
- dz_ext2 = dz0
- dw_ext2 = dw0
- ''Other two points are based on the omitted axes.
- Dim As Byte c = cast(Byte,(aPoint or bPoint))
- if ((c and &h01) = 0) Then
- xsv_ext0 = xsb - 1
- xsv_ext1 = xsb
- dx_ext0 = dx0 + 1 - SQUISH_CONSTANT_4D
- dx_ext1 = dx0 - SQUISH_CONSTANT_4D
- Else
- xsv_ext0 = xsv_ext1 = xsb + 1
- dx_ext0 = dx_ext1 = dx0 - 1 - SQUISH_CONSTANT_4D
- EndIf
- if ((c and &h02) = 0) Then
- ysv_ext0 = ysv_ext1 = ysb
- dy_ext0 = dy_ext1 = dy0 - SQUISH_CONSTANT_4D
- if ((c and &h01) = &h01) Then
- ysv_ext0 -= 1
- dy_ext0 += 1
- Else
- ysv_ext1 -= 1
- dy_ext1 += 1
- EndIf
- Else
- ysv_ext0 = ysv_ext1 = ysb + 1
- dy_ext0 = dy_ext1 = dy0 - 1 - SQUISH_CONSTANT_4D
- EndIf
- if ((c and &h04) = 0) Then
- zsv_ext0 = zsv_ext1 = zsb
- dz_ext0 = dz_ext1 = dz0 - SQUISH_CONSTANT_4D
- if ((c and &h03) = &h03) Then
- zsv_ext0 -= 1
- dz_ext0 += 1
- Else
- zsv_ext1 -= 1
- dz_ext1 += 1
- EndIf
- Else
- zsv_ext0 = zsv_ext1 = zsb + 1
- dz_ext0 = dz_ext1 = dz0 - 1 - SQUISH_CONSTANT_4D
- EndIf
- if ((c and &h08) = 0) Then
- wsv_ext0 = wsb
- wsv_ext1 = wsb - 1
- dw_ext0 = dw0 - SQUISH_CONSTANT_4D
- dw_ext1 = dw0 + 1 - SQUISH_CONSTANT_4D
- Else
- wsv_ext0 = wsv_ext1 = wsb + 1
- dw_ext0 = dw_ext1 = dw0 - 1 - SQUISH_CONSTANT_4D
- EndIf
- EndIf
- Else ''One point on each "side"
- Dim As Byte c1, c2
- if (aIsBiggerSide) Then
- c1 = aPoint
- c2 = bPoint
- Else
- c1 = bPoint
- c2 = aPoint
- EndIf
- ''Two contributions are the bigger-sided point with each 0 replaced with -1.
- if ((c1 and &h01) = 0) Then
- xsv_ext0 = xsb - 1
- xsv_ext1 = xsb
- dx_ext0 = dx0 + 1 - SQUISH_CONSTANT_4D
- dx_ext1 = dx0 - SQUISH_CONSTANT_4D
- Else
- xsv_ext0 = xsv_ext1 = xsb + 1
- dx_ext0 = dx_ext1 = dx0 - 1 - SQUISH_CONSTANT_4D
- EndIf
- if ((c1 and &h02) = 0) Then
- ysv_ext0 = ysv_ext1 = ysb
- dy_ext0 = dy_ext1 = dy0 - SQUISH_CONSTANT_4D
- if ((c1 and &h01) = &h01) Then
- ysv_ext0 -= 1
- dy_ext0 += 1
- Else
- ysv_ext1 -= 1
- dy_ext1 += 1
- EndIf
- Else
- ysv_ext0 = ysv_ext1 = ysb + 1
- dy_ext0 = dy_ext1 = dy0 - 1 - SQUISH_CONSTANT_4D
- EndIf
- if ((c1 and &h04) = 0) Then
- zsv_ext0 = zsv_ext1 = zsb
- dz_ext0 = dz_ext1 = dz0 - SQUISH_CONSTANT_4D
- if ((c1 and &h03) = &h03) Then
- zsv_ext0 -= 1
- dz_ext0 += 1
- Else
- zsv_ext1 -= 1
- dz_ext1 += 1
- EndIf
- Else
- zsv_ext0 = zsv_ext1 = zsb + 1
- dz_ext0 = dz_ext1 = dz0 - 1 - SQUISH_CONSTANT_4D
- EndIf
- if ((c1 and &h08) = 0) Then
- wsv_ext0 = wsb
- wsv_ext1 = wsb - 1
- dw_ext0 = dw0 - SQUISH_CONSTANT_4D
- dw_ext1 = dw0 + 1 - SQUISH_CONSTANT_4D
- Else
- wsv_ext0 = wsv_ext1 = wsb + 1
- dw_ext0 = dw_ext1 = dw0 - 1 - SQUISH_CONSTANT_4D
- EndIf
- ''One contribution is a permutation of (0,0,0,2) based on the smaller-sided point
- xsv_ext2 = xsb
- ysv_ext2 = ysb
- zsv_ext2 = zsb
- wsv_ext2 = wsb
- dx_ext2 = dx0 - 2 * SQUISH_CONSTANT_4D
- dy_ext2 = dy0 - 2 * SQUISH_CONSTANT_4D
- dz_ext2 = dz0 - 2 * SQUISH_CONSTANT_4D
- dw_ext2 = dw0 - 2 * SQUISH_CONSTANT_4D
- if ((c2 and &h01) <> 0) Then
- xsv_ext2 += 2
- dx_ext2 -= 2
- ElseIf ((c2 and &h02) <> 0) Then
- ysv_ext2 += 2
- dy_ext2 -= 2
- elseif ((c2 and &h04) <> 0) Then
- zsv_ext2 += 2
- dz_ext2 -= 2
- Else
- wsv_ext2 += 2
- dw_ext2 -= 2
- EndIf
- EndIf
- ''Contribution (1,0,0,0)
- Dim As Double dx1 = dx0 - 1 - SQUISH_CONSTANT_4D
- Dim As Double dy1 = dy0 - 0 - SQUISH_CONSTANT_4D
- Dim As Double dz1 = dz0 - 0 - SQUISH_CONSTANT_4D
- Dim As Double dw1 = dw0 - 0 - SQUISH_CONSTANT_4D
- Dim As Double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1 - dw1 * dw1
- if (attn1 > 0) Then
- attn1 *= attn1
- value += attn1 * attn1 * extrapolate4(xsb + 1, ysb + 0, zsb + 0, wsb + 0, dx1, dy1, dz1, dw1)
- EndIf
- ''Contribution (0,1,0,0)
- Dim As Double dx2 = dx0 - 0 - SQUISH_CONSTANT_4D
- Dim As Double dy2 = dy0 - 1 - SQUISH_CONSTANT_4D
- Dim As Double dz2 = dz1
- Dim As Double dw2 = dw1
- Dim As Double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2 - dw2 * dw2
- if (attn2 > 0) Then
- attn2 *= attn2
- value += attn2 * attn2 * extrapolate4(xsb + 0, ysb + 1, zsb + 0, wsb + 0, dx2, dy2, dz2, dw2)
- EndIf
- ''Contribution (0,0,1,0)
- Dim As Double dx3 = dx2
- Dim As Double dy3 = dy1
- Dim As Double dz3 = dz0 - 1 - SQUISH_CONSTANT_4D
- Dim As Double dw3 = dw1
- Dim As Double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3 - dw3 * dw3
- if (attn3 > 0) Then
- attn3 *= attn3
- value += attn3 * attn3 * extrapolate4(xsb + 0, ysb + 0, zsb + 1, wsb + 0, dx3, dy3, dz3, dw3)
- EndIf
- ''Contribution (0,0,0,1)
- Dim As Double dx4 = dx2
- Dim As Double dy4 = dy1
- Dim As Double dz4 = dz1
- Dim As Double dw4 = dw0 - 1 - SQUISH_CONSTANT_4D
- Dim As Double attn4 = 2 - dx4 * dx4 - dy4 * dy4 - dz4 * dz4 - dw4 * dw4
- if (attn4 > 0) Then
- attn4 *= attn4
- value += attn4 * attn4 * extrapolate4(xsb + 0, ysb + 0, zsb + 0, wsb + 1, dx4, dy4, dz4, dw4)
- EndIf
- ''Contribution (1,1,0,0)
- Dim As Double dx5 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dy5 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dz5 = dz0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dw5 = dw0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double attn5 = 2 - dx5 * dx5 - dy5 * dy5 - dz5 * dz5 - dw5 * dw5
- if (attn5 > 0) Then
- attn5 *= attn5
- value += attn5 * attn5 * extrapolate4(xsb + 1, ysb + 1, zsb + 0, wsb + 0, dx5, dy5, dz5, dw5)
- EndIf
- ''Contribution (1,0,1,0)
- Dim As Double dx6 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dy6 = dy0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dz6 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dw6 = dw0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double attn6 = 2 - dx6 * dx6 - dy6 * dy6 - dz6 * dz6 - dw6 * dw6
- if (attn6 > 0) Then
- attn6 *= attn6
- value += attn6 * attn6 * extrapolate4(xsb + 1, ysb + 0, zsb + 1, wsb + 0, dx6, dy6, dz6, dw6)
- EndIf
- ''Contribution (1,0,0,1)
- Dim As Double dx7 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dy7 = dy0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dz7 = dz0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dw7 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double attn7 = 2 - dx7 * dx7 - dy7 * dy7 - dz7 * dz7 - dw7 * dw7
- if (attn7 > 0) Then
- attn7 *= attn7
- value += attn7 * attn7 * extrapolate4(xsb + 1, ysb + 0, zsb + 0, wsb + 1, dx7, dy7, dz7, dw7)
- EndIf
- ''Contribution (0,1,1,0)
- Dim As Double dx8 = dx0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dy8 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dz8 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dw8 = dw0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double attn8 = 2 - dx8 * dx8 - dy8 * dy8 - dz8 * dz8 - dw8 * dw8
- if (attn8 > 0) Then
- attn8 *= attn8
- value += attn8 * attn8 * extrapolate4(xsb + 0, ysb + 1, zsb + 1, wsb + 0, dx8, dy8, dz8, dw8)
- EndIf
- ''Contribution (0,1,0,1)
- Dim As Double dx9 = dx0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dy9 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dz9 = dz0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dw9 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double attn9 = 2 - dx9 * dx9 - dy9 * dy9 - dz9 * dz9 - dw9 * dw9
- if (attn9 > 0) Then
- attn9 *= attn9
- value += attn9 * attn9 * extrapolate4(xsb + 0, ysb + 1, zsb + 0, wsb + 1, dx9, dy9, dz9, dw9)
- EndIf
- ''Contribution (0,0,1,1)
- Dim As Double dx10 = dx0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dy10 = dy0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dz10 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dw10 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double attn10 = 2 - dx10 * dx10 - dy10 * dy10 - dz10 * dz10 - dw10 * dw10
- if (attn10 > 0) Then
- attn10 *= attn10
- value += attn10 * attn10 * extrapolate4(xsb + 0, ysb + 0, zsb + 1, wsb + 1, dx10, dy10, dz10, dw10)
- EndIf
- Else ''We're inside the second dispentachoron (Rectified 4-Simplex)
- Dim As Double aScore
- Dim As Byte aPoint
- Dim As boolean aIsBiggerSide = TRUE
- Dim As Double bScore
- Dim As Byte bPoint
- Dim As boolean bIsBiggerSide = TRUE
- ''Decide between (0,0,1,1) and (1,1,0,0)
- if (xins + yins < zins + wins) Then
- aScore = xins + yins
- aPoint = &h0C
- Else
- aScore = zins + wins
- aPoint = &h03
- EndIf
- ''Decide between (0,1,0,1) and (1,0,1,0)
- if (xins + zins < yins + wins) Then
- bScore = xins + zins
- bPoint = &h0A
- Else
- bScore = yins + wins
- bPoint = &h05
- EndIf
- ''Closer between (0,1,1,0) and (1,0,0,1) will replace the further of a and b, if closer.
- if (xins + wins < yins + zins) Then
- Dim As Double score = xins + wins
- if (aScore <= bScore And score < bScore) Then
- bScore = score
- bPoint = &h06
- ElseIf (aScore > bScore And score < aScore) Then
- aScore = score
- aPoint = &h06
- EndIf
- Else
- Dim As Double score = yins + zins
- if (aScore <= bScore And score < bScore) Then
- bScore = score
- bPoint = &h09
- elseif (aScore > bScore And score < aScore) Then
- aScore = score
- aPoint = &h09
- EndIf
- EndIf
- ''Decide if (0,1,1,1) is closer.
- Dim As Double p1 = 3 - inSum + xins
- if (aScore <= bScore And p1 < bScore) Then
- bScore = p1
- bPoint = &h0E
- bIsBiggerSide = FALSE
- ElseIf (aScore > bScore And p1 < aScore) Then
- aScore = p1
- aPoint = &h0E
- aIsBiggerSide = FALSE
- EndIf
- ''Decide if (1,0,1,1) is closer.
- Dim As Double p2 = 3 - inSum + yins
- if (aScore <= bScore And p2 < bScore) Then
- bScore = p2
- bPoint = &h0D
- bIsBiggerSide = FALSE
- ElseIf (aScore > bScore And p2 < aScore) Then
- aScore = p2
- aPoint = &h0D
- aIsBiggerSide = FALSE
- EndIf
- ''Decide if (1,1,0,1) is closer.
- Dim As Double p3 = 3 - inSum + zins
- if (aScore <= bScore And p3 < bScore) Then
- bScore = p3
- bPoint = &h0B
- bIsBiggerSide = FALSE
- ElseIf (aScore > bScore And p3 < aScore) Then
- aScore = p3
- aPoint = &h0B
- aIsBiggerSide = FALSE
- EndIf
- ''Decide if (1,1,1,0) is closer.
- Dim As Double p4 = 3 - inSum + wins
- if (aScore <= bScore And p4 < bScore) Then
- bScore = p4
- bPoint = &h07
- bIsBiggerSide = FALSE
- elseif (aScore > bScore and p4 < aScore) Then
- aScore = p4
- aPoint = &h07
- aIsBiggerSide = FALSE
- EndIf
- ''Where each of the two closest points are determines how the extra three vertices are calculated.
- if (aIsBiggerSide = bIsBiggerSide) Then
- if (aIsBiggerSide) Then ''Both closest points on the bigger side
- Dim As Byte c1 = Cast(Byte,(aPoint And bPoint))
- Dim As Byte c2 = cast(Byte,(aPoint or bPoint))
- ''Two contributions are permutations of (0,0,0,1) and (0,0,0,2) based on c1
- xsv_ext0 = xsv_ext1 = xsb
- ysv_ext0 = ysv_ext1 = ysb
- zsv_ext0 = zsv_ext1 = zsb
- wsv_ext0 = wsv_ext1 = wsb
- dx_ext0 = dx0 - SQUISH_CONSTANT_4D
- dy_ext0 = dy0 - SQUISH_CONSTANT_4D
- dz_ext0 = dz0 - SQUISH_CONSTANT_4D
- dw_ext0 = dw0 - SQUISH_CONSTANT_4D
- dx_ext1 = dx0 - 2 * SQUISH_CONSTANT_4D
- dy_ext1 = dy0 - 2 * SQUISH_CONSTANT_4D
- dz_ext1 = dz0 - 2 * SQUISH_CONSTANT_4D
- dw_ext1 = dw0 - 2 * SQUISH_CONSTANT_4D
- if ((c1 and &h01) <> 0) Then
- xsv_ext0 += 1
- dx_ext0 -= 1
- xsv_ext1 += 2
- dx_ext1 -= 2
- ElseIf ((c1 and &h02) <> 0) Then
- ysv_ext0 += 1
- dy_ext0 -= 1
- ysv_ext1 += 2
- dy_ext1 -= 2
- ElseIf ((c1 and &h04) <> 0) Then
- zsv_ext0 += 1
- dz_ext0 -= 1
- zsv_ext1 += 2
- dz_ext1 -= 2
- Else
- wsv_ext0 += 1
- dw_ext0 -= 1
- wsv_ext1 += 2
- dw_ext1 -= 2
- EndIf
- ''One contribution is a permutation of (1,1,1,-1) based on c2
- xsv_ext2 = xsb + 1
- ysv_ext2 = ysb + 1
- zsv_ext2 = zsb + 1
- wsv_ext2 = wsb + 1
- dx_ext2 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D
- dy_ext2 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D
- dz_ext2 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D
- dw_ext2 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D
- if ((c2 and &h01) = 0) Then
- xsv_ext2 -= 2
- dx_ext2 += 2
- ElseIf ((c2 and &h02) = 0) Then
- ysv_ext2 -= 2
- dy_ext2 += 2
- ElseIf ((c2 and &h04) = 0) Then
- zsv_ext2 -= 2
- dz_ext2 += 2
- Else
- wsv_ext2 -= 2
- dw_ext2 += 2
- EndIf
- Else ''Both closest points on the smaller side
- ''One of the two extra points is (1,1,1,1)
- xsv_ext2 = xsb + 1
- ysv_ext2 = ysb + 1
- zsv_ext2 = zsb + 1
- wsv_ext2 = wsb + 1
- dx_ext2 = dx0 - 1 - 4 * SQUISH_CONSTANT_4D
- dy_ext2 = dy0 - 1 - 4 * SQUISH_CONSTANT_4D
- dz_ext2 = dz0 - 1 - 4 * SQUISH_CONSTANT_4D
- dw_ext2 = dw0 - 1 - 4 * SQUISH_CONSTANT_4D
- ''Other two points are based on the shared axes.
- Dim As Byte c = cast(Byte,(aPoint And bPoint))
- if ((c and &h01) <> 0) Then
- xsv_ext0 = xsb + 2
- xsv_ext1 = xsb + 1
- dx_ext0 = dx0 - 2 - 3 * SQUISH_CONSTANT_4D
- dx_ext1 = dx0 - 1 - 3 * SQUISH_CONSTANT_4D
- Else
- xsv_ext0 = xsv_ext1 = xsb
- dx_ext0 = dx_ext1 = dx0 - 3 * SQUISH_CONSTANT_4D
- EndIf
- if ((c and &h02) <> 0) Then
- ysv_ext0 = ysv_ext1 = ysb + 1
- dy_ext0 = dy_ext1 = dy0 - 1 - 3 * SQUISH_CONSTANT_4D
- if ((c and &h01) = 0) Then
- ysv_ext0 += 1
- dy_ext0 -= 1
- Else
- ysv_ext1 += 1
- dy_ext1 -= 1
- EndIf
- Else
- ysv_ext0 = ysv_ext1 = ysb
- dy_ext0 = dy_ext1 = dy0 - 3 * SQUISH_CONSTANT_4D
- EndIf
- if ((c and &h04) <> 0) Then
- zsv_ext0 = zsv_ext1 = zsb + 1
- dz_ext0 = dz_ext1 = dz0 - 1 - 3 * SQUISH_CONSTANT_4D
- if ((c and &h03) = 0) Then
- zsv_ext0 += 1
- dz_ext0 -= 1
- Else
- zsv_ext1 += 1
- dz_ext1 -= 1
- EndIf
- Else
- zsv_ext0 = zsv_ext1 = zsb
- dz_ext0 = dz_ext1 = dz0 - 3 * SQUISH_CONSTANT_4D
- EndIf
- if ((c and &h08) <> 0) Then
- wsv_ext0 = wsb + 1
- wsv_ext1 = wsb + 2
- dw_ext0 = dw0 - 1 - 3 * SQUISH_CONSTANT_4D
- dw_ext1 = dw0 - 2 - 3 * SQUISH_CONSTANT_4D
- Else
- wsv_ext0 = wsv_ext1 = wsb
- dw_ext0 = dw_ext1 = dw0 - 3 * SQUISH_CONSTANT_4D
- EndIf
- EndIf
- Else ''One point on each "side"
- Dim As Byte c1, c2
- if (aIsBiggerSide) Then
- c1 = aPoint
- c2 = bPoint
- Else
- c1 = bPoint
- c2 = aPoint
- EndIf
- ''Two contributions are the bigger-sided point with each 1 replaced with 2.
- if ((c1 and &h01) <> 0) Then
- xsv_ext0 = xsb + 2
- xsv_ext1 = xsb + 1
- dx_ext0 = dx0 - 2 - 3 * SQUISH_CONSTANT_4D
- dx_ext1 = dx0 - 1 - 3 * SQUISH_CONSTANT_4D
- Else
- xsv_ext0 = xsv_ext1 = xsb
- dx_ext0 = dx_ext1 = dx0 - 3 * SQUISH_CONSTANT_4D
- EndIf
- if ((c1 and &h02) <> 0) Then
- ysv_ext0 = ysv_ext1 = ysb + 1
- dy_ext0 = dy_ext1 = dy0 - 1 - 3 * SQUISH_CONSTANT_4D
- if ((c1 and &h01) = 0) Then
- ysv_ext0 += 1
- dy_ext0 -= 1
- Else
- ysv_ext1 += 1
- dy_ext1 -= 1
- EndIf
- Else
- ysv_ext0 = ysv_ext1 = ysb
- dy_ext0 = dy_ext1 = dy0 - 3 * SQUISH_CONSTANT_4D
- EndIf
- if ((c1 and &h04) <> 0) Then
- zsv_ext0 = zsv_ext1 = zsb + 1
- dz_ext0 = dz_ext1 = dz0 - 1 - 3 * SQUISH_CONSTANT_4D
- if ((c1 and &h03) = 0) Then
- zsv_ext0 += 1
- dz_ext0 -= 1
- Else
- zsv_ext1 += 1
- dz_ext1 -= 1
- EndIf
- Else
- zsv_ext0 = zsv_ext1 = zsb
- dz_ext0 = dz_ext1 = dz0 - 3 * SQUISH_CONSTANT_4D
- EndIf
- if ((c1 and &h08) <> 0) Then
- wsv_ext0 = wsb + 1
- wsv_ext1 = wsb + 2
- dw_ext0 = dw0 - 1 - 3 * SQUISH_CONSTANT_4D
- dw_ext1 = dw0 - 2 - 3 * SQUISH_CONSTANT_4D
- Else
- wsv_ext0 = wsv_ext1 = wsb
- dw_ext0 = dw_ext1 = dw0 - 3 * SQUISH_CONSTANT_4D
- EndIf
- ''One contribution is a permutation of (1,1,1,-1) based on the smaller-sided point
- xsv_ext2 = xsb + 1
- ysv_ext2 = ysb + 1
- zsv_ext2 = zsb + 1
- wsv_ext2 = wsb + 1
- dx_ext2 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D
- dy_ext2 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D
- dz_ext2 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D
- dw_ext2 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D
- if ((c2 and &h01) = 0) Then
- xsv_ext2 -= 2
- dx_ext2 += 2
- ElseIf ((c2 and &h02) = 0) Then
- ysv_ext2 -= 2
- dy_ext2 += 2
- ElseIf ((c2 And &h04) = 0) Then
- zsv_ext2 -= 2
- dz_ext2 += 2
- else
- wsv_ext2 -= 2
- dw_ext2 += 2
- EndIf
- EndIf
- ''Contribution (1,1,1,0)
- Dim As Double dx4 = dx0 - 1 - 3 * SQUISH_CONSTANT_4D
- Dim As Double dy4 = dy0 - 1 - 3 * SQUISH_CONSTANT_4D
- Dim As Double dz4 = dz0 - 1 - 3 * SQUISH_CONSTANT_4D
- Dim As Double dw4 = dw0 - 3 * SQUISH_CONSTANT_4D
- Dim As Double attn4 = 2 - dx4 * dx4 - dy4 * dy4 - dz4 * dz4 - dw4 * dw4
- if (attn4 > 0) Then
- attn4 *= attn4
- value += attn4 * attn4 * extrapolate4(xsb + 1, ysb + 1, zsb + 1, wsb + 0, dx4, dy4, dz4, dw4)
- EndIf
- ''Contribution (1,1,0,1)
- Dim As Double dx3 = dx4
- Dim As Double dy3 = dy4
- Dim As Double dz3 = dz0 - 3 * SQUISH_CONSTANT_4D
- Dim As Double dw3 = dw0 - 1 - 3 * SQUISH_CONSTANT_4D
- Dim As Double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3 - dw3 * dw3
- if (attn3 > 0) Then
- attn3 *= attn3
- value += attn3 * attn3 * extrapolate4(xsb + 1, ysb + 1, zsb + 0, wsb + 1, dx3, dy3, dz3, dw3)
- EndIf
- ''Contribution (1,0,1,1)
- Dim As Double dx2 = dx4
- Dim As Double dy2 = dy0 - 3 * SQUISH_CONSTANT_4D
- Dim As Double dz2 = dz4
- Dim As Double dw2 = dw3
- Dim As Double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2 - dw2 * dw2
- if (attn2 > 0) Then
- attn2 *= attn2
- value += attn2 * attn2 * extrapolate4(xsb + 1, ysb + 0, zsb + 1, wsb + 1, dx2, dy2, dz2, dw2)
- EndIf
- ''Contribution (0,1,1,1)
- Dim As Double dx1 = dx0 - 3 * SQUISH_CONSTANT_4D
- Dim As Double dz1 = dz4
- Dim As Double dy1 = dy4
- Dim As Double dw1 = dw3
- Dim As Double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1 - dw1 * dw1
- if (attn1 > 0) Then
- attn1 *= attn1
- value += attn1 * attn1 * extrapolate4(xsb + 0, ysb + 1, zsb + 1, wsb + 1, dx1, dy1, dz1, dw1)
- EndIf
- ''Contribution (1,1,0,0)
- Dim As Double dx5 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dy5 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dz5 = dz0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dw5 = dw0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double attn5 = 2 - dx5 * dx5 - dy5 * dy5 - dz5 * dz5 - dw5 * dw5
- if (attn5 > 0) Then
- attn5 *= attn5
- value += attn5 * attn5 * extrapolate4(xsb + 1, ysb + 1, zsb + 0, wsb + 0, dx5, dy5, dz5, dw5)
- EndIf
- ''Contribution (1,0,1,0)
- Dim As Double dx6 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dy6 = dy0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dz6 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dw6 = dw0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double attn6 = 2 - dx6 * dx6 - dy6 * dy6 - dz6 * dz6 - dw6 * dw6
- if (attn6 > 0) Then
- attn6 *= attn6
- value += attn6 * attn6 * extrapolate4(xsb + 1, ysb + 0, zsb + 1, wsb + 0, dx6, dy6, dz6, dw6)
- EndIf
- ''Contribution (1,0,0,1)
- Dim As Double dx7 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dy7 = dy0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dz7 = dz0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dw7 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double attn7 = 2 - dx7 * dx7 - dy7 * dy7 - dz7 * dz7 - dw7 * dw7
- if (attn7 > 0) Then
- attn7 *= attn7
- value += attn7 * attn7 * extrapolate4(xsb + 1, ysb + 0, zsb + 0, wsb + 1, dx7, dy7, dz7, dw7)
- EndIf
- ''Contribution (0,1,1,0)
- Dim As Double dx8 = dx0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dy8 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dz8 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dw8 = dw0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double attn8 = 2 - dx8 * dx8 - dy8 * dy8 - dz8 * dz8 - dw8 * dw8
- if (attn8 > 0) Then
- attn8 *= attn8
- value += attn8 * attn8 * extrapolate4(xsb + 0, ysb + 1, zsb + 1, wsb + 0, dx8, dy8, dz8, dw8)
- EndIf
- ''Contribution (0,1,0,1)
- Dim As Double dx9 = dx0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dy9 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dz9 = dz0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dw9 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double attn9 = 2 - dx9 * dx9 - dy9 * dy9 - dz9 * dz9 - dw9 * dw9
- if (attn9 > 0) Then
- attn9 *= attn9
- value += attn9 * attn9 * extrapolate4(xsb + 0, ysb + 1, zsb + 0, wsb + 1, dx9, dy9, dz9, dw9)
- EndIf
- ''Contribution (0,0,1,1)
- Dim As Double dx10 = dx0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dy10 = dy0 - 0 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dz10 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double dw10 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D
- Dim As Double attn10 = 2 - dx10 * dx10 - dy10 * dy10 - dz10 * dz10 - dw10 * dw10
- if (attn10 > 0) Then
- attn10 *= attn10
- value += attn10 * attn10 * extrapolate4(xsb + 0, ysb + 0, zsb + 1, wsb + 1, dx10, dy10, dz10, dw10)
- EndIf
- EndIf
- ''First extra vertex
- Dim As Double attn_ext0 = 2 - dx_ext0 * dx_ext0 - dy_ext0 * dy_ext0 - dz_ext0 * dz_ext0 - dw_ext0 * dw_ext0
- if (attn_ext0 > 0) then
- attn_ext0 *= attn_ext0
- value += attn_ext0 * attn_ext0 * extrapolate4(xsv_ext0, ysv_ext0, zsv_ext0, wsv_ext0, dx_ext0, dy_ext0, dz_ext0, dw_ext0)
- EndIf
- ''Second extra vertex
- Dim As Double attn_ext1 = 2 - dx_ext1 * dx_ext1 - dy_ext1 * dy_ext1 - dz_ext1 * dz_ext1 - dw_ext1 * dw_ext1
- if (attn_ext1 > 0) Then
- attn_ext1 *= attn_ext1
- value += attn_ext1 * attn_ext1 * extrapolate4(xsv_ext1, ysv_ext1, zsv_ext1, wsv_ext1, dx_ext1, dy_ext1, dz_ext1, dw_ext1)
- EndIf
- ''Third extra vertex
- Dim As Double attn_ext2 = 2 - dx_ext2 * dx_ext2 - dy_ext2 * dy_ext2 - dz_ext2 * dz_ext2 - dw_ext2 * dw_ext2
- if (attn_ext2 > 0) Then
- attn_ext2 *= attn_ext2
- value += attn_ext2 * attn_ext2 * extrapolate4(xsv_ext2, ysv_ext2, zsv_ext2, wsv_ext2, dx_ext2, dy_ext2, dz_ext2, dw_ext2)
- EndIf
- value/=NORM_CONSTANT_4D
- return value
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement