particles?BlitzMax Modules Forums/MiniB3D/particles?
| Has anyone got a particle system working with minib3d . I'm sure i could make something that works but im not sure how to make it fast. I know theres lots of 2d examples but im not sure what people mean by single surface? I thought the expensive part was drawing lots of times to a surface not how many there were. |
| There's a large number of different particle type systems one could implement. What I personally do:|
Create an empty mesh
Create an empty surface in the mesh
Create tons points/tris in the surface
Track/move each 3 point tri set as a particle
Manipulating the x/y/z/u/v coords of points is fast, and since there's only one object with one surface it's easy to upload the changes to the 3D card, and easy for the accelerator to handle it all.
| If speed is important, the code in here (pos 6) http://www.blitzbasic.com/Community/posts.php?topic=97398 i got working with help from Adam. ~100,000 camera aligned billboard particles at 60fps. You'd need to tidy it up a bit i suppose, but the rendering is quick.|
Otherwise i'd recommend using the single surface mesh method mentioned above.
I thought the expensive part was drawing lots of times to a surface not how many there were.
In 3D land, a surface is an array of verts and triangles with a texture. Traditionally, it is the unit that gets uploaded to the graphics card in a single burst, with the context having to be opened beforehand and closed afterwards. Therefore, packing as much as possible onto one surface reduces the bottleneck between the CPU and the graphics card, for systems like miniB3D that make heavy use of the CPU, by reducing the number of "bursts" in which things are fired across.
Once it's on the graphics card, hardware takes over and it doesn't really matter how many times the texture is repeated, because hardware is witchcraft (also, you only draw one texture to a surface; the UVs mean it can be repeated in many places but only one per layer is there). No loop, no multiple starts and stops.
| To further explain what Yasha said, a surface isn't what you see as a surface rendered in 3D, it's a concept for organizing data, as such you need a good understanding of what the terms really mean in the context of the engine and how it works to see why one "surface" is really fast even if it's very complex. |
| I didn't know that was how it works. I've got to say i still don't understand but i will have a go |
| A Surface is an object that holds geometry (vertices and triangles) that will be painted by a Brush.|
A Brush can be considered as a 'material': it holds a texture (or composition of), color, shininess and other effects.
A Mesh can have as many Surfaces as you want, and each of these Surfaces can be painted by a single Brush.
If you paint an already painted Surface you'd just be changing the Brush currently assigned to it.
The more Surfaces a Mesh has, the more expensive it is to render it.
The way graphical hardware works, to render a complete Mesh you have to render each of its Surfaces consecutively (in as many 'passes' as there are Surfaces). You can't do all Surfaces at once.
So a Mesh with 100 Surfaces, each of these Surfaces with 1 triangle, is much slower to render (in other words, 'has more overhead') than a Mesh with 1 Surface that has 100 triangles in it.
So get this: if you have a collection of Surfaces all painted with the same Brush, why not combine the geometry these Surfaces hold into a single Surface?
By use of multiple-frame textures (known as texture-sheets or atlases) and intelligent handling of the geometry stored in a Surface as abstract primitives such as quads, for instance, you can have a whole lot of 'visually different' elements stored together, all in the same Surface.
The benefit of this optimization, known as 'batching', is that all this geometry will be rendered at once instead of in several passes.
This really speeds rendering for Meshes with plenty of repeated geometry, such as particle systems, special effects etc. (so this is not particularly useful for characters or environments, which take other forms of optimization).
| Thanks for the info i will have a go at coding something and ask question later. Thanks again for the clear explanations |
| written for minib3d+monkey, but you are welcome to convert it to blitzmax, although there may be some challenges.|
Usage is as simple as "sprite = TBatchSprite.CreateSprite()".
Last edited 1+ years ago
| thanks having scanned though the code theres quite a bit i don't understand but ill give it a go first and then ask questions if needed. I want to learn how to code this not just have someone do it for me. I don't want people to think I one of the copy and paste coders. |
| TBatchSprite should be an existing addition to miniB3D, since it's actually in iminib3d.|
Also, after taking a quick stab at adding it into bmax minib3d, it will require a small trick to get the camera info into the batchsprite update.