修改水
This commit is contained in:
@@ -1,76 +1,118 @@
|
||||
#if (OBI_BURST && OBI_MATHEMATICS && OBI_COLLECTIONS)
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace Obi
|
||||
public struct GridHash
|
||||
{
|
||||
public struct GridHash
|
||||
public readonly static int3[] cellOffsets3D =
|
||||
{
|
||||
public readonly static int3[] cellOffsets3D =
|
||||
{
|
||||
new int3(1,0,0),
|
||||
new int3(0,1,0),
|
||||
new int3(1,1,0),
|
||||
new int3(0,0,1),
|
||||
new int3(1,0,1),
|
||||
new int3(0,1,1),
|
||||
new int3(1,1,1),
|
||||
new int3(-1,1,0),
|
||||
new int3(-1,-1,1),
|
||||
new int3(0,-1,1),
|
||||
new int3(1,-1,1),
|
||||
new int3(-1,0,1),
|
||||
new int3(-1,1,1)
|
||||
};
|
||||
new int3(1,0,0),
|
||||
new int3(0,1,0),
|
||||
new int3(1,1,0),
|
||||
new int3(0,0,1),
|
||||
new int3(1,0,1),
|
||||
new int3(0,1,1),
|
||||
new int3(1,1,1),
|
||||
new int3(-1,1,0),
|
||||
new int3(-1,-1,1),
|
||||
new int3(0,-1,1),
|
||||
new int3(1,-1,1),
|
||||
new int3(-1,0,1),
|
||||
new int3(-1,1,1)
|
||||
};
|
||||
|
||||
public readonly static int3[] cellOffsets =
|
||||
{
|
||||
new int3(0, 0, 0),
|
||||
new int3(-1, 0, 0),
|
||||
new int3(0, -1, 0),
|
||||
new int3(0, 0, -1),
|
||||
new int3(1, 0, 0),
|
||||
new int3(0, 1, 0),
|
||||
new int3(0, 0, 1)
|
||||
};
|
||||
public readonly static int3[] cellOffsets =
|
||||
{
|
||||
new int3(0, 0, 0),
|
||||
new int3(-1, 0, 0),
|
||||
new int3(0, -1, 0),
|
||||
new int3(0, 0, -1),
|
||||
new int3(1, 0, 0),
|
||||
new int3(0, 1, 0),
|
||||
new int3(0, 0, 1)
|
||||
};
|
||||
|
||||
public readonly static int2[] cell2DOffsets =
|
||||
{
|
||||
new int2(0, 0),
|
||||
new int2(-1, 0),
|
||||
new int2(0, -1),
|
||||
new int2(1, 0),
|
||||
new int2(0, 1),
|
||||
};
|
||||
public readonly static int2[] cell2DOffsets =
|
||||
{
|
||||
new int2(0, 0),
|
||||
new int2(-1, 0),
|
||||
new int2(0, -1),
|
||||
new int2(1, 0),
|
||||
new int2(0, 1),
|
||||
};
|
||||
|
||||
public static int3 Quantize(float3 v, float cellSize)
|
||||
public static int Hash(float3 v, float cellSize)
|
||||
{
|
||||
return Hash(Quantize(v, cellSize));
|
||||
}
|
||||
|
||||
public static int3 Quantize(float3 v, float cellSize)
|
||||
{
|
||||
return new int3(math.floor(v / cellSize));
|
||||
}
|
||||
|
||||
public static int Hash(float2 v, float cellSize)
|
||||
{
|
||||
return Hash(Quantize(v, cellSize));
|
||||
}
|
||||
|
||||
public static int2 Quantize(float2 v, float cellSize)
|
||||
{
|
||||
return new int2(math.floor(v / cellSize));
|
||||
}
|
||||
|
||||
public static int Hash(int3 grid)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return new int3(math.floor(v / cellSize));
|
||||
// Simple int3 hash based on a pseudo mix of :
|
||||
// 1) https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
||||
// 2) https://en.wikipedia.org/wiki/Jenkins_hash_function
|
||||
int hash = grid.x;
|
||||
hash = (hash * 397) ^ grid.y;
|
||||
hash = (hash * 397) ^ grid.z;
|
||||
hash += hash << 3;
|
||||
hash ^= hash >> 11;
|
||||
hash += hash << 15;
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
public static int2 Quantize(float2 v, float cellSize)
|
||||
public static int Hash(int2 grid)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return new int2(math.floor(v / cellSize));
|
||||
// Simple int3 hash based on a pseudo mix of :
|
||||
// 1) https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
||||
// 2) https://en.wikipedia.org/wiki/Jenkins_hash_function
|
||||
int hash = grid.x;
|
||||
hash = (hash * 397) ^ grid.y;
|
||||
hash += hash << 3;
|
||||
hash ^= hash >> 11;
|
||||
hash += hash << 15;
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
public static int Hash(in int4 cellIndex, int maxCells)
|
||||
{
|
||||
const int p1 = 73856093;
|
||||
const int p2 = 19349663;
|
||||
const int p3 = 83492791;
|
||||
const int p4 = 10380569;
|
||||
return math.abs(p1 * cellIndex.x ^ p2 * cellIndex.y ^ p3 * cellIndex.z ^ p4 * cellIndex.w) % maxCells;
|
||||
}
|
||||
public static ulong Hash(ulong hash, ulong key)
|
||||
{
|
||||
const ulong m = 0xc6a4a7935bd1e995UL;
|
||||
const int r = 47;
|
||||
|
||||
public static int Hash(in int3 cellIndex, int maxCells)
|
||||
{
|
||||
const int p1 = 73856093;
|
||||
const int p2 = 19349663;
|
||||
const int p3 = 83492791;
|
||||
return ((p1 * cellIndex.x ^ p2 * cellIndex.y ^ p3 * cellIndex.z) & 0x7fffffff) % maxCells;
|
||||
ulong h = hash;
|
||||
ulong k = key;
|
||||
|
||||
/*var index = cellIndex - new int3(-32, -32, -32);
|
||||
return index.x + index.y * 64 + index.z * 64 * 64;*/
|
||||
}
|
||||
k *= m;
|
||||
k ^= k >> r;
|
||||
k *= m;
|
||||
|
||||
h ^= k;
|
||||
h *= m;
|
||||
|
||||
h ^= h >> r;
|
||||
h *= m;
|
||||
h ^= h >> r;
|
||||
|
||||
return h;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user