10 hours ago, Reitano said:
Hola Alex,
First, I would recommend getting familiar with a GPU debugger, my favourite one being RenderDoc. It allows you to debug the execution of shaders on individual vertices or pixels.
I had a quick look at your shader code. You are modifying all components of pos, including w and that might explain the error. In theory you should modify the xz components with the horizontal displacement formula, y the component with the vertical formula (assuming y points vertically in your world space), and leave w to 1. k should be a 2D normalized vector, not a vec4, and the wave phase should be given by dot(k, in_Position.xz) + offset.
I have worked on waves simulation for many years so please let me know if you have any questions related to it.
@Reitano Thanks for your answer!
The problem was what you said, I was multiplying the w component.
But I have two questions:
Why should the vector k be 2D? If I want to make a wave that moves along z axis I can't then.
What is the offset of the wave?
Thank you!
9 hours ago, _Silence_ said:
I had a quick look at your code, but the first thing you have to know is that the vertex shader works per vertex whereas doing it on the CPU you have vision over all vertices.
olas seems to become the L uniform in your shader. Do you update L for every vertex as it seems it should from your CPU version ? olas is an array, so L might remain an array (thus removing the need to update the uniform for every vertex). Then to know which vertex is currently processed, you can use gl_VertexID and access it threw L[gl_VertexID] for example.
Also note that uniforms have limitations in their size (this is important if your grid is big and you use array of uniforms as I suggested).
If you don't want to use array of uniforms and if olas is constant, then use olas as a vertex attribute.
@_Silence_ First of all thanks for your answer!
olas is not the L uniform. L, k, w, speed, A are the attributes of the waves, so what I do is: when I call the draw function, I make a foor loop where in every iteration i pass to the shader olas.w, olas.k, etc. as uniforms.
I'll read about passing arrays to the shader because right now only the last wave is being rendered, the previous no, so I think I can pass several arrays (one array of w components, another one of L components, etc) and iterate inside the vertex shader applying the formulas with the right variables.
Thank you very much!