Draw calls and Defold

As of Defold 1.2.106 this is no longer true. Instead of issuing one drawcall per emitter, we now batch on:

  • Emitter material
  • Texture (tile source)
  • Blendmode
  • Render constants
7 Likes

@britzl wrote a nice summery here How to "merge" sprites in defold here is a blatant copy of it!


To clarify:

Rendering of sprites, spine models, particle fx etc

  • Rendering is based on z-order, back to front.
  • Components on different depths will be batched unless one of the following is different from the previous component:
    • Component type (sprite, spine, particle, label, model)
    • Texture
    • Material
    • Blend mode, tint etc
    • Collection proxies
    • Note: Each particle emitter will result in a draw call

Rendering of gui scenes

  • Rendering is based on the order of the nodes in the outline, depth first
    • Nodes will be batched unless one of the following is different from the previous node:
    • Node type (box, text, pie)
    • Texture
    • Blend mode
    • Font
    • Stencil settings

Layers are used to group different nodes to reduce the number of draw calls. Some images:




Example of the complexity stencil add

A basic scene

Same scene with a stencil

12 Likes

Does somebody can to explain why?

In gui the color is sent as vertex attributes as opposed to uniforms (I’m quoting Sven here).

3 Likes

Thank you, as I thought. And I have been to look into shaders before ask =)

1 Like

And why is that? You could have the possibility to set vertex attributes for sprites as well to be used for tinting (or other things) in the sprite shader as well.
Or do you use them internally for something?

1 Like

Good question! @sven?

2 Likes

Could you post your overdraw shaders?

If we could get the ability to set tinting / alpha with sprites in a way which didn’t break batching it would be super great.

The answer to that is customizable vertex formats, which I think is on our roadmap for this second half of this year. (@britzl knows more)

3 Likes

The one I use are available in DefFX

4 Likes

agree,
sprite tinting is required to create a retro lighting like the old X-Com, for example:
ufo_041

2 Likes

Yeah, it’s in our roadmap. Not sure when we’ll tackle it, but if I’m guessing it’s somewhere in December or January.

6 Likes

Hi! When are you planning on fixing the issue(batching tint and other)?

1 Like

We mentioned custom vertex formats in our most recent Roadmap Post. We’re slightly behind in terms of what we had hoped to deliver by now due to in part some stability issues during the autumn and in part because of internal needs that was given higher priority. The roadmap post is still accurate, but I will post an update in beginning of January with some updates.

5 Likes

any news?

2 Likes

News on custom vertex formats or on the roadmap (there was a new roadmap post made in January as promised)?

1 Like

News about this:


as I understood “custom vertex formats” solve this.

3 Likes

I’d like to hear some clarifications on this amazing post, namely if and how the situation changes when using custom render predicates / materials / shaders, since if I understand it correctly, this guide assumes that the builtins are used everywhere.

Would different component types break batching if they were to use the same material? Or different materials but the same rendering predicate?

Do different materials break batching by themselves, or is it ultimately because they use different shaders?

Tint is explicitly said to break batching (as long as the values are not the same), but I assume this goes for any other custom constant I might be using, right?

Does this apply only to fragment shaders, or do different vertex shader constant values also break batching?

Thanks for any insight you can give me.

2 Likes

The batch rules are documented here:

2 Likes