LightsprintSDK 2021.08.08
rr_gl::Renderer Class Referenceabstract

#include <Renderer.h>

Inheritance diagram for rr_gl::Renderer:
rr::RRUniformlyAllocatedNonCopyable rr::RRUniformlyAllocated

Public Member Functions

virtual void render (const class PluginParams *pp, const struct PluginParamsShared &sp)=0
 
virtual TextureRenderergetTextureRenderer ()=0
 
virtual class RendererOfMesh * getMeshRenderer (const rr::RRMesh *mesh)=0
 
virtual class NamedCountergetCounters ()=0
 
virtual ~Renderer ()
 
- 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)
 

Static Public Member Functions

static Renderercreate (const rr::RRString &pathToShaders, const rr::RRString &pathToMaps)
 

Additional Inherited Members

- Protected Member Functions inherited from rr::RRUniformlyAllocatedNonCopyable
 RRUniformlyAllocatedNonCopyable ()
 
 ~RRUniformlyAllocatedNonCopyable ()
 

Detailed Description

Modern plugin based renderer.

Renderer itself does not issue any rendering commands, it just calls plugins. Plugins can directly render and/or recursively call renderer with modified set of plugins or parameters. You can easily add custom plugins to add functionality. For a complete list of our plugins, see PluginParams.

Plugin capabilities
With our plugins, you can render

  • realtime global illumination from lights, emissive materials, sky, custom sources
  • unlimited number of realtime lights
  • linear and area spotlights with realtime penumbra shadows
  • sky: cubemap, cross, equirectangular, HDR, LDR, blending
  • effects: SSGI, DOF, tone mapping, bloom, lens flare etc
  • stereo: side-by-side, top-down, interlaced
  • panorama: equirectangular, little planet
  • separately enabled/disabled light features:
    • color
    • projected texture
    • polynomial, exponential, none or physically correct distance attenuation models
    • shadows with variable softness, resolution, automatically cascaded in outdoor
  • separately enabled/disabled material features:
    • diffuse reflection: none, constant, per vertex, per pixel
    • specular reflection: none, constant, per vertex, per pixel
    • emission: none, constant, per pixel
    • transparency: none, constant, per pixel / blend or 1bit alpha keying
    • bump: normal map, height map with parallax mapping

Plugin requirements
Minimal requirements for existing plugins: OpenGL 2.0 or OpenGL ES 2.0. 3.x and 4.x functions are used when available, for higher quality and speed.

How plugins call each other
Each plugin is expected to call next plugin in chain at some point, but it is free to decide when to call it, how many times to call it, and what plugin parameters to modify. So for example

  • PluginBloom is pretty simple, it calls next plugin first, then applies bloom postprocess.
  • PluginScene calls next plugin after rendering opaque faces, but before rendering transparent faces.
  • PluginStereo calls next plugin once for left eye, once for right eye.
  • PluginCube calls next plugin 6 times, once for each side of given cubemap.

Plugin order
When creating plugin chain, you are free to change order of plugins to create various effects. If not sure, use this order of standard plugins:

Using plugins
Example of calling renderer with plugin chain (see samples for complete code):

// declare first plugin in chain, to render skybox on background
PluginParamsSky ppSky(nullptr,solver);
// declare second plugin, to render objects over background
PluginParamsScene ppScene(&ppSky,solver);
ppScene.foo = bar; // (set additional parameters)
// declare third plugin, to add SSGI postprocess on top
PluginParamsSSGI ppSSGI(&ppScene,1,0.3f,0.1f);
// declare parameters shared by all plugins
ppShared.foo = bar; // (set additional parameters)
// here we just run the last plugins in chain to do its work (third plugin calls second plugin etc)
solver->getRenderer()->render(&ppSSGI,ppShared);
Adds screen space global illumination effect on top of scene render (next plugin).
Definition PluginSSGI.h:40
Renders scene, set of objects and lights.
Definition PluginScene.h:31
Renders background or blend of backgrounds as they are set in given solver.
Definition PluginSky.h:25
Parameters shared by all plugins.
Definition Plugin.h:61

Creating plugins
Creating new plugins is easy as well. Plugins contain virtually no boilerplate code, they are just constructor, render() function and destructor. For source code licensee, it is recommended to take source code of one of plugins and modify it.

Constructor & Destructor Documentation

◆ ~Renderer()

virtual rr_gl::Renderer::~Renderer ( )
inlinevirtual

Member Function Documentation

◆ create()

static Renderer * rr_gl::Renderer::create ( const rr::RRString pathToShaders,
const rr::RRString pathToMaps 
)
static

Creates renderer.

Parameters
pathToShadersPath to directory with shaders. It is passed to plugins later, renderer itself does not use it. Must be terminated with slash (or be empty for current dir).
pathToMapsPath to directory with maps. It is passed to plugins later, renderer itself does not use it. Must be terminated with slash (or be empty for current dir).

◆ render()

virtual void rr_gl::Renderer::render ( const class PluginParams pp,
const struct PluginParamsShared sp 
)
pure virtual

Runs given plugins to do their work.

Existing plugins (all but PluginCube) render into current render target and current viewport.

Existing plugins do not clear automatically, so you might want to glClear() both color and depth before calling render().

To render to texture, set render target with FBO::setRenderTarget(). When rendering sRGB correctly, target texture must be sRGB, make it sRGB with Texture::reset(,,true) before FBO::setRenderTarget().

For correct results with existing plugins, render target must contain at least depth and RGB channels. When rendering with mirror reflections, render target must contain also alpha channel. Stencil buffer is not used.

To render to rectangle within render target, use glViewport(). (Note that when rendering with nondefault viewport, mirrors and mono camera, render target's alpha channel is cleared by glClear(). If you don't want it to be cleared outside viewport, enable scissor test with scissor area identical to viewport.)

◆ getTextureRenderer()

virtual TextureRenderer * rr_gl::Renderer::getTextureRenderer ( )
pure virtual

Helper function, provides plugins with single preallocated texture renderer.

◆ getMeshRenderer()

virtual class RendererOfMesh * rr_gl::Renderer::getMeshRenderer ( const rr::RRMesh mesh)
pure virtual

Helper function, for internal use.

◆ getCounters()

virtual class NamedCounter * rr_gl::Renderer::getCounters ( )
pure virtual

Returns named counters exposed by plugins. You can freely modify counts, e.g. zero them at the beginning of frame.