Jump to content

[SOLVED] How can I control(Enable/Disable) Planar reflection by coding?


photo

Recommended Posts

Hi @shchoe,

Starting from 2.14 planar reflections are implemented via a separate node called Planar Reflection Probe. 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, for example) . The complete list of settings and parameters is available in the Planar Reflection Probe article.

Here is a simple snippet of how you can make it work via C++:

// necessary headers
#include <UniginePrimitives.h>
#include <UnigineObjects.h>
#include <UnigineLights.h>
  
/*...*/

//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
LightPlanarProbePtr planar_probe = LightPlanarProbe::create();
planar_probe->setProjectionSize(Math::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
// to project the reflection onto
planar_probe->setTransform(plane->getTransform());

// inheriting a new material from the one assigned
// to the reflecting surface by default in order to tweak it
// and set metalness and roughness values (metallic and polished)
MaterialPtr 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->setVisibleDistance(5.0f);

You can also change other parameters of the probe via API: for the list of available methods please refer to the  LightPlanarProbe class article. I'll add a Usage Example to the article in the nearest future.

Thanks!

  • Like 1
Link to comment
  • silent changed the title to [SOLVED] How can I control(Enable/Disable) Planar reflection by coding?
×
×
  • Create New...