P2D over P3D into P3D sketch

edited January 2014 in GLSL / Shaders

Hello,

I would like add a P2D layer over another with P3D render; the problem is that the 3d object intersect in Z axis with the P2D layer, and the light is influecing the P2D layer.

The question is if there are a method for put the 2d layer always over the 3d and if I make the light ingnored the p2d layer...

very thanks! muy first post!

Answers

  • edited January 2014

    The simplest solution I can think of:

    In setup(): Set your main renderer to P2D and create an P3D offscreen buffer.

    In draw(): Render the 3D stuff to the offscreen buffer, render the offscreen buffer to the main canvas, render all 2D stuff to the main canvas.

    Example:

    PGraphics canvas;
    float angle = 0;
    
    
    void setup() {
    
        size(800, 800, P2D);
    
        canvas = createGraphics(width, height, P3D);
    
    }
    
    
    void draw() {
    
        angle += 0.01;
    
        canvas.beginDraw();
        canvas.background(#000000);
        canvas.noStroke();
        canvas.pointLight(255, 0, 25, mouseX, mouseY, 800);
        canvas.translate(width / 2, height / 2);
        canvas.rotate(angle, 1.0, 1.0, 0.5);
        canvas.box(width / 3);
        canvas.endDraw();
    
        image(canvas, 0, 0);
    
        text(frameRate, 10, 10 + textAscent());
        text(mouseX + ", " + mouseY, mouseX, mouseY);
    
    }
    
  • Thank you!

    The solution is good, what happens is that I'm using the library Objloaders from saito, and I can not insert the library into a pgraphics, so the sketch is a p3d.

    Thank you very much!

  • edited January 2014 Answer ✓

    No problem. :)

    I never used .OBJ loader, but I assume it uses the main canvas (this.g) as drawing surface, so swapping the g reference could do the trick:

    PGraphics buffer, canvas;
    
    
    void setup() {
    
        size(800, 800, P2D);
    
        canvas = createGraphics(width, height, P3D);
    
    }
    
    
    void draw() {
    
        drawOn(canvas);
        background(#000000);
        noStroke();
        pointLight(255, 0, 25, mouseX, mouseY, 800);
        translate(width / 2, height / 2);
        rotate(frameCount / 100.0, 1.0, 1.0, 0.5);
        box(width / 3);
        drawOff();
    
        image(canvas, 0, 0);
    
        text(frameRate, 10, 10 + textAscent());
        text(mouseX + ", " + mouseY, mouseX, mouseY);
    
    }
    
    
    /////////////////////////////////////////////////////////////
    // Set the applets main canvas to the given one /////////////
    /////////////////////////////////////////////////////////////
    public PGraphics drawOn(PGraphics canvas) {
        buffer = g;
        g = canvas;
        g.beginDraw();
        return canvas;
    }
    
    
    /////////////////////////////////////////////////////////////
    // Reset the applets main canvas ////////////////////////////
    /////////////////////////////////////////////////////////////
    void drawOff() {
        g.endDraw();
        g = buffer;
    }
    
  • edited January 2014

    yes....

    I normally use size with OPENGL or so

    then do 3D stuff

    at the very end of draw() I say

    camera();
    noLights;
    

    hints do the trick

    do 2D stuff rects / texts....

  • here...

    // PGraphics canvas;
    float angle = 0;
    
    
    void setup() {
    
      size(800, 800, P3D);
    
      // canvas = createGraphics(width, height, P3D);
    }
    
    
    void draw() {
    
      angle += 0.01;
    
    
      background(#000000);
      noStroke();
      pointLight(255, 0, 25, mouseX, mouseY, 800);
      translate(width / 2, height / 2);
      rotate(angle, 1.0, 1.0, 0.5);
      box(width / 3);
    
    
      // image(canvas, 0, 0);
      camera();
      //  hint(DISABLE_DEPTH_MASK);
      hint(DISABLE_DEPTH_TEST);
      noLights();
      textMode(MODEL);
      text(frameRate, 10, 10 + textAscent());
      text(mouseX + ", " + mouseY, mouseX, mouseY);
      hint(ENABLE_DEPTH_TEST);
    }
    
  • thank you! I have tried both options but to Poersch worked at first, I was not able to solve the Chrisir (I'm newbie).

    Thank you very much, greetings!

Sign In or Register to comment.