Depth Sorting and PShape

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? :confused:

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();
     }
   }
 }
 
}

1 Like