Support Forum       G3D Web Page     
Classes | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
G3D::PathTracer Class Reference

Inherits G3D::ReferenceCountedObject.

Classes

class  BufferSet
 Per-path data passed between major routines. More...
 
class  Options
 

Public Member Functions

void prepare (const Options &options) const
 Call on the main thread if you wish to force GPU->CPU conversion and tree building to happen right now. More...
 
void setScene (const shared_ptr< Scene > &scene)
 Replaces the previous scene. More...
 
void traceBuffer (Array< Ray > &rayBuffer, Radiance3 *output, const Options &options, bool lightEmissiveOnFirstHit, const float *weight=nullptr, float *distance=nullptr, Vector3 *primaryWSNormalBuffer=nullptr, Color3 *primaryAlbedoBuffer=nullptr) const
 
More...
 
void traceImage (const shared_ptr< Image > &radianceImage, const shared_ptr< Camera > &camera, const Options &options, const std::function< void(const String &, float)> &statusCallback=nullptr) const
 Assumes that the scene has been previously set. More...
 
const shared_ptr< TriTree > & triTree () const
 

Static Public Member Functions

static shared_ptr< PathTracercreate (shared_ptr< TriTree > t=nullptr)
 

Protected Types

typedef Point2 PixelCoord
 

Protected Member Functions

 PathTracer (const shared_ptr< TriTree > &t=nullptr)
 
void addEmissive (const Array< Ray > &rayFromEye, const Array< shared_ptr< Surfel >> &surfelBuffer, const Array< bool > &impulseRay, const Array< Color3 > &modulationBuffer, Radiance3 *outputBuffer, const Array< int > outputCoordBuffer, const shared_ptr< Image > &radianceImage, const Array< PixelCoord > &pixelCoordBuffer) const
 In a properly modeled scene with area lights and no duplicating point lights, we should only count this term on the first bounce. More...
 
void computeDirectIllumination (const Array< shared_ptr< Surfel >> &surfelBuffer, const Array< shared_ptr< Light >> &lightArray, const Array< Ray > &rayBuffer, int currentPathDepth, int currentRayIndex, const Options &options, const Array< PixelCoord > &pixelCoordBuffer, const int radianceImageWidth, Array< Radiance3 > &directBuffer, Array< Ray > &shadowRayBuffer) const
 Choose what light surface to sample, storing the corresponding shadow ray and biradiance value. More...
 
void generateEyeRays (int width, int height, const shared_ptr< Camera > &camera, Array< Ray > &rayBuffer, bool randomSubpixelPosition, Array< PixelCoord > &pixelCoordBuffer, const shared_ptr< Image > &weightSumImage, int rayIndex, int raysPerPixel) const
 Produces a buffer of eye rays, stored in raster order in the preallocated rayBuffer. More...
 
const shared_ptr< Light > & importanceSampleLight (const Array< shared_ptr< Light >> &lightArray, const Vector3 &w_o, const shared_ptr< Surfel > &surfel, int sequenceIndex, int rayIndex, int raysPerPixel, Biradiance3 &biradiance, Color3 &cosBSDFDivPDF, Point3 &lightPosition) const
 sequenceIndex = (pixelIndex * maxPathDepth) + currentPathDepth) More...
 
void prepare (const Options &options, Array< shared_ptr< Light >> &directLightArray, Array< shared_ptr< Light >> &indirectLightArray) const
 
Point3 sampleOneLight (const shared_ptr< Light > &light, const Point3 &X, const Vector3 &n, int pixelIndex, int lightIndex, int sampleIndex, int numSamples, float &areaTimesPDFValue) const
 
Sample a single light and choose a point on it, potentially in a low-discrepancy or importance sampling way. More...
 
