Best way to limit number of draw calls(batching mashes with the same material but different UVs)

This means that we can now set per instance colors and UVs (from a texture atlas) just like it’s possible in the SPS.

1 Like

So let’s say we have a crowd : we can use the exact same instanced mesh for each character, but assigning them different materials & animations, that’s it?

Cool, can’t wait to start testing it, hope today or tomorrow :slight_smile:

@Vinc3r material needs to be the same but you can have different color or uvs.

EDIT: not sure about different animations, will test it later

the same material but different parts from the same texture image… I realize that this needs some coding from the user, it’s not that straight foward, but it’s now possible.
This is how it’s done in the SPS :

  • uvs32 are the values to be in the instance UV buffer.
  • shapeUV are the initial instance UV values, so the UV values from the instance model (the cloned mesh)
  • Vector4 uvs are the per instance coordinates of the quad, by pairs : (x,y) and (z,w), where to crop the texture image.

Maybe is a bit off topic, but as far as i know some GPUs allow to send couple textures in once draw call, which in practise means we can batch meshes with different textures. Is it possible in Babylon.js?

OK thanks for clarifications.

Animations of position,scaling and rotation is ok per instance.
Now with the new system, you can also provide other attributes per instance (like color, uvs or even normal). The only caveat is that the value is PER instance not per vertex

1 Like

arg, so one normal for one instance then ?

yep
on one uv. You cannot instantiate per vertex

OOOOOOHHHHH this could be big for me!

does this mean that usually standard instances (with no extra buffer) have each only one normal ? I didn’t notice this.

The normals are per vertex but not instances eg. they are the same per instance but vary per vertex

@Deltakosh this seems to be the exact API I’ve been hoping for, thank you! Opens up a huge realm of possibilities, not just performance wise but creatively as well.

@Greg I believe this is what you are looking for:

https://www.babylonjs-playground.com/#EK6GAC#11

2 Likes

@thrice yes, i was manage to write to something similar but need to somehow solve a problem when your images are trimmed and rotated in spritesheet.