Glsl 如何正确使用顶点着色器变形PShape

Glsl 如何正确使用顶点着色器变形PShape,glsl,processing,vertex-shader,Glsl,Processing,Vertex Shader,我正试图通过顶点着色器变形带有柏林噪声的PShape。 到目前为止,我通过向gl_位置添加一些噪波来做到这一点,但这会影响场景中的所有元素,而不仅仅是形状 我已经尝试将着色器调用放在push/popMatrix块内,或者调用resetMatrix,但到目前为止没有成功 void init() { // Initialize Shader shader = loadShader("shaders/noisy-frag.glsl", "shaders/noisy-vert.glsl"

我正试图通过顶点着色器变形带有柏林噪声的PShape。 到目前为止,我通过向
gl_位置添加一些噪波来做到这一点,但这会影响场景中的所有元素,而不仅仅是形状

我已经尝试将着色器调用放在push/popMatrix块内,或者调用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);
}
调用以还原默认着色器

如果要将客户着色器应用于单个对象,请在绘制形状之前应用着色器,并在绘制对象之后恢复默认着色器:

void display(){
// [...]
着色器(着色器);
形状(球体);
resetShader();
// [...]
}
调用以恢复默认着色器

如果要将客户着色器应用于单个对象,请在绘制形状之前应用着色器,并在绘制对象之后恢复默认着色器:

void display(){
// [...]
着色器(着色器);
形状(球体);
resetShader();
// [...]
}