math3dthree.jsshadervertex-shader

Vertex displacement on sphere break the mesh


I'm trying to make a simple noise effect on a sphere with shaders. I tried to use ashima's perlin noise but the effect wasn't what I expected so I create my own shader based on Phong.

custom phong shader with broken dispalcement

Here is what I get with this code in my vertex shader:

attribute int index;
uniform float time;

vec3 newPosition = position + normal * vec3(sin((time * 0.001) * float(index)) * 0.05);

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

where index is the index of the vertex and time the current elapsed time.

The noise effect is exactly what I expected but the sphere mesh is open...

How can I keep this effect and keep the sphere mesh closed?


Solution

  • Most likely your sphere contains duplicated vertices. Get rid of them and your shader will works well. Or get rid of your shader dependency on "index".