10

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 ...

Careen
  • 567
  • 1
  • 6
  • 26
  • Im still looking into this with not much luck, at the moment i am looking at using other complete methods but ideally want to stay with this approach. – Careen Apr 24 '15 at 07:46
  • 1
    Please reword/elaborate on your question, I have no idea what you mean by "the displacement map scrolls left the vertices snap to position of height". – Brendan Annable Apr 25 '15 at 09:34
  • @Brendan updated with picture for a visual perspective.. – Careen Apr 25 '15 at 12:47
  • Can you set up a jsfiddle to play with? You can include the displacement map as outlined [here](http://blog.2pha.com/using-threejs-jsfiddle) – 2pha Apr 28 '15 at 17:02
  • i will need a day.... or so – Careen Apr 28 '15 at 17:05
  • 1
    Not very clear question. But: Is your texture sampled nearest maybe? Also normals need to be re-normalized after blending - but it sounds you worry about offsets - I don't see any normals in your shader? – starmole May 03 '15 at 02:00

1 Answers1

1

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.

Engineer
  • 8,529
  • 7
  • 65
  • 105
Frederic Gaudet
  • 161
  • 1
  • 5