Unigine.LightPlanarProbe Class
Inherits from: | Light |
This class is used to create and manage Planar Reflection Probes the implement planar reflections functionality (used to create mirrors etc.). The probe grabs the reflection, and requires a surface to project the reflection onto. There is a set of parameters enabling you to tweak the look of your reflections and optimize rendering load (by limiting visibility distance, reflections rendering distance, etc.).
Usage Example#
In the example below a Planar Reflection Probe is created along with a plane primitive. The surface of the primitive serves for projecting the reflection grabbed by the probe (the reflection is projected only within the area of intersection of the probe and the surface). Some parameters of the material assigned to the reflecting surface are also tweaked in order to provide the desired effect and match roughness range (which enables rendering of reflections depending on surface roughness).
Copy the source code below implemented as a C# component, save it to the PlanarReflector.cs file, create a new Dummy Node or choose any other node in the scene and assign the component to it.
// PlanarReflector.cs
using System;
using System.Collections;
using System.Collections.Generic;
using Unigine;
[Component(PropertyGuid = "")] //<--- guid is autogenerated on component creation
public class PlanarReflector : Component
{
private ObjectMeshDynamic plane;
private LightPlanarProbe planar_probe;
private void Init()
{
// write here code to be called on component initialization
//creating a reflecting plane, onto which the reflection is to be projected by the probe
plane = Primitives.CreatePlane(20, 20, 1);
// Creating a planar reflection probe of the same size
planar_probe = new LightPlanarProbe();
planar_probe.ProjectionSize = new vec3(20, 20, 1);
plane.Rotate(-90.0f, 0.0f, 0.0f);
plane.Translate(0.0f, 5.0f, 5.0f);
// putting the planar probe so that it covers the reflecting surface
planar_probe.Transform = plane.Transform;
// inheriting a new material from the one assigned
// to the surface by default in order to tweak it
// and set metalness and roughness values (metallic and polished)
Material plane_mat = plane.GetMaterialInherit(0);
plane_mat.SetParameterFloat("metalness", 1.0f);
plane_mat.SetParameterFloat("roughness", 0.0f);
// set the distance from the camera, up to which
// the planar reflection will be visible
planar_probe.VisibleDistance = 5.0f;
}
private void Update()
{
// write here code to be called before updating each render frame
}
}