Depth Sorting and PShape

Yeah wow ! It actually works, I also tried different colors, seems to work well. :smiley:

But… when you move the camera, maybe its just me, but it display weird artefacts :

Actually : It works !!! :smiley: :tada::tada: @neilcsmith thank you very much :smiley: I’ts been so long since i wanted to solve this problem. You’re the best !!

I had processing 3.3.6, in 3.4.0 no artefacts !

The solution, supports transparent & opaque PShapes to be rendered correctly (exemple) :

import com.jogamp.opengl.GL2ES2;
import com.jogamp.opengl.GL;

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) {
         shp1.setFill(true);
         shp1.setFill(color(x+200, y+200, i*100));
         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) {
         shp2.setFill(true);
         shp2.setFill(color( 255-(x+200), 255-(y+200), 255-(i*100), 100 ));
         shape(shp2);
       }
       popMatrix();
     }
   }
 }
}```
1 Like