103 lines
2.0 KiB
C#
103 lines
2.0 KiB
C#
using UnityEngine;
|
|
|
|
[AddComponentMenu("Modifiers/Vertical Noise")]
|
|
public class MegaVertNoise : MegaModifier
|
|
{
|
|
public float Scale = 1f;
|
|
|
|
public bool Fractal;
|
|
|
|
public float Freq = 0.25f;
|
|
|
|
public float Iterations = 6f;
|
|
|
|
public bool Animate;
|
|
|
|
public float Phase;
|
|
|
|
public float Rough;
|
|
|
|
public float Strength;
|
|
|
|
private MegaPerlin iperlin = MegaPerlin.Instance;
|
|
|
|
private float time;
|
|
|
|
private float scale;
|
|
|
|
private float rt;
|
|
|
|
public float decay;
|
|
|
|
public override string ModName()
|
|
{
|
|
return "Vertical Noise";
|
|
}
|
|
|
|
public override string GetHelpURL()
|
|
{
|
|
return "?page_id=1063";
|
|
}
|
|
|
|
public override void Modify(MegaModifiers mc)
|
|
{
|
|
for (int i = 0; i < verts.Length; i++)
|
|
{
|
|
Vector3 point = tm.MultiplyPoint3x4(verts[i]);
|
|
float y = point.y;
|
|
float x = point.x * scale + 0.5f;
|
|
float y2 = point.z * scale + 0.5f;
|
|
float f = Mathf.Sqrt(point.x * point.x + point.z * point.z);
|
|
float num = Mathf.Exp((0f - decay) * Mathf.Abs(f));
|
|
float num2 = 0f;
|
|
num2 = ((!Fractal) ? iperlin.Noise(x, y2, time) : iperlin.fBm1(x, y2, time, rt, 2f, Iterations));
|
|
point.y += num2 * Strength;
|
|
point.y = y + (point.y - y) * num;
|
|
sverts[i] = invtm.MultiplyPoint3x4(point);
|
|
}
|
|
}
|
|
|
|
public override void ModStart(MegaModifiers mc)
|
|
{
|
|
}
|
|
|
|
public override Vector3 Map(int i, Vector3 p)
|
|
{
|
|
p = tm.MultiplyPoint3x4(p);
|
|
float y = p.y;
|
|
float f = Mathf.Sqrt(p.x * p.x + p.z * p.z);
|
|
float num = Mathf.Exp((0f - decay) * Mathf.Abs(f));
|
|
float x = p.x * scale + 0.5f;
|
|
float y2 = p.z * scale + 0.5f;
|
|
float num2 = 0f;
|
|
num2 = ((!Fractal) ? iperlin.Noise(x, y2, time) : iperlin.fBm1(x, y2, time, rt, 2f, Iterations));
|
|
p.y += num2 * Strength;
|
|
p.y = y + (p.y - y) * num;
|
|
return invtm.MultiplyPoint3x4(p);
|
|
}
|
|
|
|
public override bool ModLateUpdate(MegaModContext mc)
|
|
{
|
|
if (Animate)
|
|
{
|
|
Phase += Time.deltaTime * Freq;
|
|
}
|
|
time = Phase;
|
|
return Prepare(mc);
|
|
}
|
|
|
|
public override bool Prepare(MegaModContext mc)
|
|
{
|
|
if (Scale == 0f)
|
|
{
|
|
scale = 1E-06f;
|
|
}
|
|
else
|
|
{
|
|
scale = 1f / Scale;
|
|
}
|
|
rt = 1f - Rough;
|
|
return true;
|
|
}
|
|
}
|