Я пытаюсь изменить PShape с помощью шума perlin через вершинный шейдер.До сих пор мне удавалось сделать это, добавив немного шума к gl_Position
, но это влияет на все элементы моей сцены, а не только на форму.
Я уже пытался поместить вызов шейдера внутрьpush / popMatrix block или для вызова resetMatrix, но пока безуспешно.
void init() {
// Initialize Shader
shader = loadShader("shaders/noisy-frag.glsl", "shaders/noisy-vert.glsl");
shader.set("u_noise_amnt", 1.0);
// Initialize Shape
sphere = createShape(SPHERE, size);
sphere.setTexture(loadImage("textures/marble.jpg"));
}
void display() {
shader(shader);
pushMatrix();
translate(position.x, position.y, position.z);
rotateX(rotation.x);
rotateY(rotation.y);
rotateZ(rotation.z);
shape(sphere);
popMatrix();
}
Вершинный шейдер
uniform mat4 transform;
uniform mat3 normalMatrix;
uniform mat4 texMatrix;
uniform vec4 lightPosition;
uniform float u_time;
uniform float u_noise_amnt;
attribute vec4 position;
attribute vec4 color;
attribute vec3 normal;
attribute vec2 texCoord;
varying vec4 vertColor;
varying vec3 ecNormal;
varying vec3 lightDir;
varying vec4 vertTexCoord;
float cnoise(vec4 position) {
# perlin noise code
}
void main() {
float displacement = 25.0 * (cnoise( normal.xyz + u_time ) - 0.5);
gl_Position = transform * position + 1.0 * displacement;
vec3 ecPosition = vec3(modelview * position);
ecNormal = normalize(normalMatrix * normal);
lightDir = normalize(lightPosition.xyz - ecPosition);
vertColor = color;
vertTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0);
}