LightsprintSDK 2021.08.08
rr_gl::RealtimeLight Class Reference

#include <RealtimeLight.h>

Public Types

enum  AreaType {
  LINE ,
  CIRCLE ,
  RECTANGLE
}
 
enum  ShadowTransparency {
  FULLY_OPAQUE_SHADOWS ,
  ALPHA_KEYED_SHADOWS ,
  RGB_SHADOWS ,
  FRESNEL_SHADOWS
}
 

Public Member Functions

 RealtimeLight (rr::RRLight &rrlight)
 
virtual ~RealtimeLight ()
 
rr::RRLightgetRRLight ()
 
const rr::RRLightgetRRLight () const
 
void updateAfterRRLightChanges ()
 
rr::RRCameragetCamera () const
 
void setCamera (rr::RRCamera *camera)
 
virtual unsigned getNumShadowmaps (bool color=false) const
 
void configureCSM (const rr::RRCamera *observer, const class rr::RRSolver *solver)
 
rr::RRVec3 getObserverPos () const
 
virtual rr::RRCameragetShadowmapCamera (unsigned instance, rr::RRCamera &out) const
 
void setShadowmapSize (unsigned newSize)
 
TexturegetShadowmap (unsigned instance, bool color=false)
 
void setNumShadowSamples (unsigned numSamples)
 
unsigned getNumShadowSamples () const
 
unsigned getNumShadowSamples (unsigned instance) const
 
void setRangeDynamically (const rr::RRCollider *collider, const rr::RRObject *object, unsigned numRays=0)
 
const TexturegetProjectedTexture ()
 

Public Attributes

bool shadowOnly
 
AreaType areaType
 
float areaSize
 
ShadowTransparency shadowTransparencyRequested
 
ShadowTransparency shadowTransparencyActual
 
bool oneSidedShadows
 
unsigned * smallMapCPU
 
unsigned numTriangles
 
bool dirtyShadowmap
 
bool dirtyGI
 
bool dirtyRange
 
rr::RRVec3 positionOfLastDDI
 
bool changesInProjectedTextureAffectGI
 
unsigned numInstancesInArea
 

Protected Attributes

rr::RRLightrrlight
 
rr::RRVec3 csmObserverPos
 
rr::RRVec3 csmObserverDir
 
float csmObserverNear
 
rr::RRVec3 csmSceneSize
 
rr::RRCameracamera
 
bool deleteCamera
 
rr::RRVector< Texture * > shadowmaps [2]
 
unsigned numSoftShadowSamples
 

Detailed Description

Runtime extension of RRLight, with structures needed for realtime GI rendering (shadowmaps etc).

Member Enumeration Documentation

◆ AreaType

Shapes of light source area, relevant only for SPOT.

Enumerator
LINE 

n instances in line, spot/dir-light with penumbra shadows. Approx 1m long line, it simulates light coming from long narrow lightsource.

CIRCLE 

n instances in circle, spot/dir-light with penumbra shadows. Circle, it simulates light coming from circle (border).

RECTANGLE 

n instances in rectangle, spot/dir-light with penumbra shadows. Approx 1m*1m square grid, it simulates light coming from whole square. It needs more instances to prevent shadow banding.

◆ ShadowTransparency

Specifies how shadows of transparent materials are created (in realtime renderer), whether quickly, or more accurately.

Enumerator
FULLY_OPAQUE_SHADOWS 

The fastest, fully opaque shadows, light is completely blocked, material properties are ignored.

ALPHA_KEYED_SHADOWS 

Fast alpha keyed shadows, light goes through or is stopped according to material, this is evaluated per-pixel.

RGB_SHADOWS 

Realistic colored shadows from semi-translucent materials (if specularTransmittance is red, only red light goes through), this is evaluated per-pixel.

FRESNEL_SHADOWS 

The most realistic shadows, with normal maps and Fresnel term applied to increase occlusion depending on index of refraction. It goes half way towards caustics, as light intensity is modulated, but light direction is not. For refractionIndex 1, result is identical to RGB_SHADOWS.

Constructor & Destructor Documentation

◆ RealtimeLight()

rr_gl::RealtimeLight::RealtimeLight ( rr::RRLight rrlight)

Extends RRLight, adding properties and functions for realtime rendering.

RRLight must exist at least as long as realtime light. RRLight position/direction is updated each time this->getCamera()->update() is called.

