how to return a modified version of a PShape from a PShader

edited July 2015 in GLSL / Shaders


Is it possible to return data from a PShader ?

I'm using a vertex shader to update the vertices position of a PShape. I'd like to access this modified version to perform additional modifications inside draw() or at least use this modified version with the same PShader next time draw() is called.


  • edited October 2015

    Short answer: No. Although OpenGL does support Transform Feedback since version 3.0 (which offers the wanted features), PShader/Processing does not.

    Long answer: Of course. Using "low level GL" you can utilize anything OpenGL has to offer:

    // Begin "low level GL" code
    GL2GL3 gl = ((PJOGL)g.beginPGL()).gl.getGL2GL3();
    // Do some "low level GL" stuff
    gl.glClearColor(bgRed, bgGreen, bgBlue, 1.0F);
    /* ... */
    // End "low level GL" code

    But do you really need to? What kind of vertex modifications are we talking about? Displacement mapping, a simple heightmap mesh generation? How often do you need to manipulate/transform the shape's vertex data? Can the generation process be moved to the CPU?

    A little example sketch portraining what you are trying to achieve would be helpful.

  • edited October 2015


    I'm using different shaders to animate a PShape in different ways.

    The first shader does some displacement mapping and the second one animates the PShape as a particles system.

    I only need to edit the PShape (by saving the position of its vertices) when I choose to use another shader in order to create smooth transitions.

    For the moment when I choose another shader, I start with the inital position of the vertices.

    I have made a very simple sketch to explain what I'm trying to do:

    When you click on the sketch you can you choose another shader but as you will see I do not know how to save the last position of my vertices using opengl.

    In my example I'd like to keep the last position of my PShape when I start to use "pointShader2".

Sign In or Register to comment.