• Create Account

## Problem with circular wave

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

No replies to this topic

### #1Blackhart  Members

174
Like
0Likes
Like

Posted 19 August 2014 - 06:30 AM

Hello,

I try to implement circular water from the GPU Gems chapter 1. (http://http.developer.nvidia.com/GPUGems/gpugems_ch01.html)
Here is reals formula:

Wave height:

with,

• Wavelength (L): the crest-to-crest distance between waves in world space. Wavelength L relates to frequency w as w = 2p/L
• Amplitude (A): the height from the water plane to the wave crest.
• Speed (S): the distance the crest moves forward per second. It is convenient to express speed as phase-constant  , where  S x 2p/L.
• Direction (D ): the horizontal vector perpendicular to the wave front along which the crest travels.

Normal vector:

with,

Circular direction:

I implemented these formula in the tesselation evaluation shader.

Here is the source code:

#version 430 core

// In

// Uni
uniform float   uni_Time;
uniform float   uni_Frequency;
uniform float   uni_Amplitude;
uniform float   uni_Fi;
uniform vec2    uni_Direction;

uniform sampler2D   uni_Texture;

// Out
out vec3    normal;

void main(void)
{
// Compute new vertice pos
vec4    p1 = mix(gl_in[0].gl_Position, gl_in[1].gl_Position, gl_TessCoord.x);
vec4    p2 = mix(gl_in[2].gl_Position, gl_in[3].gl_Position, gl_TessCoord.x);
vec4    p = mix(p1, p2, gl_TessCoord.y);

// Compute direction
vec2    center = vec2(0.5f, 0.5f);
vec2    dir = normalize(gl_TessCoord.yx - center);

// Compute wave height
float   theta = dot(dir, gl_TessCoord.yx);
p.y -= uni_Amplitude * sin(theta * uni_Frequency + uni_Time * uni_Fi);

// Compute normal
float   A = uni_Amplitude * dir.x * uni_Frequency;
normal.x = - (A * cos(theta * uni_Frequency + uni_Time * uni_Fi));
A = uni_Amplitude * dir.y * uni_Frequency;
normal.y = - (A * cos(theta * uni_Frequency + uni_Time * uni_Fi));
normal.z = 1.0f;
normal = normalize(normal);

gl_Position = p;
}



and the video:

The problem is,

In the case where i choose directional wave, it works fine (direction and normal vector.)
But, in the case where i choose circular wave, i get a wrong wave and normal ...

I think that, with circular wave, my direction is wrong ... but i dont understand why ...