We are about to switch to a new forum software. Until then we have removed the registration on this forum.
blendModes does not work when looking from -Z to +Z axis in 3D. How do I make it work when looking in any direction?
import peasy.*;
PeasyCam cam;
double[] defaultCam = {
0.5, 0, 0, 1000
};
void setup() {
size(850, 400, P3D);
smooth(16);
cam = new PeasyCam(this, defaultCam[3]);
cam.setMinimumDistance(0.00001);
cam.setMaximumDistance(999999999);
cam.setRotations(defaultCam[0], defaultCam[1], defaultCam[2]);
cam.lookAt(0, 0, 0);
} // end of setup
void draw() {
background(18, 18, 20);
float cameraZ = ((height/2.0) / tan(PI*60.0/360.0));
perspective(PI/3.0, (float) width/height, cameraZ/100.0, cameraZ*100.0);
// draw axis
noFill();
strokeWeight(1);
stroke(0, 255, 0, 128);
line(0, 0, 0, 0, 80, 0); // y
stroke(255, 0, 0, 128);
line(0, 0, 0, 80, 0, 0); // x
stroke(0, 0, 255, 128);
line(0, 0, 0, 0, 0, 80); // z
stroke(255, 50);
box(10);
stroke(255);
//hint(DISABLE_DEPTH_TEST);
blendMode(ADD);
stroke(255);
fill(#3C92D6, 100);
for (int i=0; i<4; i++) {
pushMatrix();
translate(50, 0, i*100);
rect(0, 0, 100, 100);
popMatrix();
}
}
Comments
It's not the blendMode command that fails, it's the depth sorting.
Uncommenting line 35 should resolve this issue, is there a reason you commented it out? Not the desired effect or do you need the depth test for other purposes?
Is it possible to make it work with depth test?
Sure, you just have to implement some sort of depth-sorting yourself. In your case a simple check if the camera's Z coordinate is positive/negative should suffice to choose the rect render order.
Replace lines 39-44 with the following code:
If your real project needs a more complex sorting algorithm, just give us a shout, I'm sure we are able to help you. :)