[SOLVED]Instancing different batch amount on one mesh buffer

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
kevinsbro
Posts: 51
Joined: Fri Nov 05, 2010 8:18 pm

[SOLVED]Instancing different batch amount on one mesh buffer

Post by kevinsbro »

So while trying to apply GPU instancing I run into a problem that comes from having to render the instanced set with different materials. The max number of batches varies across shaders due to different amounts of data that need to be passed to the shader.
Now here's the problem...
The mesh buffer (an SMeshBufferLightMap for the use of S3DVertex2TCoords) is created with X copies of a simple mesh. X represents the number of instances in a batch, which causes the problem since X varies on the material chosen to render with. I want the material to be dynamic (with dynamic batch sizes) but X in the mesh buffer is static.

I can think of two solutions but I don't like them
1) create a mesh buffer for each material I would use. (requires me keeping many copies of essentially the same data)
2) make all the shaders use the same amount of instances per batch. (requires the smallest shader instances count to be used across all shaders)

What I would like, is to find a way to render part of a mesh buffer. So in the driver->drawMeshBuffer(parameters) method, I could simply add an extra parameter of how far in the list of vertexes and indices to render to. Then I could create the buffer with the max amount of instances and then only draw the ones I need.

Is this even possible?
Last edited by kevinsbro on Sun Apr 08, 2012 10:47 pm, edited 1 time in total.
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Instancing different batch amount on one mesh buffer

Post by REDDemon »

Yes definitively possible with OpenGL and DX but Irrlicht API don't allows for that. The only way you can do that with Irrlicht is similiar to the Terrain scene node in wich different index buffers are used for the same Vertex buffer. maybe it can help to you looking at that code. I think that Nadro's patch allows for that also (not sure. I'm still unfamiliar with the new code)
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Re: Instancing different batch amount on one mesh buffer

Post by Virion »

I too think Nadro's patch would solve this problem. You can test it out. http://irrlicht.sourceforge.net/forum/v ... =2&t=38357
kevinsbro
Posts: 51
Joined: Fri Nov 05, 2010 8:18 pm

Re: [SOLVED]Instancing different batch amount on one mesh bu

Post by kevinsbro »

If anyone is curious I was able to solve this problem by extending IMeshBuffer with my own buffer class that is essentially CMeshSceneBuffer but with 2 texture coordinates instead of the generic template for vertices. And creating extra functionality of specifying the amount of instances you want rendered and using this value to alter the getIndicesCount method.

For example, to render only 3 instances from a possible MAX I simply multiply the number of actual indices by (3/MAX) and return that instead.
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: [SOLVED]Instancing different batch amount on one mesh bu

Post by REDDemon »

That's the way to go. Good job ;-)
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Post Reply