public float Evaluate(float x, float y) { var xy = new Vector2(x, y); var ix = Mathf.FloorToInt(x); var iy = Mathf.FloorToInt(y); var minDis = float.MaxValue; for (var i = ix - 1; i <= ix + 1; i++) { for (var j = iy - 1; j <= iy + 1; j++) { var fi = MathUtility.ModPositive(i, _loopSize.x); var fj = MathUtility.ModPositive(j, _loopSize.y); var hash = RandomHash.Get(fi, fj); _lcgRandom.Seed = (uint)(hash * (uint.MaxValue >> 9)); var checkPointCount = _lcgRandom.NextRange(1, _maxPointsInCell + 1); for (var idx = 0; idx < checkPointCount; idx++) { var rx = i + _lcgRandom.NextFloat(); var ry = j + _lcgRandom.NextFloat(); var dis = _distanceCalculator(xy, new Vector2(rx, ry)); minDis = Mathf.Min(dis, minDis); } } } return(_distanceNormalize(minDis)); }
public float Evaluate(float x, float y) { var ix = Mathf.FloorToInt(x); var iy = Mathf.FloorToInt(y); return(RandomHash.Get(ix, iy) / 128f - 1); }
public float Evaluate(float x) { var ix = Mathf.FloorToInt(x); var fx = x - ix; var p1 = fx; var p2 = fx - 1; var hash1 = RandomHash.Get(ix); var hash2 = RandomHash.Get(ix + 1); _random.Seed = (uint)(hash1 * magicNumber); var g1 = _random.NextFloat() * 4 - 2; _random.Seed = (uint)(hash2 * magicNumber); var g2 = _random.NextFloat() * 4 - 2; var v1 = g1 * p1; var v2 = g2 * p2; return(MathUtility.SmoothLerp2(v1, v2, fx)); }
public float Evaluate(float x, float y) { var ix = Mathf.FloorToInt(x); var iy = Mathf.FloorToInt(y); var fx = x - ix; var fy = y - iy; var ix1 = ix + 1; var iy1 = iy + 1; ix = MathUtility.ModPositive(ix, _loopSize.x); iy = MathUtility.ModPositive(iy, _loopSize.y); ix1 = MathUtility.ModPositive(ix1, _loopSize.x); iy1 = MathUtility.ModPositive(iy1, _loopSize.y); var p1 = new Vector2(fx, fy); var p2 = p1 - new Vector2(1, 0); var p3 = p1 - new Vector2(0, 1); var p4 = p1 - new Vector2(1, 1); var hash1 = RandomHash.Get(ix, iy); var hash2 = RandomHash.Get(ix1, iy); var hash3 = RandomHash.Get(ix, iy1); var hash4 = RandomHash.Get(ix1, iy1); var g1 = RandomGrad.GetVector(hash1); var g2 = RandomGrad.GetVector(hash2); var g3 = RandomGrad.GetVector(hash3); var g4 = RandomGrad.GetVector(hash4); var v1 = Vector2.Dot(g1, p1); var v2 = Vector2.Dot(g2, p2); var v3 = Vector2.Dot(g3, p3); var v4 = Vector2.Dot(g4, p4); var a = MathUtility.SmoothLerp2(v1, v2, fx); var b = MathUtility.SmoothLerp2(v3, v4, fx); return(MathUtility.SmoothLerp2(a, b, fy)); }
private static float RandomValue(int x) { var hash = RandomHash.Get(x); return((hash - 128) / 128f); }