◆ ~RealtimeLight()

virtual rr_gl::RealtimeLight::~RealtimeLight ( )
virtual

Member Function Documentation

◆ getRRLight() [1/2]

rr::RRLight & rr_gl::RealtimeLight::getRRLight ( )
inline

Returns our RRLight with standard light properties like color. It's legal to edit RRLight properties at any moment as long as you call updateAfterRRLightChanges() later.

◆ getRRLight() [2/2]

const rr::RRLight & rr_gl::RealtimeLight::getRRLight ( ) const
inline

Returns our RRLight with standard light properties like color.

◆ updateAfterRRLightChanges()

void rr_gl::RealtimeLight::updateAfterRRLightChanges ( )

Propagates changes from RRLight (position,direction etc) to RealtimeLight and its camera. Note that changes in the opposite direction (from camera to RRLight) are propagated automatically.

◆ getCamera()

rr::RRCamera * rr_gl::RealtimeLight::getCamera ( ) const

Returns camera you can use to control light's position, direction etc. Changes made to this camera are automatically propagated to original RRLight.

◆ setCamera()

void rr_gl::RealtimeLight::setCamera ( rr::RRCamera camera)

Assigns new camera to this light.

Ownership is not passed. Should not be used in new programs.

◆ getNumShadowmaps()

virtual unsigned rr_gl::RealtimeLight::getNumShadowmaps ( bool  color = false) const
virtual

Returns number of shadowmaps (depth maps or color maps).

◆ configureCSM()

void rr_gl::RealtimeLight::configureCSM ( const rr::RRCamera observer,
const class rr::RRSolver solver 
)

Provides light with data necessary for CSM calculations in getShadowmapCamera().

◆ getObserverPos()

rr::RRVec3 rr_gl::RealtimeLight::getObserverPos ( ) const

Returns position of observer from previous configureCSM() call.

◆ getShadowmapCamera()

virtual rr::RRCamera & rr_gl::RealtimeLight::getShadowmapCamera ( unsigned  instance,
rr::RRCamera out 
) const
virtual

Copies camera for n-th shadowmap into out and returns it.

◆ setShadowmapSize()

void rr_gl::RealtimeLight::setShadowmapSize ( unsigned  newSize)

Sets shadowmap resolution.

This is shortcut for setting rrlight.rtShadowmapSize and dirtyShadowmap. Set higher resolution for hard and sharper shadows, set lower resolution for area and more blurry shadows.

◆ getShadowmap()

Texture * rr_gl::RealtimeLight::getShadowmap ( unsigned  instance,
bool  color = false 
)

Returns shadowmap (depth or color) for given light instance (element of area light).

◆ setNumShadowSamples()

void rr_gl::RealtimeLight::setNumShadowSamples ( unsigned  numSamples)

Recommends number of shadow samples for given light. Valid numbers 1,2,4,8. In case of dirlight, this is number of samples close to camera.

◆ getNumShadowSamples() [1/2]

unsigned rr_gl::RealtimeLight::getNumShadowSamples ( ) const

Returns recommended number of shadow samples. In case of dirlight, this is number of samples close to camera.

◆ getNumShadowSamples() [2/2]

unsigned rr_gl::RealtimeLight::getNumShadowSamples ( unsigned  instance) const

Returns recommended number of shadow samples for given light instance.

◆ setRangeDynamically()

void rr_gl::RealtimeLight::setRangeDynamically ( const rr::RRCollider collider,
const rr::RRObject object,
unsigned  numRays = 0 
)

Sets near and far to cover scene visible by light, but not much more.

Uses raycasting, performance hit for one light is acceptable even if called once per frame; but it could be too much when called for many lights in every frame.

Does nothing if RRLight::rtShadowmapAutomaticNearFar is not set.

Instead of directly calling setRangeDynamically(), you can set dirtyRange, solver will call setRangeDynamically() automatically before updating shadowmaps. This way you avoid calling setRangeDynamically() twice if different parts of code request update.

Parameters
colliderCollider to be used for distance testing.
objectObject to be used for material testing, may be nullptr.
numRaysHow many rays it shoots to measure distances. Higher = more accurate, but slower. 0 for defaults (around 300 for pointlight, 100 for spotlight).

◆ getProjectedTexture()

const Texture * rr_gl::RealtimeLight::getProjectedTexture ( )

Returns texture projected by spotlight.

Member Data Documentation

