Graphics Reference
In-Depth Information
float2 K = D * k; // wave vector and magnitude (direction)
// peak/crest steepness, higher means steeper, but too much
// can cause the wave to become inside out at the top
// A value of zero results in a sine wave.
float Q = steepness;
// Calculate wave speed (frequency) from input
float S = speed * 0.5; // Speed 1 =~ 2m/s so halve first
float w = S * k; // Phase/frequency
float wT = w * Time;
// Calculate values for reuse
float KPwT = dot(K, position.xz)-wT;
float S0 = sin(KPwT);
float C0 = cos(KPwT);
7.
Next, we will calculate the vertex offset from the provided direction and current
vertex position.
// Calculate the vertex offset along the X and Z axes
float2 xz = position.xz - D*Q*A*S0;
// Calculate the vertex offset along the Y (up/down) axis
float y = A*C0;
8.
Then, we need to calculate the new normal and tangent vectors, as follows:
// Calculate the tangent/bitangent/normal
// Bitangent
float3 B = float3(
1-(Q * D.x * D.x * kA * C0),
D.x * kA * S0,
-(Q*D.x * D.y * kA * C0));
// Tangent
float3 T = float3(
-(Q * D.x * D.y * kA * C0),
D.y * kA * S0,
1-(Q*D.y * D.y * kA * C0));
B = normalize(B);
T = normalize(T);
float3 N = cross(T, B);
9.
And lastly, set the output values. Note that we are accumulating the results in
order to call the method multiple times with varying parameters.
// Append the results
result.xz += xz;
 
Search WWH ::




Custom Search