Graphics Reference
In-Depth Information
result.y += y;
normal += N;
tangent += T;
With the Gerstner wave function in place, we can now displace the vertices within
our vertex or domain shader.
10. The following is an example of the code that is necessary to generate gentle
ocean waves. This should be inserted before any WorldViewProjection or
ViewProjection transforms.
...SNIP
// Existing vertex shader code
float3 N = (float3)0; // normal
float3 T = (float3)0; // tangent
float3 waveOffset = (float3)0; // vertex xyz offset
float2 direction = float2(1, 0);
// Gentle ocean waves
GerstnerWaveTessendorf(8, 0.5, 0.3, 1, direction, vertex.Position,
waveOffset, N, T);
GerstnerWaveTessendorf(4, 0.5, 0.4, 1, direction + float2(0, 0.5),
vertex.Position, waveOffset, N, T);
GerstnerWaveTessendorf(3, 0.5, 0.3, 1, direction + float2(0, 1),
vertex.Position, waveOffset, N, T);
GerstnerWaveTessendorf(2.5, 0.5, 0.2, 1, direction,
vertex.Position, waveOffset, N, T);
vertex.Position.xyz += waveOffset;
vertex.Normal = normalize(N);
vertex.Tangent.xyz = normalize(T); // If using normal mapping
// Existing vertex shader code
result.Position = mul(vertex.Position, WorldViewProjection);
...SNIP
11. For larger and more choppy waves, you can try the following code instead:
// Choppy ocean waves
GerstnerWaveTessendorf(10, 2, 2.5, 0.5, direction,
vertex.Position, waveOffset, N, T);
GerstnerWaveTessendorf(5, 1.2, 2, 1, direction,
vertex.Position, waveOffset, N, T);
GerstnerWaveTessendorf(4, 2, 2, 1, direction + float2(0,
1), vertex.Position, waveOffset, N, T);
 
Search WWH ::




Custom Search