attrib*() function does not work well with PShape #4048

Closed
codeanticode opened this Issue Oct 23, 2015 · 0 comments

Comments

Projects
None yet
1 participant
@codeanticode
Member

codeanticode commented Oct 23, 2015

The PShape version of the new MeshTween example:

PShader sh;
PShape grid;

void setup() {
  size(640, 360, P3D);
  sh = loadShader("frag.glsl", "vert.glsl");
  shader(sh);

  grid = createShape();
  grid.beginShape(QUADS);
  grid.noStroke();  
  grid.fill(150);  
  float d = 10;
  for (int x = -500; x < 500; x += d) {
    for (int y = -500; y < 500; y += d) {
      grid.fill(255 * noise(x, y));
      grid.attribPosition("tweened", x, y, 100 * noise(x, y));
      grid.vertex(x, y, 0);

      grid.fill(255 * noise(x + d, y));
      grid.attribPosition("tweened", x + d, y, 100 * noise(x + d, y));
      grid.vertex(x + d, y, 0);

      grid.fill(255 * noise(x + d, y + d));
      grid.attribPosition("tweened", x + d, y + d, 100 * noise(x + d, y + d)); 
      grid.vertex(x + d, y + d, 0);

      grid.fill(255 * noise(x, y + d));
      grid.attribPosition("tweened", x, y + d, 100 * noise(x, y + d));
      grid.vertex(x, y + d, 0);    
    }
  }
  grid.endShape();  
}

void draw() {
  background(255);

  sh.set("tween", map(mouseX, 0, width, 0, 1));

  translate(width/2, height/2, 0);
  rotateX(frameCount * 0.01);
  rotateY(frameCount * 0.01);

  shape(grid);
}

gives a wrong output when the tween factor is greater than 0:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment