Add lines to the edges of the model

I want to achieve the effect of selecting models with lines on the edges, which is the same as the model selection effect in RealityComposer Pro. Also, when selecting, the axis model can still be seen as the complete axis model in the selected model

Hi @xfck,

There are two main ways of building a selection outline effect in Reality Composer Pro:

  1. Inverted hull. Duplicate the model and give the copy a Shader Graph material that multiplies the vertex Normal by a width parameter and connects it to the Model Position Offset input of a Geometry Modifier. This pushes the vertices of the duplicated model outward along their normal directions. Then, use an Unlit Surface to get a uniform outline color, and set the material's Face Culling to Front. With this approach, only the inside of the enlarged duplicate model is visible, so it appears as a solid border/outline around the original model. Note that this approach can lead to artifacts for model with hard edges (such as a cube).

  2. Fresnel rim. In the model's own material, take the Dot Product of View Direction and Normal, then Clamp it between 0.0 and 1.0, take One Minus, and raise it to a falloff exponent with Power. Multiply by an outline color and connect the result to the surface's Emissive Color input. This brightens the parts of the surface that face away from the viewer along the edges of the model, and you can tune the falloff exponent to adjust how strong the effect is. This approach works best for smooth, rounded models.

If you're not targeting visionOS, another approach is to write a customPostProcessing effect that finds edges in the rendered frame and colors them to create outlines. At a high-level, this can be achieved by comparing each pixel's depth and/or color with those of its neighbors, and blending the outline color into any pixel where they differ sharply.

To keep the axis gizmo fully visible inside the selected model, set readsDepth to false on each of the gizmo's materials. Then put the gizmo and the model in the same ModelSortGroup, with the gizmo at a higher order, so it draws after the model and always renders on top.

Let me know if you have any further questions!