jdf / peasycam

Dead-simple mouse-driven camera for Processing
http://MrFeinberg.com/peasycam/
Apache License 2.0
116 stars 35 forks source link

Shaders displaced by the camera #17

Closed hamoid closed 10 years ago

hamoid commented 10 years ago

This is not necessarily a bug, but maybe just not mentioned in the documentation?

I'm trying to draw objects, apply a shader filter, then draw more objects. The effect of the shader spins around in a flat plane when moving the camera. How can I avoid having the filter effect move? I tried with state and with HUD...

Here an example (it needs blur.glsl from Examples > Topics > Shaders > BlurFilter)

import peasy.*;
PeasyCam cam;
PShader blur;

void setup() {
  size(1000, 800, P3D);  
  cam = new PeasyCam(this, 500);
  blur = loadShader("blur.glsl");
  noFill();
  stroke(255);
}

void draw() {
  background(40);
  for (int i=0; i<100; i++) {
    pushMatrix();
    rotateX(i*0.11);
    rotateY(i*0.21);
    translate(500, 0, 0);
    box(20);
    popMatrix();
  }

  cam.beginHUD();
  rect(10,10,width-20,height-20);
  filter(blur);
  cam.endHUD();

  box(200);
}
hamoid commented 10 years ago

Here you can see that the HUD keeps the border rectangle in place, but the blurred area is displaced down and to the left. screenshot from 2014-05-11 11 52 15

jdf commented 10 years ago

That sure looks to me like you're trying to apply a 2D effect to a 3D scene.

hamoid commented 10 years ago

Ok :) Does that mean I have to rewrite the shader so it works on 3D?

jdf commented 10 years ago

I'm closing because I don't believe this is related to PeasyCam.