Aetheria/Assets/Scripts/ServerShared/Noise1D.cs
Reinier Vens b53e4aec8c Combat & Visibility & Collisions
Converted entity materials to new fade shader
Implemented visibility system
Refactored per-instance entity code to run inside monobehavior on entity instances
Created state machine AI for enemy ships with basic patrol and combat routines
Removed legacy AI code (controller item behaviors)
Added automatic trigger group assignment for matched weapons
Created ship collision system
Created shield VFX and colliders
2021-02-26 19:01:47 +00:00

28 lines
648 B
C#

using Unity.Mathematics;
using static Unity.Mathematics.math;
public static class Noise1D
{
private const float HASHSCALE = 0.1031f;
static float hash(float p)
{
float3 p3 = frac(float3(p) * HASHSCALE);
p3 += dot(p3, p3.yzx + 19.19f);
return frac((p3.x + p3.y) * p3.z);
}
static float fade(float t) { return t * t * t * (t * (6f* t - 15f) + 10f); }
static float grad(float hash, float p)
{
int i = (int)(1e4 * hash);
return (i & 1) == 0 ? p : -p;
}
public static float noise(float p)
{
float pi = floor(p), pf = p - pi, w = fade(pf);
return lerp(grad(hash(pi), pf), grad(hash(pi + 1.0f), pf - 1.0f), w) * 2.0f;
}
}