how to maintain transparency for one object?

edited September 2015 in Questions about Code

hello,

i am building a 3d scene, where some objects are in front of the other.

i want to fade out the scene, but in doing so, the object behind is visible as soon as the alpha starts to drop.

somehow i want to have the front object retain its 'opaqueness', yet fading out at the same time.

for instance in filming the real world, a crossfade does not reveal what is behind a given object.

how can i give this solidity to a 3d object that is in front of all the others?

i tried with PGraphics and clear() and some blendModes, but am not having much luck.

float a = 0;

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


void draw() {
  background(0);
  translate(width/2, height/2);
  noFill();
  a = map(mouseX, 0, width, 0, 255);
  fill(255, a);
  noStroke();

  box(50);

  pushMatrix();
  translate(100, 0);
  box(50);
  popMatrix();

  pushMatrix();
  translate(-100, 0);
  box(50);
  popMatrix();

  sphere(50);
}

Answers

  • Can you describe in more detail what fading out looks like? Try to break it down into very small steps that each last much less than a second. What is happening when it starts to fade? What is happening when it's almost completely faded?

  • after some research i think what i need is back face culling. i tried some experiments with PGL calls but didn't have much luck. think its a bit beyond me for the timeline i have ahead of me so i think i'll have to fix it in a lofi way

  • edited September 2015 Answer ✓

    Back face culling is the way to go:

    import com.jogamp.opengl.GL; // Import GL
    
    float a = 0;
    
    void setup() {
        size(400, 400, P3D);
    }
    
    
    void draw() {
    
        background(0);
        translate(width/2, height/2);
        noFill();
        a = map(mouseX, 0, width, 0, 255);
        fill(255, a);
        noStroke();
    
        GL gl = ((PJOGL)beginPGL()).gl.getGL(); // Begin PGL and get the GL reference
        gl.glEnable(GL.GL_CULL_FACE); // Enable back face culling
    
        box(50);
    
        pushMatrix();
        translate(100, 0);
        box(50);
        popMatrix();
    
        pushMatrix();
        translate(-100, 0);
        box(50);
        popMatrix();
    
        sphere(50);
    
        flush(); // Render it before using end PGL
        endPGL(); // End PGL
    }
    

    Don't know if there's a hint() for this? :/

  • thank you poersch u made me realise i had my code in the wrong order

Sign In or Register to comment.