Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
PathTracer Class Reference

Unidirectional path tracer. Generates renderings of a scene by emitting rays from the user viewpoint and letting them bounce in the scene, forming paths. Lighting and materials contributions are accumulated along each path to compute the color of the associated sample. More...

#include <PathTracer.hpp>

Public Member Functions

 PathTracer ()=default
 
 PathTracer (const std::shared_ptr< Scene > &scene)
 
void render (const Camera &camera, size_t samples, size_t depth, Image &render)
 
const Raycasterraycaster () const
 

Private Member Functions

bool checkVisibility (const glm::vec3 &startPos, const glm::vec3 &rayDir, float maxDist) const
 
glm::vec3 evalBackground (const glm::vec3 &rayDir, const glm::vec3 &rayPos, const glm::vec2 &ndcPos, bool directHit) const
 

Static Private Member Functions

static glm::ivec2 getSampleGrid (size_t samples)
 
static glm::vec2 getSamplePosition (size_t sid, const glm::ivec2 &cellCount, const glm::vec2 &cellSize)
 
static glm::mat3 buildLocalFrame (const Object &obj, const Raycaster::Hit &hit, const glm::vec3 &rayDir, const glm::vec2 &uv)
 

Private Attributes

Raycaster _raycaster
 The internal raycaster.
 
std::shared_ptr< Scene_scene
 The scene.
 

Detailed Description

Unidirectional path tracer. Generates renderings of a scene by emitting rays from the user viewpoint and letting them bounce in the scene, forming paths. Lighting and materials contributions are accumulated along each path to compute the color of the associated sample.

Constructor & Destructor Documentation

◆ PathTracer() [1/2]

PathTracer::PathTracer ( )
default

Empty constructor.

◆ PathTracer() [2/2]

PathTracer::PathTracer ( const std::shared_ptr< Scene > &  scene)
explicit

Constructor. Initializes the internal raycaster with the scene data.

Parameters
scenethe scene to path trace against

Member Function Documentation

◆ buildLocalFrame()

glm::mat3 PathTracer::buildLocalFrame ( const Object obj,
const Raycaster::Hit hit,
const glm::vec3 &  rayDir,
const glm::vec2 &  uv 
)
staticprivate

Build the local frame at an intersection on an object surface.

Parameters
objthe intersected object
hitthe intersection record
rayDirthe direction of the ray that intersected
uvthe local texture coordinates (if valid)
Returns
the local tangent space frame. \

◆ checkVisibility()

bool PathTracer::checkVisibility ( const glm::vec3 &  startPos,
const glm::vec3 &  rayDir,
float  maxDist 
) const
private

Check visibility from a point along a ray in the scene, taking into account object opacity masks.

Parameters
startPosthe point to test visibility for
rayDirthe ray direction to follow
maxDistthe maximum distance to travel along the ray
Returns
true if the point has clear visibility along the ray

◆ evalBackground()

glm::vec3 PathTracer::evalBackground ( const glm::vec3 &  rayDir,
const glm::vec3 &  rayPos,
const glm::vec2 &  ndcPos,
bool  directHit 
) const
private

Evalutation the contribution from the scene background.

Parameters
rayDirthe direction of the ray that intersected
rayPosthe ray world space position
ndcPosthe current pixel in the final image
directHitwas it a direct hit or a hit after bounces
Returns
the background contribution

◆ getSampleGrid()

glm::ivec2 PathTracer::getSampleGrid ( size_t  samples)
staticprivate

Compute the dimensions of a grid that contains a given number of samples.

Parameters
samplesthe number of samples to place on a regular grid
Returns
the number of samples on each axis

◆ getSamplePosition()

glm::vec2 PathTracer::getSamplePosition ( size_t  sid,
const glm::ivec2 &  cellCount,
const glm::vec2 &  cellSize 
)
staticprivate

Get the local location of a sample in a pixel.

Parameters
sidthe sample ID for the pixel
cellCountthe number of samples on each grid axis
cellSizethe spacing between two samples on an axis
Returns
the local sample location in [0,1]
Note
The sample will be randomly jittered.

◆ raycaster()

const Raycaster & PathTracer::raycaster ( ) const
inline
Returns
the internal raycaster.

◆ render()

void PathTracer::render ( const Camera camera,
size_t  samples,
size_t  depth,
Image render 
)

Performs a rendering of the scene.

Parameters
camerathe viewpoint to use
samplesthe number of samples per-pixel
depththe maximum number of bounces for each path
renderthe image, will be filled with the (gamma-corrected) result
Todo:
Support dieletric specular on top.
Todo:
Support all materials from the PBR demo.

The documentation for this class was generated from the following files: