Am I doing something wrong or hint(ENABLE_DEPTH_SORT); only works with beginShape() and endShape() and not with PShape. If I am not wrong, and this is a issue, how can I do depth sort myself on PShapes ?
Screenshot, red = PShape, blue = not PShape like : beginShape(), box(), line() …
I could not install QueasyCam (it fails) so I tried with PeasyCam
import peasy.*;
PeasyCam cam;
PShape box;
PShape sphere;
public void setup() {
fullScreen(P3D);
cam = new PeasyCam(this, 400);
box = createShape(BOX, 100.0f);
sphere = createShape(SPHERE, 50.0f);
box.setStroke(false);
box.setFill(color(255, 0, 0, 100));
sphere.setStroke(false);
sphere.setFill(color(255, 0, 0, 100));
noStroke();
fill(0, 0, 255, 100);
}
public void draw() {
background(255);
// Just to be sure
hint(ENABLE_DEPTH_TEST);
hint(ENABLE_DEPTH_MASK);
// Magic line that should all correct
hint(ENABLE_DEPTH_SORT);
for(int i=0; i<2; i++) {
translate(0, 0, i*200);
pushMatrix();
translate(100, 100, 0);
sphere(50);
translate(-200, 0, 0);
box(100);
translate(0, -200, 0);
shape(box);
translate(200, 0, 0);
shape(sphere);
popMatrix();
}
}
For me too the shapes created with createShape behave different from those drawn directly.
But even when dealing only with shapes drawn directly the transparency works only sometimes, depending on the rotation.
But same problem with QueasyCam in some angles hint(ENABLE_DEPTH_SORT); doesent work properly PShape or not I thought at least it worked 100% without PShape
I modified this program for testing transparency and hints and it seems like things are fine (as @neilcsmith suggests) when all three hints are disabled.
That wasn’t quite what I suggested! There are still times you might want to depth sort to do the painter’s algorithm, although sometimes the output will be fine without. I’m just not sure when you’d want to depth test and depth sort together.
Wow ! At first i thought it worked well… but if you add opaque objects you see it doesent work. I also tried enabling per object depth mask but still doesent work.
Thinking about it I’m not sure disabling the depth test is correct. Draw solid objects with depth mask enabled, then draw depth sorted translucent objects with depth mask disabled?
This seems to work correctly? Enabling / Disabling depth sort doesn’t change anything, although I think it might if the translucent shapes were different colours / opacities?
import peasy.*;
PeasyCam cam;
PShape shp1, shp2;
void setup() {
size(800, 600, P3D);
cam = new PeasyCam(this, 400);
shp1 = createShape(SPHERE, 90);
shp1.setStroke(false);
shp1.setFill(color(100));
shp2 = createShape(BOX, 180);
shp2.setStroke(false);
shp2.setFill(color(255, 40, 20, 100));
}
void draw() {
background(255);
// All opaque
hint(ENABLE_DEPTH_MASK);
//hint(DISABLE_DEPTH_SORT);
for(int i=0; i<2; i++) {
for (int x = -200; x<=200; x+=200) {
for (int y = -200; y<=200; y+=200) {
pushMatrix();
translate(x, i*300, y);
if ((x+y)/200 % 2 == 0) {
shape(shp1);
}
popMatrix();
}
}
}
// All transparent
hint(DISABLE_DEPTH_MASK);
//hint(ENABLE_DEPTH_SORT);
for(int i=0; i<2; i++) {
for (int x = -200; x<=200; x+=200) {
for (int y = -200; y<=200; y+=200) {
pushMatrix();
translate(x, i*300, y);
if ((x+y)/200 % 2 != 0) {
shape(shp2);
}
popMatrix();
}
}
}
}