简体   繁体   中英

Processing - See through transparent 3D shapes

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:

在此输入图像描述

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.

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

预习

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM