LightsprintSDK 2021.08.08
rr_gl::RRSolverGL Class Reference

#include <RRSolverGL.h>

Inheritance diagram for rr_gl::RRSolverGL:
rr::RRSolver rr::RRUniformlyAllocatedNonCopyable rr::RRUniformlyAllocated

Public Types

enum  DDIQuality {
  DDI_AUTO ,
  DDI_4X4 ,
  DDI_8X8
}
 
- Public Types inherited from rr::RRSolver
enum  InternalSolverType {
  NONE ,
  ARCHITECT ,
  FIREBALL ,
  BOTH
}
 

Public Member Functions

 RRSolverGL (const rr::RRString &pathToShaders, const rr::RRString &pathToMaps, DDIQuality detectionQuality=DDI_AUTO)
 
virtual ~RRSolverGL ()
 
virtual void setLights (const rr::RRLights &lights) override
 
virtual void renderLights (const rr::RRCamera &_camera)
 
virtual void reportDirectIlluminationChange (int lightIndex, bool dirtyShadowmap, bool dirtyGI, bool dirtyRange) override
 
virtual void calculate (const CalculateParameters *params=nullptr) override
 
virtual unsigned updateEnvironmentMap (rr::RRObjectIllumination *illumination, unsigned layerEnvironment, unsigned layerLightmap, unsigned layerAmbientMap) override
 
UberProgramgetUberProgram ()
 
RenderergetRenderer ()
 
- Public Member Functions inherited from rr::RRSolver
 RRSolver ()
 
virtual ~RRSolver ()
 
virtual void setColorSpace (const RRColorSpace *colorSpace)
 
const RRColorSpacegetColorSpace () const
 
void setEnvironment (RRBuffer *environment0, RRBuffer *environment1=nullptr, RRReal angleRad0=0, RRReal angleRad1=0)
 
RRBuffergetEnvironment (unsigned environmentIndex=0, RRReal *angleRad=nullptr) const
 
void setEnvironmentBlendFactor (float blendFactor)
 
float getEnvironmentBlendFactor () const
 
virtual void setLights (const RRLights &lights)
 
const RRLightsgetLights () const
 
void setDirectIllumination (const unsigned *perTriangleIrradianceRGBA)
 
const unsigned * getDirectIllumination ()
 
virtual void setStaticObjects (const RRObjects &objects, const SmoothingParameters *smoothing, const char *cacheLocation=nullptr, RRCollider::IntersectTechnique intersectTechnique=RRCollider::IT_BVH_FAST, RRSolver *copyFrom=nullptr)
 
const RRObjectsgetStaticObjects () const
 
void setDynamicObjects (const RRObjects &objects)
 
const RRObjectsgetDynamicObjects () const
 
RRObjects getObjects () const
 
RRObjectgetObject (unsigned index) const
 
RRCollidergetCollider () const
 
const RRObjectgetAABB (RRVec3 *_mini, RRVec3 *_maxi, RRVec3 *_center) const
 
void processBuffers (const RRVector< unsigned > *layers, std::function< void(RRBuffer *)> func) const
 
virtual void calculate (const CalculateParameters *params=nullptr)
 
unsigned getSolutionVersion () const
 
virtual unsigned updateLightmap (int objectNumber, RRBuffer *lightmap, RRBuffer *directionalLightmap[3], RRBuffer *bentNormals, const UpdateParameters *params, const FilteringParameters *filtering=nullptr)
 
virtual unsigned updateLightmaps (int layerLightmap, int layerDirectionalLightmap, int layerBentNormals, const UpdateParameters *params, const FilteringParameters *filtering)
 
virtual unsigned updateEnvironmentMap (RRObjectIllumination *illumination, unsigned layerEnvironment, unsigned layerLightmap, unsigned layerAmbientMap)
 
bool getTriangleMeasure (unsigned triangle, unsigned vertex, RRRadiometricMeasure measure, RRVec3 &out) const
 
virtual void reportMaterialChange (bool dirtyShadows, bool dirtyGI)
 
virtual void reportDirectIlluminationChange (int lightIndex, bool dirtyShadows, bool dirtyGI, bool dirtyRange)
 
virtual void reportInteraction ()
 
bool buildFireball (unsigned avgRaysPerTriangle, const RRString &filename)
 
bool loadFireball (const RRString &filename, bool onlyPerfectMatch)
 
void leaveFireball ()
 
InternalSolverType getInternalSolverType () const
 
void checkConsistency ()
 
virtual bool containsLightSource () const
 
virtual bool containsRealtimeGILightSource () const
 
virtual void allocateBuffersForRealtimeGI (int layerLightmap, int layerEnvironment, unsigned diffuseEnvMapSize=4, unsigned specularEnvMapSize=16, unsigned refractEnvMapSize=16, bool allocateNewBuffers=true, bool changeExistingBuffers=true, float specularThreshold=0.2f, float depthThreshold=0.1f) const
 
RRObjectgetMultiObject () const
 
void pathTraceFrame (const RRCamera &camera, RRBuffer *frame, unsigned accumulate, const PathTracingParameters &parameters)
 
- Public Member Functions inherited from rr::RRUniformlyAllocated
void * operator new (std::size_t n)
 
void * operator new[] (std::size_t n)
 
void operator delete (void *p, std::size_t n)
 
void operator delete[] (void *p, std::size_t n)
 

Public Attributes

rr::RRVector< RealtimeLight * > realtimeLights
 
rr::RRCameraobserver
 
- Public Attributes inherited from rr::RRSolver
bool aborting
 

Protected Member Functions

virtual const unsigned * detectDirectIllumination (unsigned delayDDI)
 
