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
Add lines to the edges of the model
Hi @xfck,
There are two main ways of building a selection outline effect in Reality Composer Pro:
-
Inverted hull. Duplicate the model and give the copy a Shader Graph material that multiplies the vertex
Normalby a width parameter and connects it to theModel Position Offsetinput of aGeometry Modifier. This pushes the vertices of the duplicated model outward along their normal directions. Then, use anUnlit Surfaceto get a uniform outline color, and set the material'sFace CullingtoFront. 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). -
Fresnel rim. In the model's own material, take the
Dot ProductofView DirectionandNormal, thenClampit between0.0and1.0, takeOne Minus, and raise it to a falloff exponent withPower. Multiply by an outline color and connect the result to the surface'sEmissive Colorinput. 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!