Jump to content

  • Log In with Google      Sign In   
  • 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.


  • You cannot reply to this topic
No replies to this topic

#1   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:
 
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, 
 
ch01_eqn007.jpg
 
Circular direction:
 
011equ01.jpg
 
 
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, 19 August 2014 - 02:29 PM.





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.