How to draw many instances (Low Level GL)

edited March 2016 in GLSL / Shaders

Is there any example of how to draw many instances of the same PShape or mesh? I found an cinder example for c++ which uploads the transforms with a gl_array and the shader reads out the transformation data.. (the usual way to do that, from what i understand)

I am trying to translate that to PGL, but looking at the Processing low level gl samples, i really need some help / tipps where to start

Answers

  • there is a Many PShapes example in the tutorials on the website.

  • edited March 2016

    thanks - i am aware of that, but i specifically would need the buffered approach, as i want to draw about 100k objects. PShape is not applicable, as it would be way slower once i want to edit the positions etc, and also eat up a lot of memory

  • have you tried? PShape uses VBOs under the covers (according to that tutorial)

  • edited March 2016

    yes i tried, unfortunately it is not so much about the PShape draw speed, but about the transforms that have to run each loop from the cpu to gpu.

    Creating a grouped PShape would take care of that too, but as far as i understand, it would also create a unique geometry for each child (hence the memory problem). Also editing single child positions is possible, but changing a lot at the same time is too slow.

    The instanced method with a custom shader can draw every instance of the specific shape in one draw call - thats what i am after.

  • like Point sprites?

    A handle to the raw GL object is available and you can call any Java code from within processing so you can get a bit closer to the metal should you need to.

    Also, shaders are available but the processing shader dialect is a bit odd so I'm not sure you can just copy the ones you have across. (Which may be the reason your asking this question)

    Which processing version? In P2 there was also a GlGraphics library that made vbos a bit easier to handle. I think the PShape code came from that.

    but it does sound like you want a shader, so i've moved this to the shader section.

    maybe a link to the cinder example would help us.

  • edited March 2016

    https://github.com/cinder/Cinder/blob/master/samples/_opengl/InstancedTeapots/src/InstancedTeapotsApp.cpp

    above is the link to the code example. Also very crucial for me - how can you redirect pgl commands to a createGraphics object? Thanks!

    Ps: https://github.com/cinder/Cinder/blob/master/samples/_opengl/InstancedTeapots/assets/shader.vert

    Is the shader code.

    just as additional info - i want to draw a small set of meshes in different places a lot of times - think tree > forrest

  • Hey @Damjan, I haven't seen any example for geometry instancing using Processing. Since P5 uses jogl, and you can get the jogl context from the pgl object, it could be possible to implement it.

    A quick search showed a jogl example with instanced drawing. Not sure wich jogl version is currentlly used by Processing or if its compatible with the example, sorry. Tell us something if you manage to get it working,please.

  • Did anybody find any examples of geometry instancing using Processing 3? I am working on a project that could use this and I would like to see some samples as I could not figure out how to implement the JOGL examples.

Sign In or Register to comment.