hey, if you have some time pls help. how do I adjust the equation for GetWaveHeight? The equation I’m trying to use is from a shader, so everythings broken for some reason. idk why, i just started c# a few days ago.
public class WaveManager1 : MonoBehaviour
{
public static WaveManager1 instance;
public float amplitude = 1f;
public float length = 2f;
public float speed = 1f;
public float offset = 0f;
private void Awake()
{
if (instance == null)
{
instance = this;
}
else if (instance != this)
{
Debug.Log("Instance already exists, destroying object!");
Destroy(this);
}
}
private void Update()
{
offset += Time.deltaTime * speed;
}
public float GetWaveHeight(float _x)
{
return amplitude * Mathf.Sin(_x / length + offset);
}
}
Shader "Custom/Waves"
{
Properties
{
_WaveA ("Wave A (dir, steepness, wavelength)", Vector) = (1,0,0.5,10)
_WaveB ("Wave B", Vector) = (0,1,0.25,20)
_WaveC ("Wave C", Vector) = (1,1,0.15,10)
}
SubShader
{
float4 _WaveA, _WaveB, _WaveC;
float3 GerstnerWave (
float4 wave, float3 p, inout float3 tangent, inout float3 binormal)
{
float steepness = wave.z;
float wavelength = wave.w;
float k = 2 * UNITY_PI / wavelength;
float c = sqrt(9.8 / k);
float2 d = normalize(wave.xy);
float f = k * (dot(d, p.xz) - c * _Time.y);
float a = steepness / k;
tangent += float3(
-d.x * d.x * (steepness * sin(f)),
d.x * (steepness * cos(f)),
-d.x * d.y * (steepness * sin(f))
);
binormal += float3(
-d.x * d.y * (steepness * sin(f)),
d.y * (steepness * cos(f)),
-d.y * d.y * (steepness * sin(f))
);
return float3(
d.x * (a * cos(f)),
a * sin(f),
d.y * (a * cos(f))
);
}
thanks