Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Processing - See through transparent 3D shapes

Tags:

3d

processing

I would like to be able to see through transparent 3D shapes. For example, this:

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

void draw() {
    clear();
    translate(width/2, height/2, -width/2);

    stroke(255);
    fill(0, 255, 255, 100);
    box(width);

    noStroke();
    lights();
    fill(255);
    sphere(100);

}

...displays this:

screenshot1

but I want this:

enter image description here

Note that I just added hint(DISABLE_DEPTH_TEST) for the second one. I would like a solution without this because, you know, it disables the depth test.

like image 718
Rostan Avatar asked Dec 07 '25 05:12

Rostan


1 Answers

I recommend to draw the box with disabled depth test. But enable the depth test before the sphere is drawn:

void draw() {
    clear();
    translate(width/2, height/2, -width/2);

    hint(DISABLE_DEPTH_TEST);
    stroke(255);
    fill(0, 255, 255, 100);
    box(width);

    hint(ENABLE_DEPTH_TEST);
    noStroke();
    lights();
    fill(255);
    sphere(100); 
}

preview

like image 137
Rabbid76 Avatar answered Dec 11 '25 08:12

Rabbid76



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!