PShape with transparent texture issue

Trying to get texture with transparency on a PShape.

It seems some faces can’t see through to the face behind, but then apparently it still sees behind that again (background). Not to mention the texture is flipped on all sides, at least for the box shape (or perhaps just inside-out?).

I tried searching for it, multiple finds but they are all about the transparent objects themselves, not objects with transparent sides (that I found at least).

Also found some hint() settings, but the only thing that changes the visuals (apparently) is the DEPTH_MASK setting.

Demo: (Picture with transparency from here, I used 240px version).

/**   Texturing tests

  hint test method from
  https://discourse.processing.org/t/program-to-test-hint-with-transparency/4361
  
  Image (used 240px version) from
  https://commons.wikimedia.org/wiki/File:Processing_3_logo.png
*/
import peasy.*;
PeasyCam cam;

PImage tex;
PShape someShape;

boolean b[] = { true, true, true };

void setup()
{
  size(600, 600, P3D);
  avoidClipping();
  cam = new PeasyCam(this, 0, 0, 0, 200);
  cam.setMaximumDistance(1000);

  tex = loadImage("240px-Processing_3_logo.png");
  someShape = createShape(BOX, 150, 100, 100);
  someShape.setTexture(tex);
}


void draw()
{
  background(32);
  cam.beginHUD();
  fill(220);
  text("DEPTH_TEST " + b[0], 20, 20);
  text("DEPTH_SORT " + b[1], 20, 40);
  text("DEPTH_MASK " + b[2], 20, 60);
  text("<- use the mouse to toggle settings", 180, 40);
  
  image(tex, 300,100);
  cam.endHUD();

  shape(someShape);
}


void avoidClipping() {
  // avoid clipping (at camera): 
  perspective(PI/3.0, (float) width/height, 1, 1000000);
}


void mousePressed() {
  int id = mouseY / 20;
  if (id < b.length) {
    b[id] ^= true; // same as b[id] = !b[id]
  }
  hint(b[0] ? ENABLE_DEPTH_TEST : DISABLE_DEPTH_TEST);
  hint(b[1] ? ENABLE_DEPTH_SORT : DISABLE_DEPTH_SORT);
  hint(b[2] ? ENABLE_DEPTH_MASK : DISABLE_DEPTH_MASK);
}
1 Like