Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/MegaNoiseWarp.cs
2026-02-21 16:45:37 +08:00

109 lines
2.0 KiB
C#

using UnityEngine;
[AddComponentMenu("Modifiers/Warps/Noise")]
public class MegaNoiseWarp : MegaWarp
{
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 Vector3 Strength = new Vector3(0f, 0f, 0f);
private MegaPerlin iperlin = MegaPerlin.Instance;
private float time;
private float scale;
private float rt;
private Vector3 d = default(Vector3);
private Vector3 sp = Vector3.zero;
public override string WarpName()
{
return "Noise";
}
public override string GetIcon()
{
return "MegaNoise icon.png";
}
public override string GetHelpURL()
{
return "?page_id=2576";
}
public override Vector3 Map(int i, Vector3 p)
{
p = tm.MultiplyPoint3x4(p);
Vector3 vector = p;
float magnitude = p.magnitude;
float num = Mathf.Exp((0f - totaldecay) * Mathf.Abs(magnitude));
sp.x = p.x * scale + 0.5f;
sp.y = p.y * scale + 0.5f;
sp.z = p.z * scale + 0.5f;
if (Fractal)
{
d.x = iperlin.fBm1(sp.y, sp.z, time, rt, 2f, Iterations);
d.y = iperlin.fBm1(sp.x, sp.z, time, rt, 2f, Iterations);
d.z = iperlin.fBm1(sp.x, sp.y, time, rt, 2f, Iterations);
}
else
{
d.x = iperlin.Noise(sp.y, sp.z, time);
d.y = iperlin.Noise(sp.x, sp.z, time);
d.z = iperlin.Noise(sp.x, sp.y, time);
}
p.x += d.x * Strength.x;
p.y += d.y * Strength.y;
p.z += d.z * Strength.z;
p.x = vector.x + (p.x - vector.x) * num;
p.y = vector.y + (p.y - vector.y) * num;
p.z = vector.z + (p.z - vector.z) * num;
return invtm.MultiplyPoint3x4(p);
}
private void Update()
{
if (Animate)
{
Phase += Time.deltaTime * Freq;
}
time = Phase;
}
public override bool Prepare(float decay)
{
tm = base.transform.worldToLocalMatrix;
invtm = tm.inverse;
if (Scale == 0f)
{
scale = 1E-06f;
}
else
{
scale = 1f / Scale;
}
rt = 1f - Rough;
totaldecay = Decay + decay;
if (totaldecay < 0f)
{
totaldecay = 0f;
}
return true;
}
}