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

edited July 2015 in GLSL / Shaders

Hello,

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.

Answers

  • 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);
    gl.glClear(GL2GL3.GL_COLOR_BUFFER_BIT | GL2GL3.GL_DEPTH_BUFFER_BIT);
    gl.glEnable(GL2GL3.GL_CULL_FACE);
    /* ... */
    
    // End "low level GL" code
    g.endPGL();
    

    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

    Hello,

    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:

    https://www.dropbox.com/s/6i0a3trqz8r2olo/save_point_pshape.zip?dl=0

    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.