If the distortion is done in a shader it can be done by passing the world coordinates of the vertices like this:
uniform float strength;
vec4 pos = gl_Vertex;
vec4 noisePos = pos;
pos.x = pos.x + random( vec4( pos.xyz, 0 ) ) * strength;
pos.y = pos.y + random( vec4( pos.xyz, 1 ) ) * strength;
pos.z = pos.z + random( vec4( pos.xyz, 2 ) ) * strength;
gl_Position = gl_ModelViewProjectionMatrix * noisePos;
random is not a openGL built in, see https://stackoverflow.com/a/17479300/31151 for implementations
This will have the effect of having each vertex be offset in a pseudo-random fashion, this will also work for corners where the vertices aren't shared (different textures), because the seed is the world position.
If you are rendering multiple textures in a single mesh what I would do is pass in a per vertex
int type (from which you can calculate/look up the UV coordinates in the fragment shader) and make the
strength parameter an array.
Some possible improvements that might make the effect look better would be:
- Making the
strength uniform a vec3 rather than a straight float to tweak the strength per direction (or vec2 if you only care about changing the height differently).
- Calculating the offset in a temporary vector and normalizing it, then scaling it.