Alpha weird behaviour

Dear All
I tried to research about it but I couldn’t find anything. I have this simple example:

void setup(){
  size(600,600, P3D);
  
}

void draw(){
  background(0);
  translate(width/2, height/2, 0);
  rotateY(radians(mouseX));
  rotateX(radians(mouseY));
  fill(255,0,0,50);
  pushMatrix();
  translate(-80, 0,-80);
  box(100);
  popMatrix();
  
  fill(255,255,0,50);
  pushMatrix();
  translate(80, 0,80);
  box(100);
  popMatrix();
  
  fill(255,0,0,50);
  pushMatrix();
  translate(80, 0,-80);
  box(100);
  popMatrix();
  
  fill(255,255,0,50);
  pushMatrix();
  translate(-80, 0,80);
  box(100);
  popMatrix();
}

My simple question is related with alpha behaviour. If I set all boxes to 50 Alpha isn’t suppose to see all box transparent. They have transparency but in some sideviews it loses completely when I rotate. It also doesn’t present any logic in the way it display the transparency. Look a this screenShot


the left box has transparency and the right one doesn’t .
Could some one help me out to solve this enigma.

Thank in advance

2 Likes

-a- please format your code using the

</> code tag of the editor

what looks like
```
type or paste code here
```


i not used your boxes example ( what looks very good )
but an other example where i noticed transparency problems,

i wanted to indicate a plane ( X - Y plane ) by a rectangle
and could not look through it even using alpha 10

but when i started to play with the HINT things
it worked. please try that too

  hint(ENABLE_DEPTH_SORT);      // now can look through the rectangle

void setup() {
  size(600, 600, P3D);
  hint(ENABLE_DEPTH_SORT);      // now can look through the rectangle
  //  hint(DISABLE_DEPTH_SORT);   // default
  //  hint(DISABLE_DEPTH_TEST);
  //  hint(ENABLE_DEPTH_TEST);    // default
  //  hint(DISABLE_DEPTH_MASK);
  //  hint(ENABLE_DEPTH_MASK);    // default
}

void draw() {
  background(200, 200, 0);
  translate(width/2, height/2, 0);
  rotateY(TAU*mouseX/width);
  rotateX(TAU*mouseY/height);

  axis();
  my_box();
}


void axis() {
  int max = 100;
  stroke(200, 0, 0);
  strokeWeight(2);
  line(0, 0, 0, max, 0, 0);
  strokeWeight(0.5);
  line(0, 0, 0, -max, 0, 0);
  fill(200, 0, 0);
  text("x", max, 0);
  stroke(0, 200, 0);
  strokeWeight(2);
  line(0, 0, 0, 0, max, 0);
  strokeWeight(0.5);
  line(0, 0, 0, 0, -max, 0);
  fill(0, 200, 0);
  text("y", 0, max);
  stroke(0, 0, 200);
  strokeWeight(2);
  line(0, 0, 0, 0, 0, max);
  strokeWeight(0.5);
  line(0, 0, 0, 0, 0, -max);
  fill(0, 0, 200);
  text("z", 0, 0, max);

  fill(100, 100, 0, 10); // transparent not work
  noStroke();
  //max = 20;              // so make it small
  rect(-max, -max, 2*max, 2*max);   // xy plane
}

void my_box() {
  translate(0, 0, 50);
  fill(200, 0, 200);
  stroke(0, 200, 0);
  box(20);
}

2 Likes

Thank you I will try out :slight_smile: