public void Init( int _TableSize, int _GradientSeed, int _PermutationSeed )
{
m_NoiseSize = (uint) _TableSize;
Random GradientRNG = new Random( _GradientSeed );
Random PermutationRNG = new Random( _PermutationSeed );
// Build the noise & permutation tables
m_NoiseTable = new float4[2*m_NoiseSize];
m_PermutationTable = new uint[2*m_NoiseSize];
for ( uint SlotIndex=0; SlotIndex < m_NoiseSize; SlotIndex++ )
{
m_NoiseTable[SlotIndex] = m_NoiseTable[m_NoiseSize+SlotIndex] = new float4( 2.0f * (float) GradientRNG.NextDouble() - 1.0f,
2.0f * (float) GradientRNG.NextDouble() - 1.0f,
2.0f * (float) GradientRNG.NextDouble() - 1.0f,
2.0f * (float) GradientRNG.NextDouble() - 1.0f );
m_PermutationTable[SlotIndex] = SlotIndex;
}
// Mix the permutation table by exchanging indices at random
for ( uint SlotIndex=0; SlotIndex < m_NoiseSize; SlotIndex++ )
{
uint RandomIndex = (uint) PermutationRNG.Next( (int) m_NoiseSize );
uint Temp = m_PermutationTable[RandomIndex];
m_PermutationTable[RandomIndex] = m_PermutationTable[SlotIndex];
m_PermutationTable[SlotIndex] = Temp;
}
// Finalize the permutation table by doubling its size
for ( uint SlotIndex=0; SlotIndex < m_NoiseSize; SlotIndex++ )
m_PermutationTable[m_NoiseSize + SlotIndex] = m_PermutationTable[SlotIndex];
}