Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GLSL webgl lerp normals from uv offset

I have a displacement map on a plane 512px* 512px (100x100 segments) , as the image for the displacement map scrolls left the vertices snap to position of height not blend smoothly, I have been looking at the mix() function and smooth-step() to morph the normals to their positions over time but i having a hard time implementing it.

    uniform sampler2D heightText;  //texture greyscale 512x512
    uniform float displace;        
    uniform float time;
    uniform float speed;

    varying vec2 vUV;
    varying float scaleDisplace;

    void main() { 
        vUV = uv;
        vec2 uvOffset = vUV + vec2( 0.1, 0.1)* time;    // animates offset
        vec2 uvCo = vUV + vec2( 0.0, 0.0);
        vec2 texSize = vec2(-0.8, 0.8);        // scales image larger

        vec4 data = texture2D( heightText, uvOffset + fract(uvCo)*texSize.x);
        scaleDisplace = data.r; 

        //vec3 possy = normal  * displace  * scaleDisplace;

        vec3 morphPossy = mix( position, normal *displace , scaleDisplace)* time ;

        gl_Position = projectionMatrix * modelViewMatrix * vec4(morphPossy, 1.0 );


   }

Using Three.js 71 with vertex and pixel:

Illustration purpose:

uv offset Any help appreciated ...

like image 879
Careen Avatar asked Apr 20 '15 13:04

Careen


1 Answers

Since you're using a texture as a height map, you should make sure that:

heightText.magFilter = THREE.LinearFilter; // This is the default value.

so that the values you receive are smoothed texel to texel.

like image 50
Frederic Gaudet Avatar answered Nov 10 '22 16:11

Frederic Gaudet