Jump to content
  • Advertisement
Sign in to follow this  

Problem with circular wave

This topic is 1458 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:
ch01_eqn001.jpg 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 phase-constant.jpg , where phase-constant.jpg S x 2p/L.
  • Direction (D ): the horizontal vector perpendicular to the wave front along which the crest travels.

Normal vector:
01equ06b.jpg with, 
Circular direction:
I implemented these formula in the tesselation evaluation shader.
Here is the source code:

#version 430 core

// In
layout (quads, equal_spacing, cw) 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 ...
Thanks for your help smile.png

Edited by Blackhart

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!