virtual void scatterRays (const Array< shared_ptr< Surfel >> &surfelBuffer, const Array< shared_ptr< Light >> &indirectLightArray, int currentPathDepth, int rayIndex, int raysPerPixel, Array< Ray > &rayBuffer, Array< Color3 > &modulationBuffer, Array< bool > &impulseScatterBuffer) const
 Compute the next bounce direction by mutating rayBuffer, and then multiply the modulationBuffer by the inverse probability density that the direction was taken. More...
 
virtual void shade (const Array< shared_ptr< Surfel >> &surfelBuffer, const Array< Ray > &rayFromEye, const Array< Ray > &rayFromLight, const Array< bool > &lightShadowedBuffer, const Array< Radiance3 > &directBuffer, const Array< Color3 > &modulationBuffer, Radiance3 *outputBuffer, const Array< int > outputCoordBuffer, const shared_ptr< Image > &radianceImage, const Array< PixelCoord > &pixelCoordBuffer) const
 Apply the BSDF for each surfel to the biradiance in the corresponding light (unless shadowed), modulate as specified, and add to the image. More...
 
Radiance3 skyRadiance (const Vector3 &direction) const
 
virtual void traceBufferInternal (BufferSet &buffers, Radiance3 *output, const shared_ptr< Image > &radianceImage, float *distance, const Array< shared_ptr< Light >> &directLightArray, const Array< shared_ptr< Light >> &indirectLightArray, int currentRayIndex) const
 Called from traceBuffer after the options are set and scene is processed. More...
 

Static Protected Member Functions

template<class T , class ... ArgTypes>
static shared_ptr< T > createShared (ArgTypes &&... args)
 Like std::make_shared, but works for protected constructors. More...
 

Protected Attributes

shared_ptr< CubeMapm_environmentMap
 
Options m_options
 For the active trace. More...
 
shared_ptr< Scenem_scene
 
shared_ptr< CubeMapm_skybox
 
shared_ptr< TriTreem_triTree
 

Static Protected Attributes

static const Ray s_degenerateRay
 

Member Typedef Documentation

◆ PixelCoord

Constructor & Destructor Documentation

◆ PathTracer()

G3D::PathTracer::PathTracer ( const shared_ptr< TriTree > &  t = nullptr)
protected

Member Function Documentation

◆ addEmissive()

void G3D::PathTracer::addEmissive ( const Array< Ray > &  rayFromEye,
const Array< shared_ptr< Surfel >> &  surfelBuffer,
const Array< bool > &  impulseRay,
const Array< Color3 > &  modulationBuffer,
Radiance3 outputBuffer,
const Array< int >  outputCoordBuffer,
const shared_ptr< Image > &  radianceImage,
const Array< PixelCoord > &  pixelCoordBuffer 
) const
protected

In a properly modeled scene with area lights and no duplicating point lights, we should only count this term on the first bounce.

However, we're only going to sample point lights explicitly, so we need emissive on every bounce. Scenes like G3D cornell box where there are both point and emissives in the same location will get brighter than expected as a result.

If outputBuffer is not null, writes to it using outputCoordBuffer indices, otherwise writes to radianceImage using pixelCoordBuffer indices.

◆ computeDirectIllumination()

void G3D::PathTracer::computeDirectIllumination ( const Array< shared_ptr< Surfel >> &  surfelBuffer,
const Array< shared_ptr< Light >> &  lightArray,
const Array< Ray > &  rayBuffer,
int  currentPathDepth,
int  currentRayIndex,
const Options options,
const Array< PixelCoord > &  pixelCoordBuffer,
const int  radianceImageWidth,
Array< Radiance3 > &  directBuffer,
Array< Ray > &  shadowRayBuffer 
) const
protected

Choose what light surface to sample, storing the corresponding shadow ray and biradiance value.

◆ create()

static shared_ptr<PathTracer> G3D::PathTracer::create ( shared_ptr< TriTree t = nullptr)
static

◆ createShared()

template<class T , class ... ArgTypes>
static shared_ptr<T> G3D::ReferenceCountedObject::createShared ( ArgTypes &&...  args)
inlinestaticprotectedinherited

