How do instances / draw calls work? How are they drawn to a RenderTargetTexture?

So I have a PG,

What I’m doing here,

  • Spawning several instances
  • Making a RenderTargetTexture
  • Adding just 1 instance to the renderlist of the RTT
  • masking whatever’s drawn on the RTT with yellow

Since instances are supposed to share a draw call, it’s supposed to be a draw 1, draw all kinda deal yeah?

but that doesn’t seem to be the case. only the chosen mesh gets highlighted.

but the sceneInstrumentation disagrees and reports only 4 (not 40 as with clones) draw calls.

what’s weird is if I do scene.freezeActiveMeshes() (press p), now all of them DO get highlighted together.

I’m confused as to what’s going on, can anyone please help me make sense of this?

1 Like

@sebavan, @Evgeni_Popov, @Cedric - any thoughts here?

1 Like

You have:

  • 1 draw call to render in the RTT
  • 1 draw call to render the “mask” post process in the RTT
  • 1 draw call to render the main scene
  • 1 draw call to render the GUI

Total: 4 draw calls

The problem when freezing active meshes is that when freezeActiveMeshes() is called, the list of active meshes are calculated and set aside. For instanced meshes, all the instances currently active are taken into account, and even if a single instance is pushed into the RTT’s renderList, all instances are drawn because of this.

One way to overcome the problem would be to create a clone instead of an instance for the mesh you’re pushing into renderList

3 Likes

so I’m more confused in how I was able to draw a singular instance on the RTT in the 1st place.

Why did all of them not get drawn together before freezeActiveMeshes

I was assuming instances always have to be drawn together, you can’t just have 1?

but I get it now it’s like setting isVisible on an instance, all of this isn’t set in stone until it’s sent to render and we can decide what instances to send in that 1 draw call

Thank you soo much for the detailed breakdown : D

When meshes are not frozen, the list of meshes are recomputed in each cases, that is for the RTT and for the regular scene rendering. When meshes are frozen, the list is generated a single time and reused “as is” in all cases.

1 Like

got it! tysmm :smiley: