pouët.net

Go to bottom

Instancing in OpenGL

category: code [glöplog]
If you compute it in the vertex shader, then it will be evaluated for every vertex of the instanced model. Even for cubes, that's at least 8x as much work. For more complicated models, it can be much worse.

Also, if you have e.g. a stateful particle system (with particles interacting with each other), you can't perform the simulation in the vertex shader at all. Also, some types of simulation don't map well to GPU processing, and besides, it's not all particle systems - another common usage of instancing is for foliage, for example, and in that case your data is static and you just want to draw it as efficiently as possible (both for the CPU and GPU, if possible).

What you can do if your animation is GPU-friendly is use a different shader / separate pass to write animation data to a texture, then use the "instancing from texture" method. Which is what the Fairlight GPU particle system demos use as far as I can tell :)
added on the 2010-11-24 06:01:37 by ryg ryg
Quote:
Also, if you have e.g. a stateful particle system (with particles interacting with each other), you can't perform the simulation in the vertex shader at all.

I thought stateful particle systems on gpu are commonly implemented via render to vertex texture/buffer or transform feedback nowadays?
added on the 2010-11-24 16:35:31 by snoutmate snoutmate
kusma: that's why you don't use vertex arrays, you use plain old glBegin() glEnd() and a gazillion calls to glVertex4f()

it's slow the first time, but fast afterwards.
added on the 2010-11-24 16:51:52 by jaw jaw
I insert the vertex id ((float)id/(float)max_id) in .w as glVertexID in GLSL never works anyway.
added on the 2010-11-24 16:52:50 by jaw jaw
"I thought stateful particle systems on gpu are commonly implemented via render to vertex texture/buffer or transform feedback nowadays?"
You can implement them using shaders, but not in the vertex shader used for actual rendering because that's too late to update state (as said, you see each particle multiple times). You can use a pixel shader (rendering to a texture) or a separate pass with a vertex shader using stream output (on DX10+), but it needs to be a separate pass.
added on the 2010-11-24 21:12:55 by ryg ryg
jaw: What I'm saying is you can't have additional vertex attributes with display lists. So it simply will not work.
added on the 2010-11-24 21:18:11 by kusma kusma
ryg: afaik "stream output on dx10+" is "transform feedback in ogl", like snoutmate said
added on the 2010-11-24 21:22:17 by xTr1m xTr1m
kusma: ah, yes, true that.
added on the 2010-11-24 22:00:18 by jaw jaw

login

Go to top