Defold 1.9.4 BETA

Is this similar or same as “GPU instancing”? (Unity - Manual: GPU instancing)

1 Like

Yes, there’s a manual entry for how this works here: Defold materials manual

3 Likes

It’s easy to do. We can grab it from the GH data like you suggest. How should it be presented? Next to the issue title? Or after the description? Example:


NEW: (#9474) The physics contact_point_event now returns the correct contact point (authored by JCash)
This is a bug fix for the contact_point_event, where the position is now the contact point itself.
This makes it similar to the contact_point_response event, which was the intention.

If you need the old position (the world position of the object itself), you can use either message.a.instance_position/message.b.instance_position.

Authored by JCash

5 Likes

Thanks :+1:
Example work. Instancing in my game also worked. :fire:

I have question. If i make material with instancing, I need to use new predicate for every unique model?

So if i have 3 different stones. When i use single predicate i get same draw call number with instancing and without it.

But with 3 predicates(unique predicate per model) it worked.

So when rendering, if mesh is not same will break batching instancing?

3 Likes

No you should be able to use the same predicate. As long as the render state is the same (same textures and meshes) all instance models will be included in the same draw call. In general, you shouldn’t have to think about it, the renderer should separate the instances into their bucket automatically.

Could you share your example?

I I will share later.
The collection use 3 different models(stone1,stone2,stone3)
If every model use same material with instancing.
For example in scene I have 6 models.
stone1,stone2,stone3,stone1,stone2,stone3.

Will instancing group models automatic. So it draw stone1,stone2,stone3?

Or it will draw, stone1, stone2,stone3, stone1,stone2, stone3?

How many predicates I can use? 32?

Also is it good or bad to enable instancing for all models?
For example I have some modelsz that used once, or few times.

It is bad for once model to use instancing?

1 Like

No, it’s not inherently bad in any way.

1 Like

It will be grouped automatically

1 Like

I think this not worked(

I will try to make small example, later today

I try but find something strange.
instancing_groups.zip (1.7 MB)
1)For default model.material i get same dc as for instancing
2)For default model.material i see modelVertexCount in profiler. But for instancing i don’t see it.

Also i can’t reproduce that:(

@jhonny.goransson

This is my game in 1.9.3.


And in 1.9.4

I am happy to see smaller dc number. But why? is it expected behavior? I don’t enable instancing

Yeah hold on, I’m investigating this. I think the batch key is getting calculated a bit strangely in some cases that include instancing. It is supposed to work as I proposed, but I might need to make a small change on our end.

4 Likes

Right, this is how it’s supposed to work:
This scene has 6 model componens - 3 with one .glb file and 3 with another .glb file. Each model is referencing multiple meshes (~10 meshes per glb file). With instancing this means that we should be able to render all sub meshes for each model in one draw call:

Here you can see that the heads of one of the model is getting rendered all in one go, which is what is expected.

There is a PR currently for the batch key change, so I’ll let you know once it’s been merged to beta :+1:

4 Likes

You right here. I investigated it, and it seems like we don’t have enough parameters for draw_text message to draw it nice in a 3d world.
I’m reverting these changes.

3 Likes

is it done already?

I also tried turning on instancing on one project with a lot of repetitive geometry like a selected block on the screenshot:

My results:

  1. Whole project before changes. The world vertex space in the model material is used. 19 draw calls, huge modelVertexSize.

  2. Just turn on the local vertex space in the model material. (mtx_world as uniform)

  3. and mtx_world as attribute:

I don’t see a reduction in the number of Draw calls, but I do see other changes.
When instancing is used how are models ordered by distance from the camera?

ps. tested with beta sha1 40a62943dd9c72d3544bcfa368838d5ee79204fb

2 Likes

The build is stuck currently on CI. I’ll let you know

1 Like

There is a new beta now with a fix.

2 Likes

Seems, it works ! )

4 Likes