ibequa

08-31-2016, 10:56 AM

I want to achieve a ripple effect on a procedurally generated mesh: distort it's z coordinate so that the mesh kind of floats like a wave in a random manner.

To do that I'm generating a heightmap using a Perlin noise, feeding it into a vertex shader and smoothly (via time uniform parameter) interpolating to the sampled height. But when the interpolation is complete, I need to change a heightmap (to achieve randomness of a ripple), doing that flickers the mesh, that is, a transition is not smooth. How do I smooth it out? The mesh in VBO is just a plain triangulated surface with the constant z-coordinate.

My current vertex shader in glsl es:

attribute vec3 aVertexPosition; // vertex pos

attribute vec2 aUV; // uv coords of a vertex

uniform mat4 u_view;

uniform mat4 u_projection;

uniform mat4 u_model;

varying highp vec2 vUV;

uniform float u_time; // animation parameter

uniform sampler2D u_samplerHeight; // heightmap sampler

void main() {

float sample = texture2D(u_samplerHeight, aUV).r; // heightmap sample

float height = mix(aVertexPosition.z, sample, u_time); // interpolate

height *= 10.0; // scale it, so that changes are noticable

vec3 pos = vec3(aVertexPosition.xy, height);

gl_Position = u_projection * u_view * u_model * vec4(pos, 1.0);

vUV = aUV;

}

To do that I'm generating a heightmap using a Perlin noise, feeding it into a vertex shader and smoothly (via time uniform parameter) interpolating to the sampled height. But when the interpolation is complete, I need to change a heightmap (to achieve randomness of a ripple), doing that flickers the mesh, that is, a transition is not smooth. How do I smooth it out? The mesh in VBO is just a plain triangulated surface with the constant z-coordinate.

My current vertex shader in glsl es:

attribute vec3 aVertexPosition; // vertex pos

attribute vec2 aUV; // uv coords of a vertex

uniform mat4 u_view;

uniform mat4 u_projection;

uniform mat4 u_model;

varying highp vec2 vUV;

uniform float u_time; // animation parameter

uniform sampler2D u_samplerHeight; // heightmap sampler

void main() {

float sample = texture2D(u_samplerHeight, aUV).r; // heightmap sample

float height = mix(aVertexPosition.z, sample, u_time); // interpolate

height *= 10.0; // scale it, so that changes are noticable

vec3 pos = vec3(aVertexPosition.xy, height);

gl_Position = u_projection * u_view * u_model * vec4(pos, 1.0);

vUV = aUV;

}