I'm working on urp shader gerstner wave. Problem was that two side by side ocean plane waves were not continuesly. So, I tought if vertex positions would be world position, problem could fixed. it worked. However there was something I really don't understand.
this code worked
v.positionOS = mul(unity_ObjectToWorld, v.positionOS);
that one made weird things
float worldPos = mul(unity_ObjectToWorld, v.positionOS);
v.positionOS = worldPos;
all vertex shader here:
v2f vert(a2v v)
{
v2f o;
float3 tangent = float3(1, 0, 0);
float3 binormal = float3(0, 0, 1);
float3 p = v.positionOS;
/*float worldPos = mul(unity_ObjectToWorld, v.positionOS);
v.positionOS = worldPos;*/
v.positionOS = mul(unity_ObjectToWorld, v.positionOS);
p += GerstnerWave(_WaveA, v.positionOS.xyz, tangent, binormal);
o.heightOS = p.y;
VertexPositionInputs positionInputs = GetVertexPositionInputs(p);
o.positionCS = positionInputs.positionCS;
o.positionWS = positionInputs.positionWS;
return o;
}
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) * _Frequency;
float f = k * (dot(d, p.xz) - c * _Time.y * _Speed);
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))
);
}