Mirrors
A mirror is an FL# script: a camera made by the script renders the reflection into a texture, and the mirror's shader shows it. The example world has a complete one, PlanarMirror.cs with the shader NodeWorld Example/Mirror: start from it.
Put one in your world
- Import the Example World sample (install the SDK), then copy
Flux/PlanarMirror.csandShaders/Mirror.shaderinto your world's folders: the script into your FL# scripts folder, the shader anywhere inAssets. They are yours to change. - Add
PlanarMirror.csto Flux Sharp Sources of your NW World Config. - Make a Quad: its visible face is the mirror. Give it a material with the shader NodeWorld Example/Mirror.
- On the quad, Add Component, NodeWorld, FL# Script, then Read the scripts and pick
NodeWorldExample.PlanarMirror(or the class name you gave it). - Put a Reflection Probe near the mirror: the shader shows it while the script does not render.
Its fields
| Field | What it does |
|---|---|
maxDistance | The reflection is rendered only while the player stands in front of the mirror, closer than this (8 m), and looks at it. Otherwise the mirror shows the reflection probe, and costs nothing. |
resolution | The width of the reflection, in pixels (1024). Lower it for a small mirror or for Quest. |
layers | The layers the reflection shows (all of them). |
showLocalPlayerHead | The player sees their own head in it (on). |
In VR the script renders one image per eye, so the reflection has depth.
A mirror of the players only
Set layers to the two layers of the players' avatars: 384, that is 1 << 7 (LocalPlayer, your avatar) plus 1 << 8 (RemotePlayer, the others). The reflection then shows only the avatars, over the sky (a new camera's clearFlags); to clear to a color instead, set clearFlags and backgroundColor on the script's camera (cameras). See layers.
Cost
Each mirror in view renders the scene again, once per eye in VR. Keep few mirrors in the same place, keep maxDistance short, and lower resolution on Quest: the script can read World.isMobile (Quest).
The script runs only on the players' games ([ClientOnly]): a mirror is never on the server.
