I’m trying to make an ftf gerstner like shader in the BGE 2.78a using openGL, this is what I have so far but it’s not quite right.
GerstnerWaves.blend (852.0 KB)
Like always any help is appreciated.
I’m trying to make an ftf gerstner like shader in the BGE 2.78a using openGL, this is what I have so far but it’s not quite right.
GerstnerWaves.blend (852.0 KB)
Like always any help is appreciated.
A couple of things about the shader, you are hard coding the values and updating the shader every frame, that’s slow because every time you use setSource
the shader has to be compiled; use uniforms instead to pass values to the shader.
When deforming a vertex in a shader, traditionally you get the vertex from gl_Vertex, apply the deformation and then multiply by the ModelViewProjection matrix, i.e.:
vec4 vertex = gl_Vertex;
vertex.xyz += vec3(0.01);
gl_Position = gl_ModelViewProjectionMatrix * vertex;
Don’t modifiy the w component unless you really know what you are doing.
Lastly, when dealing with sin
or cos
, if you want a perfect loop, use 2.0*pi as max value (that’s a perfect circle), and reset back to 0.0.
I’m really not familiar with Gerstner waves, but I hope this suggestions help you somehow.
GerstnerWaves-1.blend (761.9 KB)