# Agnostic Transparencies

**URL:** <https://discourse.processing.org/t/agnostic-transparencies/22997>\
**Category:** Coding Questions\
**Created:** [August 2, 2020, 4:39pm UTC](https://discourse.processing.org/t/agnostic-transparencies/22997 "2020-08-02T16:39:52Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Aleksi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/aleksi/32/11065_2.png) [@Aleksi](https://discourse.processing.org/u/Aleksi)\
**Post date:** [August 2, 2020, 4:39pm UTC](https://discourse.processing.org/t/agnostic-transparencies/22997/1 "2020-08-02T16:39:53Z")

</div>

Hi there. Is there any way to draw transparent objects that allow them to stay transparent no matter which order they’re drawn?

Here’s a gif demonstrating how the order in which they’re drawn affects an object’s transparency relative to ones drawn after it:

![TransparencyTest](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/fa9cfd5e14da3e5414c209cb183f58e67b54a13e.gif)

Is there any straightforward way to draw the red & blue shapes that allow both to be transparent? Since they’re both the same distance from camera we can’t use any depth sorting, nor `Comparable.compareTo()` since I won’t be able to privilege one dimension or field over another.

Here’s the code in its entirety:

```auto

// TEST SURFACE TRANSPARENCIES BASED ON CREATION ORDER //

PShape psRed, psBlu;

void setup(){
  size(300,300,P3D);
  //hint(ENABLE_DEPTH_SORT); doesn't apply
  psRed = surf(150, 100, -50, color(255, 0, 0, 80), color(255, 255, 0, 150), 5);
  psBlu = surf(150, 100, 50, color(0, 0, 255, 80), color(0, 255, 255, 150), 5);
  fill(0, 255, 0, 100); noStroke();
}

void draw(){
  background(255);
  pushMatrix(); translate(width/2, height/2);
  rotateY(frameCount*.01);
  
  // upper sphere visible because drawn first
  pushMatrix(); translate(0, -25); sphere(10); popMatrix(); 
  
  shape(psRed, 0, 0); // red obscures blue because red drawn first
  shape(psBlu, 0, 0);
  
  // lower sphere obscured because drawn last
  pushMatrix(); translate(0, 25); sphere(10); popMatrix(); 
  
  popMatrix();
}

PShape surf(float dim1, float dim2, float dist, color fcol, color scol, float sw){
  // build surface on YZ plane //
  PShape ps = createShape();
  ps.beginShape();
  ps.fill(fcol);
  ps.stroke(scol);
  ps.strokeWeight(sw);
  ps.vertex(dist , -dim1/2 , -dim2/2);
  ps.vertex(dist , dim1/2 , -dim2/2);
  ps.vertex(dist , dim1/2 , dim2/2);
  ps.vertex(dist , -dim1/2 , dim2/2);
  ps.endShape(CLOSE);
  return ps;
}

```

---

_[View the full topic](https://discourse.processing.org/t/agnostic-transparencies/22997)._