◆ shadowOnly

bool rr_gl::RealtimeLight::shadowOnly

Renders only shadows, no illumination. This is useful for simulating indirect shadows. Works only in presence of indirect illumination, shadows are subtracted from indirect illumination. When rendering with multiple lights, works only in first light.

◆ areaType

AreaType rr_gl::RealtimeLight::areaType

Shape of light source area.

Area light is simulated by multiple spot lights. Types of area are implemented in virtual getShadowmapCamera().

◆ areaSize

float rr_gl::RealtimeLight::areaSize

Size factor, light source size scales linearly with areaSize.

◆ shadowTransparencyRequested

ShadowTransparency rr_gl::RealtimeLight::shadowTransparencyRequested

Requested shadow transparency mode. It defaults to the highest quality mode, you can change it freely to reduce quality and increase speed. Renderer is still allowed to use lower(simpler) transparency modes for materials that need it, but not higher. If you set unnecessarily high mode, there's no performance penalty, renderer detects it and uses lower mode (see shadowTransparencyActual).

◆ shadowTransparencyActual

ShadowTransparency rr_gl::RealtimeLight::shadowTransparencyActual

Actual shadow transparency mode. For reading only, set by RRSolverGL::updateShadowmaps().

◆ oneSidedShadows

bool rr_gl::RealtimeLight::oneSidedShadows

Default twosided shadows are nearly always better, this option exists only to make Lightsmark renders like in 2007/8.

◆ smallMapCPU

unsigned* rr_gl::RealtimeLight::smallMapCPU

Helper for GI calculation, used by RRSolverGL.

◆ numTriangles

unsigned rr_gl::RealtimeLight::numTriangles

Helper for GI calculation, used by RRSolverGL.

◆ dirtyShadowmap

bool rr_gl::RealtimeLight::dirtyShadowmap

Whether shadowmap needs update.

Set by RRSolverGL::reportDirectIlluminationChange() or manually, cleared by RRSolverGL::calculate() (unless light or shadow casting is disabled).

◆ dirtyGI

bool rr_gl::RealtimeLight::dirtyGI

◆ dirtyRange

bool rr_gl::RealtimeLight::dirtyRange

Whether shadowmap near/far range needs update.

Set by RRSolverGL::reportDirectIlluminationChange(), cleared by RRSolverGL::calculate() or setRangeDynamically(). Range should be wide enough to not clip visible geometry, but not wider, becuase it increases shadow bias and makes distant triangles z-fight. You can set range manually or just set dirtyRange and we will recalculate range automatically.

◆ positionOfLastDDI

rr::RRVec3 rr_gl::RealtimeLight::positionOfLastDDI

Eye position when direct lighting was detected. Only for directional light.

◆ changesInProjectedTextureAffectGI

bool rr_gl::RealtimeLight::changesInProjectedTextureAffectGI

True = each time projected texture content changes, GI is updated. For higher performance, clear it if you know that changes have small effect on GI. Even if cleared, you can still set dirtyGI manually on big changes.

◆ numInstancesInArea

unsigned rr_gl::RealtimeLight::numInstancesInArea

Number of instances approximating area light. Used only for SPOT, 1 = standard spot, more = area light.

◆ rrlight

rr::RRLight& rr_gl::RealtimeLight::rrlight
protected

RRLight used at our creation, contains standard light properties like color.

◆ csmObserverPos

rr::RRVec3 rr_gl::RealtimeLight::csmObserverPos
protected

◆ csmObserverDir

rr::RRVec3 rr_gl::RealtimeLight::csmObserverDir
protected

◆ csmObserverNear

float rr_gl::RealtimeLight::csmObserverNear
protected

◆ csmSceneSize

rr::RRVec3 rr_gl::RealtimeLight::csmSceneSize
protected

◆ camera

rr::RRCamera* rr_gl::RealtimeLight::camera
protected

◆ deleteCamera

bool rr_gl::RealtimeLight::deleteCamera
protected

◆ shadowmaps

rr::RRVector<Texture*> rr_gl::RealtimeLight::shadowmaps[2]
protected

◆ numSoftShadowSamples

unsigned rr_gl::RealtimeLight::numSoftShadowSamples
protected

Number of samples in soft shadows, defaults to 4, you may change it to 1,2,8.

Vectors of depth and color shadow maps. Sizes of vectors are updated lazily, only when map is requested and actual number of maps doesn't match.