Unsure of correct approach to apply outline shader

I have a shaderMaterial that uses the inverse hull method to create an outline around some objects. Now I want to apply this shader to a gltf object with a whole bunch of meshes. However, I only want to outline the entire object and not the individual children. How exactly can I achieve this?

Can you merge them all into a single mesh that is only used for outline? BufferGeometryUtils.mergeGeometries()

I think that would be hard since the model has a lot of different materials and textures. Is there a way to preserve these materials when merging the geometries?

I’m thinking you would only use this merged geometry to feed the outline effect, but use the non-merged as it is normally.

You’d have to somehow prevent the merged one from rendering normally… perhaps by setting it invisible or something. I don’t know how your outline logic is set up…

I would just like to give a little word of caution for that approach, as I have done something similar when I wanted a shadow effect when the character was behind a wall, so I duplicated the model, and used another material with a high render order and depthTest = false. However, this doubles the number of triangles for the model, which can add up quickly. Depending on your use case, this might not be a problem, but might be good to keep in mind.

How did you solve the problem without making a merged geometry?

I didn’t. I think your approach is reasonable, and probably necessary, just wanted to point out to the OP that you will double the triangle count of the model, doing that.

1 Like

Yeah for sure. Good point.
And merging them at selection time would probably be terribly slow… so you really would want/need to precompute the merged versions of all your selectable things beforehand at init time.