- Protected Member Functions inherited from rr::RRSolver
void calculateDirtyLights (const CalculateParameters *params=nullptr)
 
- Protected Member Functions inherited from rr::RRUniformlyAllocatedNonCopyable
 RRUniformlyAllocatedNonCopyable ()
 
 ~RRUniformlyAllocatedNonCopyable ()
 

Detailed Description

Implementation of rr::RRSolver generic GPU operations using OpenGL 2.0.

Before creating solver, make sure OpenGL context already exists, and OpenGL version is at least 2.0.

Member Enumeration Documentation

◆ DDIQuality

Enumerator
DDI_AUTO 
DDI_4X4 
DDI_8X8 

Constructor & Destructor Documentation

◆ RRSolverGL()

rr_gl::RRSolverGL::RRSolverGL ( const rr::RRString pathToShaders,
const rr::RRString pathToMaps,
DDIQuality  detectionQuality = DDI_AUTO 
)

Initializes generic GPU access implemented in RRSolverGL.

Parameters
pathToShadersPath to directory with shaders. Must be terminated with slash (or be empty for current dir). It is also passed to renderer and its plugins.
pathToMapsPath to directory with maps. Must be terminated with slash (or be empty for current dir). It is passed to renderer and its plugins, solver itself doesn't use any maps.
detectionQualitySets quality of our detectDirectIllumination() routine.

◆ ~RRSolverGL()

virtual rr_gl::RRSolverGL::~RRSolverGL ( )
virtual

Member Function Documentation

◆ setLights()

virtual void rr_gl::RRSolverGL::setLights ( const rr::RRLights lights)
overridevirtual

Sets lights used by both realtime and offline renderer.

For realtime rendering, realtimeLights are created based on lights given here.

It is legal to modify light properties after set, but not number of lights. Changes are processed when RealtimeLight::dirtyXxx flag is set. While renderer reads most of light properties from original lights, 'camera' properties like position, direction, fov are taken from realtimeLights.

By default, light's near/far range is autodetected from distance to static objects in solver (to avoid clipping), but if you wish to set range manually, clear RealtimeLight::dirtyRange after setLights() to prevent autodetection and set your own range.

Reimplemented from rr::RRSolver.

◆ renderLights()

virtual void rr_gl::RRSolverGL::renderLights ( const rr::RRCamera _camera)
virtual

Renders scene in solver, with all static and dynamic objects, lights, environment.

Renders wireframe frustums or boxes of lights.

◆ reportDirectIlluminationChange()

virtual void rr_gl::RRSolverGL::reportDirectIlluminationChange ( int  lightIndex,
bool  dirtyShadowmap,
bool  dirtyGI,
bool  dirtyRange 
)
overridevirtual

Sets dirty flags in given light, or in all lights if lightIndex is -1.

Reimplemented from rr::RRSolver.

◆ calculate()

virtual void rr_gl::RRSolverGL::calculate ( const CalculateParameters params = nullptr)
overridevirtual

Updates shadowmaps, detects direct illumination, calculates GI.

Call this function once per frame while rendering realtime shadows or realtime GI. You can call it even when not rendering, to improve GI solution inside solver (so that you have it ready when you render scene later). On the other hand, don't call it when you don't need realtime shadows and realtime GI, for example when rendering offline baked lightmaps, it would still spend time calculating realtime GI even if you don't need it.

It updates illumination from dirty lights only, call reportDirectIlluminationChange() to mark light dirty.
You can update only shadowmaps by setting params->qualityIndirectDynamic=0.

Note that RRSolverGL::calculate() calls setDirectIllumination() automatically. If you want to provide your own direct illumination data, switch from RRSolverGL to rr::RRSolver and call setDirectIllumination() manually before calculate().

Reimplemented from rr::RRSolver.

◆ updateEnvironmentMap()

virtual unsigned rr_gl::RRSolverGL::updateEnvironmentMap ( rr::RRObjectIllumination illumination,
unsigned  layerEnvironment,
unsigned  layerLightmap,
unsigned  layerAmbientMap 
)
overridevirtual

Calculates and updates object's environment map, stored in given layer of given illumination.

Function renders map with LightsprintGL's renderer, honouring all light and material properties, with indirect illumination taken from buffers in layerXxx. If your envmap has low resolution (less than approximately 32x32x6), consider calling RRSolver::updateEnvironmentMap() instead, which is faster.

Reimplemented from rr::RRSolver.

◆ getUberProgram()

UberProgram * rr_gl::RRSolverGL::getUberProgram ( )
inline

Users can reuse our uberprogram for their own rendering.

◆ getRenderer()

Renderer * rr_gl::RRSolverGL::getRenderer ( )
inline

Users can reuse our renderer for their own rendering.

◆ detectDirectIllumination()

virtual const unsigned * rr_gl::RRSolverGL::detectDirectIllumination ( unsigned  delayDDI)
protectedvirtual

Detects direct illumination from lights (see setLights()) on all faces in scene and returns it in array of RGBA values. Result may be immediately passed to setDirectIllumination().

Returns
Pointer to array of detected average per-triangle direct-lighting irradiances in custom scale (= average triangle colors when material is not applied). Values are stored in RGBA8 format. Return nullptr when direct illumination was not detected for any reason, this function will be called again in next calculate().

Member Data Documentation

◆ realtimeLights

rr::RRVector<RealtimeLight*> rr_gl::RRSolverGL::realtimeLights

Realtime lights, set by setLights(). You may modify them freely.

◆ observer

rr::RRCamera* rr_gl::RRSolverGL::observer

Scene observer, inited to nullptr. You may modify it freely. Shadow quality is optimized for observer.