Like std::make_shared, but works for protected constructors.

Call as createShared<myclass>.

◆ generateEyeRays()

void G3D::PathTracer::generateEyeRays ( int  width,
int  height,
const shared_ptr< Camera > &  camera,
Array< Ray > &  rayBuffer,
bool  randomSubpixelPosition,
Array< PixelCoord > &  pixelCoordBuffer,
const shared_ptr< Image > &  weightSumImage,
int  rayIndex,
int  raysPerPixel 
) const
protected

Produces a buffer of eye rays, stored in raster order in the preallocated rayBuffer.

Parameters
castThroughCenterWhen true (for the first ray at each pixel), cast the ray through the pixel center to make images look less noisy.
raysPerPixel
rayIndexbetween 0 and raysPerPixel - 1, used for lens low-discrepancy sampling

◆ importanceSampleLight()

const shared_ptr<Light>& G3D::PathTracer::importanceSampleLight ( const Array< shared_ptr< Light >> &  lightArray,
const Vector3 w_o,
const shared_ptr< Surfel > &  surfel,
int  sequenceIndex,
int  rayIndex,
int  raysPerPixel,
Biradiance3 biradiance,
Color3 cosBSDFDivPDF,
Point3 lightPosition 
) const
protected

sequenceIndex = (pixelIndex * maxPathDepth) + currentPathDepth)

Parameters
probabilityRelative probablity mass with which this particular sample was taken relative to other samples that were considered.

◆ prepare() [1/2]

void G3D::PathTracer::prepare ( const Options options,
Array< shared_ptr< Light >> &  directLightArray,
Array< shared_ptr< Light >> &  indirectLightArray 
) const
protected

Referenced by prepare().

◆ prepare() [2/2]

void G3D::PathTracer::prepare ( const Options options) const
inline

Call on the main thread if you wish to force GPU->CPU conversion and tree building to happen right now.

◆ sampleOneLight()

Point3 G3D::PathTracer::sampleOneLight ( const shared_ptr< Light > &  light,
const Point3 X,
const Vector3 n,
int  pixelIndex,
int  lightIndex,
int  sampleIndex,
int  numSamples,
float &  areaTimesPDFValue 
) const
protected


Sample a single light and choose a point on it, potentially in a low-discrepancy or importance sampling way.

areaTimesPDFValue Return value that is the area of the light times the differential probability with which each point was selected.For uniform selection, this value is just 1.0f.

X the point from which the light will be viewed. Set to Point3::NaN to ignore. n the surface normal at X. Set to Point3::NaN to ignore.

See also
Light::lowDiscrepancyPosition

◆ scatterRays()

virtual void G3D::PathTracer::scatterRays ( const Array< shared_ptr< Surfel >> &  surfelBuffer,
const Array< shared_ptr< Light >> &  indirectLightArray,
int  currentPathDepth,
int  rayIndex,
int  raysPerPixel,
Array< Ray > &  rayBuffer,
Array< Color3 > &  modulationBuffer,
Array< bool > &  impulseScatterBuffer 
) const
protectedvirtual

Compute the next bounce direction by mutating rayBuffer, and then multiply the modulationBuffer by the inverse probability density that the direction was taken.

Those probabilities are computed across three color channels, so modulationBuffer can become "colored" by this.

◆ setScene()

void G3D::PathTracer::setScene ( const shared_ptr< Scene > &  scene)

Replaces the previous scene.

◆ shade()

virtual void G3D::PathTracer::shade ( const Array< shared_ptr< Surfel >> &  surfelBuffer,
const Array< Ray > &  rayFromEye,
const Array< Ray > &  rayFromLight,
const Array< bool > &  lightShadowedBuffer,
const Array< Radiance3 > &  directBuffer,
const Array< Color3 > &  modulationBuffer,
Radiance3 outputBuffer,
const Array< int >  outputCoordBuffer,
const shared_ptr< Image > &  radianceImage,
const Array< PixelCoord > &  pixelCoordBuffer 
) const
protectedvirtual

