highlightlayer.addMesh doubles indices, faces and draw calls

Heyho!

I experimented with the highlight layer: On mouse over/click the mesh is added once to the highlight layer. Worked as intended. But i noticed a drop in performance, so i investigated. Somehow, as soon as a mesh is added to the highlight layer, the draw calls, active faces and active indices are doubled. In my project the jump for adding a single mesh to the highlight layer was from 1260 active indices to 2520, from 420 active faces to 840 and from 27 draw calls to 57 draw calls.

Example playground for the highlight layer from the docs: https://playground.babylonjs.com/#1KUJ0A#305

Comment out line 20 & 21:
7800 active indices, 2600 active faces, 3 draw calls

Comment in line 20:
15600 active indices, 5200 active faces, 11 draw calls

Is this a bug or a feature? If that is the way, it works, i’d have had expected a hint in the documentation, that using highlight layers could lead to performance drops.

Thanks in advance :slight_smile:

it due to how such effects are achieved , not a bug. geometry doubled and normals inverted is common for outline effects. So for verts and indices and triangles , double can be expected , i dont know why draw calls are doubled , i think it should not be like that.

It is possible to do this in a shader , Ive done it before many years back using Unity engine. But that is for simple outlines, not a glowing outline. For the glowing a post process would probably still be required , and for that it does need to do another pass?

So basically im saying , there will always be a performance increase when adding an effect like this in some manner or another.

I have not personally looked at how babylon is handling this. Better to have someone more clued up give details. I do know they have the more performant version of it enabled by default ( overlapping highlights cancel those beneath ) and to not have that it will become even more expensive to render

1 Like

Yep there’s not much way around it than do another pass :slight_smile: You can see how the highlight is constructed using Spector Spector.js – Get this Extension for :fox_face: Firefox (en-US) (mozilla.org)

highlight-layer-spector

Okay, thanks for your answers and time. I expected some performance drops, because, as you already said, it is an expensive operation. But i wasn’t expecting the doubled draw calls. A few, yes, but not doubled.

They are doubled but on a way smaller RenderTarget relying on mainly only 2 variants of a shader so it should not end up being that bad.

Rendering with draw buffers would enforce the same Target size being potentially less effeicient than double the draw calls GPU wise.