AddMesh and Reduce Draw Calls?

Blitz3D Forums/Blitz3D Beginners Area/AddMesh and Reduce Draw Calls?

RustyKristi(Posted 2016) [#1]
I have meshes with alpha textures, is using AddMesh and combining them going to reduce my draw calls and improve framerate?


Bobysait(Posted 2016) [#2]
If the surfaces use the same material, they 'll be mixed into a single surface, then you'll gain performance.
Else, it will juste add another surface to the mesh = same amount of draw calls (but less matrix transformations, so it's a gain too, but almost insignificant)

Now, the problem with alpha stuff : intersection in the same mesh using alpha will result in z-fighting issue. Generally, we try to explode alpha meshes into several meshes that don't intersect the one on the others.
So, it's another aspect you should take care.


RustyKristi(Posted 2016) [#3]
thanks bobysait. I did notice that if you keep camera distance to a minimum, z-fighting is ok.

I would just like to optimize performance with dynamic geometry or primitives created at runtime.


RemiD(Posted 2016) [#4]
The less surfaces the less time it takes to render, but only if the scene is organised in different zones so that some zones which are not in the fov or masked (occluded by a wall or a big shape) can be hidden., There has been several discussions and demonstrations about this on these forums, maybe do a search...
But sometimes it is more practical to use copyentity, especially for turning/moving/animating entities.
For example, in my snowfall snowaccumulation demo, the falling snowflakes use copyentity (but i could have used a single surface particles system) and the melted snowflakes on the ground are merged in one mesh a few surfaces (because there is a maximum number of vertices/triangles per surface or you will get a mav on some graphics cards)


RustyKristi(Posted 2016) [#5]
btw I did not know b3d supports occlusion culling, not the camera not in view thing.

so completely hidden meshes are not rendered?

I found one of these topics and assume nothing has changed in regard to handling occlusion

http://www.blitzbasic.com/Community/posts.php?topic=26335


RemiD(Posted 2016) [#6]

I did not know b3d supports occlusion culling


it does not by default, but you can create your own system (using zones and passages)


Bobysait(Posted 2016) [#7]

thanks bobysait. I did notice that if you keep camera distance to a minimum, z-fighting is ok.


My bad, I was talking about z-order (not z-fighting)
The z-order problem with the alpha surface can't be fixed by setting the camera's depth


RustyKristi(Posted 2016) [#8]
thank you for that. For some reason, some of my models are ok with z-order (I just put in entity order 0) and this is with alpha surfaces as you mentioned. I don't know why but it works.

If I combined multiple objects with alpha surf on them (ie bunch of trees) it does have z-order or fighting whatever problem it is but it does not look good.


Bobysait(Posted 2016) [#9]
problem with alpha comes when you have a surface that is rendered, at the same time, before AND after another. As mentionned, the z buffer can only store a single value, so what happens is :

- for each pixels from the first surface, it writes the alpha on the z buffer
- for each pixels of the second surface, if it finds that there are already a pixel at a point that is nearer than the pixel you want to add, it will skip it. So it doesn't add it with a blending mode or else (while, it's true that the previous pixel was nearer, it doesn't care it was an "alpha" pixel, so the alpha will override a solid pixel making it not being drawn at all - and here is the glitch of the z-order)
And that's what make the thing goes wrong.

So, in some case, you won't notice it because surfaces are well sorted or does not "intersect" with an other surface depth. But for trees, (it's probably the most frequent case where it happens) it's a real problem. For now, we generally solve this by not using "Alpha" flag on texture for the leaves, but use the "Mask" flag. So the leaves are actually rendered as "0" alpha or "1".
(It's also a common problem with terrain splatting when you want to add a plane to modelise water, but it's still a problem because it can't be solved with a simple Mask -> so we need to split the plane into several polygons with holes that follows the terrain "beach")


RustyKristi(Posted 2016) [#10]
in some case, you won't notice it because surfaces are well sorted or does not "intersect" with an other surface depth.


yes, maybe this is the case. At least I can conform that this is not a glitch or anomaly inside b3d.