Apply the BSDF for each surfel to the biradiance in the corresponding light (unless shadowed), modulate as specified, and add to the image.

Emissive light is only added for primary surfaces since it is already accounted for by explicit light sampling.

If outputBuffer is not null, writes to it using outputCoordBuffer indices, otherwise writes to radianceImage using pixelCoordBuffer indices.

◆ skyRadiance()

Radiance3 G3D::PathTracer::skyRadiance ( const Vector3 direction) const
protected

◆ traceBuffer()

void G3D::PathTracer::traceBuffer ( Array< Ray > &  rayBuffer,
Radiance3 output,
const Options options,
bool  lightEmissiveOnFirstHit,
const float *  weight = nullptr,
float *  distance = nullptr,
Vector3 primaryWSNormalBuffer = nullptr,
Color3 primaryAlbedoBuffer = nullptr 
) const


Parameters
outputMust be allocated to at least the size of rayBuffer. This may be uncached, memory mapped memory.
weightif not null, each output is scaled by the corresponding weight.

The rayBuffer will be modified. Make a copy if you wish to preserve the initial values.

Parameters
distanceIf not null, this is filled with the hit distance to the primary surface for each ray. Misses are set to infinity.
lightEmissiveOnFirstHitShould the first hit be treated as a primary/impulse hit and include the emissive term from a light source surface?
primaryWSNormalBufferIf not null, the normal at the primary hit point for each ray. NaN if no hit.
primaryAlbedoBufferIf not null, a color at the primary hit point.

◆ traceBufferInternal()

virtual void G3D::PathTracer::traceBufferInternal ( BufferSet buffers,
Radiance3 output,
const shared_ptr< Image > &  radianceImage,
float *  distance,
const Array< shared_ptr< Light >> &  directLightArray,
const Array< shared_ptr< Light >> &  indirectLightArray,
int  currentRayIndex 
) const
protectedvirtual

Called from traceBuffer after the options are set and scene is processed.

Parameters
currentRayIndexIf you are tracing multiple rays per pixel, this is the loop index of these rays.

If output is not null, the output is written there. Otherwise the output is bilinearly blended into the radianceImage and the pixelCoordBuffer is used.

If weight is not null, it is an array of per-output weights.

If distance is not null, the distance to each primary hit is written to it (not the "Z" value).

◆ traceImage()

void G3D::PathTracer::traceImage ( const shared_ptr< Image > &  radianceImage,
const shared_ptr< Camera > &  camera,
const Options options,
const std::function< void(const String &, float)> &  statusCallback = nullptr 
) const

Assumes that the scene has been previously set.

Only rebuilds the tree if the scene has changed.

Parameters
statusCallbackFunction called periodically to update the GUI with the rendering progress. Arguments are percentage (between 0 and 1) and an arbitrary message string.

◆ triTree()

const shared_ptr<TriTree>& G3D::PathTracer::triTree ( ) const
inline

Member Data Documentation

◆ m_environmentMap

shared_ptr<CubeMap> G3D::PathTracer::m_environmentMap
mutableprotected
See also
Options:: useEnvironmentMapForLastScatteringEvent

◆ m_options

Options G3D::PathTracer::m_options
mutableprotected

For the active trace.

◆ m_scene

shared_ptr<Scene> G3D::PathTracer::m_scene
protected

◆ m_skybox

shared_ptr<CubeMap> G3D::PathTracer::m_skybox
mutableprotected

◆ m_triTree

shared_ptr<TriTree> G3D::PathTracer::m_triTree
mutableprotected

Referenced by triTree().

◆ s_degenerateRay

const Ray G3D::PathTracer::s_degenerateRay
staticprotected

documentation generated on Wed Nov 24 2021 08:01:59 using doxygen 1.8.15