球体上的顶点位移会破坏网格

时间:2015-09-01 10:39:03

标签: math 3d three.js shader vertex-shader

我正在尝试使用着色器对球体进行简单的噪声效果。 我尝试使用ashima's perlin noise,但效果不是我所期望的,所以我根据Phong创建了自己的着色器。

custom phong shader with broken dispalcement

以下是我在顶点着色器中使用此代码的内容:

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);

其中index是顶点的索引,time是当前经过的时间。

噪音效果正是我的预期,但球形网格是开放的......

如何保持此效果并保持球体网格关闭?

1 个答案:

答案 0 :(得分:0)

您的球体很可能包含重复的顶点。摆脱它们,你的着色器将运行良好。或者摆脱对“index”的着色器依赖。