EntityPlanarReflection entity[,reflection]

Parameters

entity - rigid planar mesh or CreatePlane receiver

reflection (optional) - compatible managed handle from CreatePlanarReflection; 0 removes this entity's association (default)

Description

Supplies a captured reflected view to an entity's existing compatible material.

Assign the planar-reflection or water built-in first, then associate its receiver. EntityShader and surface/brush shader precedence remain unchanged. This command does not choose or replace the material.

Entity, source camera and plane must belong to the same world. Each receiver has one association; multiple coplanar receivers may share a handle. It contributes only in that handle's source camera. Other cameras and nested reflection views use the receiver's fallback.

Every mesh vertex, including each static LOD, must lie on the declared plane. The mesh tolerance is the larger of .001 scene units and .0001 times its world bounding-box diagonal. CreatePlane receivers must have matching orientation and an offset within .001 units. Skinned, morphed and curved receivers are unsupported. Move the declared plane and receiver together; invalid later geometry is diagnosed and cannot consume a stale capture. Reflected scene objects may still be skinned or non-planar.

Water normal maps may distort reflection lookup without bending the actual plane. Its existing WaveScale, WaveSpeed, colours, foam and transmission remain useful. Removing the association restores the ordinary water reflection path. Associated receivers exclude an additional SSR contribution while retaining their depth, normals and motion; no roughness setting is silently changed.

For parameters and worked scenes, see the shader parameter reference and the illustrated reflection study.


See also: CreatePlanarReflection, PlanarReflectionSettings, PlanarReflectionEnabled, FreePlanarReflection, EntityShader.

Example

; EntityPlanarReflection Example
; ------------------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,3,2.7,-7

light=CreateLight()
RotateEntity light,35,-25,0

AmbientLight 65,65,65

; An invisible pivot declares the mirror plane (local +Y faces the camera)
plane=CreatePivot()
PositionEntity plane,0,1.8,3
RotateEntity plane,-90,0,0
PointEntity camera,plane

; A finite mirror quad lying on that plane
mirror=CreateMesh()
surface=CreateSurface(mirror)
AddVertex surface,-2,0,-1.5,0,0
AddVertex surface,2,0,-1.5,1,0
AddVertex surface,2,0,1.5,1,1
AddVertex surface,-2,0,1.5,0,1
AddTriangle surface,0,3,1
AddTriangle surface,1,3,2
UpdateNormals mirror
PositionEntity mirror,0,1.8,3
RotateEntity mirror,-90,0,0

; Assign the receiver material first; association supplies the view
material=LoadShader("builtin:planar-reflection")
ShaderColor material,"FallbackColor",35,65,80
EntityShader mirror,material

reflection=CreatePlanarReflection(camera,plane)
EntityPlanarReflection mirror,reflection

; A marker to watch in the mirror
marker=CreateCone(16)
ScaleEntity marker,0.55,1.2,0.55
PositionEntity marker,-1.4,1,-4
EntityColor marker,240,160,35
arm=CreateCylinder(12,True,marker)
ScaleEntity arm,0.12,0.9,0.12
RotateEntity arm,0,0,90
PositionEntity arm,0.7,0.4,0
EntityColor arm,50,170,190

floor=CreatePlane()
PositionEntity floor,0,-0.3,0
EntityColor floor,40,50,65

attached=True

While Not KeyDown(1)

    TurnEntity marker,0,1,0

    ; Space attaches or detaches the receiver; detached shows the fallback
    If KeyHit(57)
        attached=Not attached
        If attached Then EntityPlanarReflection mirror,reflection Else EntityPlanarReflection mirror,0
    EndIf

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    Text 0,0,"Arrow keys: move camera   Space: attach/detach   Esc: exit"
    Text 0,20,"EntityPlanarReflection mirror association: "+attached

    Flip

Wend

FreePlanarReflection reflection
FreeShader material

End

Index