We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hi! im trying to do a multipass shader effect. the problem is that peasyCam dont apply the transformations in the buffer.
PShader sh;
PShader sha;
PGraphics buffer;
PGraphics buffer2;
import com.hamoid.*;
import themidibus.*;
import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.*;
PeasyCam cam;
float count;
void settings () {
fullScreen(P3D);
}
void setup(){
background(0);
cam = new PeasyCam(this, 500);
sh = loadShader("basicShaderFrag.glsl", "basicShader.glsl");
sha = loadShader("frag2.glsl", "basicShader.glsl");
buffer = createGraphics(width, height, P3D);
buffer2 = createGraphics(width, height, P3D);
}
void draw(){
background(0);
// println(frameRate);
count +=0.005;
sh.set("u_time", count);
buffer.beginDraw();
render(buffer);
buffer.endDraw();
buffer2.beginDraw();
buffer2.background(0);
buffer2.shader(sh);
buffer2.image(buffer,0, 0);
buffer2.endDraw();
cam.getState().apply(buffer2); // here the question. the image show the shader but like it was a 2D screen.
cam.beginHUD();
image(buffer2, 0,0);
cam.endHUD();
}
void render(PGraphics a){
a.background(0, 50);
a.noStroke();
s.run();
a.sphere(200);
}
if i skip the buffer2
and apply the shader into buffer
it works fine.
i was follow this post https://github.com/jdf/peasycam/issues/25 but it doest work for me.
what im doing wrong?
Answers
cam.getState().apply(canvas);
im sorry @Chrisir but canvas is not a field in my code. if i try with
it works fine (shader apply in buffer and camera transformations also) but if i try:
buffer2 shows like a 2D screen in 3D space and camera transformations apply but not in that buffer.
I took it from the github discussion
I don’t know
edit 1: new results but not resolve yet:
and in both shaders: #define PROCESSING_TEXTURE_SHADER. the transformations do in the buffer2 but don't draw geometry (it apply the shader to the full screen). if i define #define PROCESSING_COLOR_SHADER the geometry is draw but is only white.
You have to create a simple example, with just the things that are needed to reproduce the problem. You have a
s.run();
in your code, which is not even declared. Otherwise it is really hard to help you and takes too much time.And please share the whole sketch, also the shaders.
Because I am a very kind person, I fixed the missing parts and created this very small example.
The problem you had was, that you tried to draw a texture with a shader onto a
P3D
graphics object, which is possible, but with weird results. For a multipass texture shader you should use aP2D
texture.To apply the pease cam matrix to the rendered scene, you have to use the already mentioned command
cam.getState().apply(buffer);
.Oh and just for the next time: I recommend to not use a sphere as object to which is placed in the center of peasycam to check if the view matrix is applied correctly. A box gives you a better feeling of the scene.
Here the solution (just add your shaders again):