SLProject 4.0.000
SLRay Class Reference

Ray class with ray and intersection properties. More...

#include <SLRayMC.h>

Public Member Functions

 SLRay (SLSceneView *sv=nullptr)
 default ctor More...
 
 SLRay (const SLVec3f &Origin, const SLVec3f &Dir, SLfloat X, SLfloat Y, const SLCol4f &backColor, SLSceneView *sv)
 ctor for primary rays More...
 
 SLRay (SLfloat distToLight, const SLVec3f &dirToLight, SLRay *rayFromHitPoint)
 ctor for shadow rays More...
 
void reflect (SLRay *reflected) const
 
void refract (SLRay *refracted)
 
bool reflectMC (SLRay *reflected, const SLMat3f &rotMat) const
 
void refractMC (SLRay *refracted, const SLMat3f &rotMat) const
 
void diffuseMC (SLRay *scattered) const
 
void print () const
 
void setDir (const SLVec3f &Dir)
 Setter for the rays direction in world space also setting the inverse direction. More...
 
void setDirOS (const SLVec3f &Dir)
 Setter for the rays direction in object space also setting the inverse direction. More...
 
void normalizeNormal ()
 
SLbool isShaded () const
 Returns true if a shadow ray hits an object on the ray to the light. More...
 
SLbool hitMatIsReflective () const
 Returns true if the hit material specular color is not black. More...
 
SLbool hitMatIsTransparent () const
 Returns true if the hit material transmission color is not black. More...
 
SLbool hitMatIsDiffuse () const
 Returns true if the hit material diffuse color is not black. More...
 
 SLRay ()
 default ctor More...
 
 SLRay (SLVec3f Origin, SLVec3f Dir, SLint X, SLint Y)
 ctor for primary rays More...
 
 SLRay (SLfloat distToLight, SLVec3f dirToLight, SLRay *rayFromHitPoint)
 ctor for shadow rays More...
 
 SLRay (SLVec3f origin, SLVec3f dir, SLRayType type, SLShape *originShape, SLfloat length=SL_FLOAT_MAX, SLint depth=1)
 ctor for all parameters More...
 
void reflect (SLRay *reflected)
 
void refract (SLRay *refracted)
 
bool reflectMC (SLRay *reflected, SLMat3f rotMat)
 
void refractMC (SLRay *refracted, SLMat3f rotMat)
 
void diffuseMC (SLRay *scattered)
 
void setDir (SLVec3f Dir)
 
void setDirOS (SLVec3f Dir)
 
SLbool isShaded ()
 
void print ()
 
void normalizeNormal ()
 
SLbool nodeReflectance ()
 
SLbool nodeTransparency ()
 
SLbool nodeDiffuse ()
 

Static Public Member Functions

static SLuint totalNumRays ()
 Total NO. of rays shot during RT. More...
 

Public Attributes

SLVec3f origin
 Vector to the origin of ray in WS. More...
 
SLVec3f dir
 Direction vector of ray in WS. More...
 
SLfloat length
 length from origin to an intersection More...
 
SLint depth
 Recursion depth for ray tracing. More...
 
SLfloat contrib
 Current contribution of ray to color. More...
 
SLVec3f originOS
 Vector to the origin of ray in OS. More...
 
SLVec3f dirOS
 Direction vector of ray in OS. More...
 
SLRayType type
 PRIMARY, REFLECTED, REFRACTED, SHADOW. More...
 
SLfloat lightDist
 Distance to light for shadow rays. More...
 
SLfloat x
 
SLfloat y
 Pixel position for primary rays. More...
 
SLbool isOutside
 Flag if ray is inside of a material. More...
 
SLbool isInsideVolume
 Flag if ray is in Volume. More...
 
SLNodesrcNode
 Points to the node at ray origin. More...
 
SLMeshsrcMesh
 Points to the mesh at ray origin. More...
 
SLint srcTriangle
 Points to the triangle at ray origin. More...
 
SLCol4f backgroundColor
 Background color at pixel x,y. More...
 
SLSceneViewsv
 Pointer to the sceneview. More...
 
SLfloat hitU
 
SLfloat hitV
 barycentric coords in hit triangle More...
 
SLNodehitNode
 Points to the intersected node. More...
 
SLMeshhitMesh
 Points to the intersected mesh. More...
 
SLint hitTriangle
 Points to the intersected triangle. More...
 
SLVec3f hitPoint
 Point of intersection. More...
 
SLVec3f hitNormal
 Surface normal at intersection point. More...
 
SLCol4f hitTexColor
 Color at intersection for texture or color attributes. More...
 
SLfloat hitAO
 Ambient occlusion factor at intersection point. More...
 
SLVec3f invDir
 Inverse ray dir for fast AABB hit in WS. More...
 
SLVec3f invDirOS
 Inverse ray dir for fast AABB hit in OS. More...
 
SLint sign [3]
 Sign of invDir for fast AABB hit in WS. More...
 
SLint signOS [3]
 Sign of invDir for fast AABB hit in OS. More...
 
SLfloat tmin
 min. dist. of last AABB intersection More...
 
SLfloat tmax
 max. dist. of last AABB intersection More...
 
SLShape * originShape
 Points to the shape at ray origin. More...
 
SLFace * originTria
 Points to the triangle at ray origin. More...
 
SLMaterialoriginMat
 Points to appearance at ray origin. More...
 
SLShape * hitShape
 Points to the intersected shape. More...
 
SLFace * hitTriangle
 Points to the intersected triangle. More...
 
SLMaterialhitMat
 Points to material of intersected node. More...
 
SLCol4f hitTexCol
 Texture color at intersection point. More...
 

Static Public Attributes

static SLint maxDepth = 0
 Max. recursion depth. More...
 
static SLfloat minContrib = 1.0 / 256.0
 Min. contibution to color (1/256) More...
 
static SLuint primaryRays = 0
 NO. of primary rays shot. More...
 
static SLuint reflectedRays = 0
 NO. of reflected rays. More...
 
static SLuint refractedRays = 0
 NO. of refracted rays. More...
 
static SLuint ignoredRays = 0
 NO. of ignore refraction rays. More...
 
static SLuint shadowRays = 0
 NO. of shadow rays. More...
 
static SLuint tirRays = 0
 NO. of TIR refraction rays. More...
 
static SLuint tests = 0
 NO. of intersection tests. More...
 
static SLuint intersections = 0
 NO. of intersection. More...
 
static SLint depthReached = 1
 depth reached for a primary ray More...
 
static SLint maxDepthReached = 0
 max. depth reached for all rays More...
 
static SLfloat avgDepth = 0
 average depth reached More...
 
static SLuint subsampledRays = 0
 NO. of of subsampled rays. More...
 
static SLuint subsampledPixels = 0
 NO. of of subsampled pixels. More...
 
static SLlong emittedPhotons = 0
 NO. of emitted photons from all lightsources. More...
 
static SLlong diffusePhotons = 0
 NO. of diffusely scattered photons on surfaces. More...
 
static SLlong reflectedPhotons = 0
 NO. of reflected photons;. More...
 
static SLlong refractedPhotons = 0
 NO. of refracted photons;. More...
 
static SLlong tirPhotons = 0
 NO. of total internal refraction photons. More...
 
static SLbool ignoreLights = true
 flag for gloss sampling More...
 
static TRanrotBGenerator * random = new TRanrotBGenerator((unsigned)time(NULL))
 Random generator. More...
 

Detailed Description

Ray class with ray and intersection properties.

Ray class for Ray Tracing. It not only holds informations about the ray itself but also about the node hit by the ray. With that information the method reflect calculates a reflected ray and the method transmit calculates a REFRACTED ray.

Ray class for Ray Tracing. It not only holds informations about the ray itself but also about the node hit by the ray. With that information the method reflect calculates a reflected ray and the method transmit calculates a transmitted ray.

Constructor & Destructor Documentation

◆ SLRay() [1/7]

SLRay::SLRay ( SLSceneView sceneView = nullptr)
explicit

default ctor

SLRay::SLRay default constructor

◆ SLRay() [2/7]

SLRay::SLRay ( const SLVec3f Origin,
const SLVec3f Dir,
SLfloat  X,
SLfloat  Y,
const SLCol4f backColor,
SLSceneView sceneView 
)

ctor for primary rays

SLRay::SLRay constructor for primary rays

◆ SLRay() [3/7]

SLRay::SLRay ( SLfloat  distToLight,
const SLVec3f dirToLight,
SLRay rayFromHitPoint 
)

ctor for shadow rays

SLRay::SLRay constructor for shadow rays

◆ SLRay() [4/7]

SLRay::SLRay ( )

default ctor

SLRay::SLRay default constructor

◆ SLRay() [5/7]

SLRay::SLRay ( SLVec3f  Origin,
SLVec3f  Dir,
SLint  X,
SLint  Y 
)

ctor for primary rays

SLRay::SLRay constructor for primary rays

◆ SLRay() [6/7]

SLRay::SLRay ( SLfloat  distToLight,
SLVec3f  dirToLight,
SLRay rayFromHitPoint 
)

ctor for shadow rays

SLRay::SLRay constructor for shadow rays

◆ SLRay() [7/7]

SLRay::SLRay ( SLVec3f  origin,
SLVec3f  dir,
SLRayType  type,
SLShape *  originShape,
SLfloat  length = SL_FLOAT_MAX,
SLint  depth = 1 
)

ctor for all parameters

Member Function Documentation

◆ diffuseMC() [1/2]

void SLRay::diffuseMC ( SLRay scattered)

SLRay::diffuseMC scatters a ray around hit normal (cosine distribution). This is only used for photonmapping(russian roulette). The random direction lies around z-Axis and is then transformed by a rotation matrix to lie along the normal. The direction is calculated according to MCCABE

◆ diffuseMC() [2/2]

void SLRay::diffuseMC ( SLRay scattered) const

SLRay::diffuseMC scatters a ray around hit normal (cosine distribution). This is only used for photonmapping(russian roulette). The random direction lies around z-Axis and is then transformed by a rotation matrix to lie along the normal. The direction is calculated according to MCCABE

◆ hitMatIsDiffuse()

SLbool SLRay::hitMatIsDiffuse ( ) const
inline

Returns true if the hit material diffuse color is not black.

◆ hitMatIsReflective()

SLbool SLRay::hitMatIsReflective ( ) const
inline

Returns true if the hit material specular color is not black.

◆ hitMatIsTransparent()

SLbool SLRay::hitMatIsTransparent ( ) const
inline

Returns true if the hit material transmission color is not black.

◆ isShaded() [1/2]

SLbool SLRay::isShaded ( )
inline

◆ isShaded() [2/2]

SLbool SLRay::isShaded ( ) const
inline

Returns true if a shadow ray hits an object on the ray to the light.

◆ nodeDiffuse()

SLbool SLRay::nodeDiffuse ( )
inline

◆ nodeReflectance()

SLbool SLRay::nodeReflectance ( )
inline

◆ nodeTransparency()

SLbool SLRay::nodeTransparency ( )
inline

◆ normalizeNormal() [1/2]

void SLRay::normalizeNormal ( )
inline

SLRay::normalizeNormal does a careful normalization of the normal only when the squared length is > 1.0+FLT_EPSILON or < 1.0-FLT_EPSILON.

SLRay::normalizeNormal does a careful normalization of the normal only when the squared length is > 1.0+SL_EPSILON or < 1.0-SL_EPSILON.

◆ normalizeNormal() [2/2]

void SLRay::normalizeNormal ( )

◆ print() [1/2]

void SLRay::print ( )

SLRay::prints prints the rays origin (O), direction (D) and the length to the intersection (L)

◆ print() [2/2]

void SLRay::print ( ) const

SLRay::prints prints the rays origin (O), direction (D) and the length to the intersection (L)

◆ reflect() [1/2]

void SLRay::reflect ( SLRay reflected)

SLRay::reflect calculates a secondary ray reflected at the normal, starting at the intersection point. All vectors must be normalized vectors. R = 2(-I�N) N + I

◆ reflect() [2/2]

void SLRay::reflect ( SLRay reflected) const

SLRay::reflect calculates a secondary ray reflected at the normal, starting at the intersection point. All vectors must be normalized vectors. R = 2(-I*N) N + I

◆ reflectMC() [1/2]

bool SLRay::reflectMC ( SLRay reflected,
const SLMat3f rotMat 
) const

SLRay::reflectMC scatters a ray around perfect specular direction according to shininess (for higher shininess the ray is less scattered). This is used for path tracing and distributed ray tracing as well as for photon scattering. The direction is calculated according to MCCABE. The created direction is along z-axis and then transformed to lie along specular direction with rotationMatrix rotMat. The rotation matrix must be precalculated (stays the same for each ray sample, needs to be be calculated only once)

◆ reflectMC() [2/2]

bool SLRay::reflectMC ( SLRay reflected,
SLMat3f  rotMat 
)

SLRay::reflectMC scatters a ray around perfect specular direction according to shininess (for higher shininess the ray is less scattered). This is used for path tracing and distributed ray tracing as well as for photon scattering. The direction is calculated according to MCCABE. The created direction is along z-axis and then transformed to lie along specular direction with rotationMatrix rotMat. The rotation matrix must be precalculated (stays the same for each ray sample, needs to be be calculated only once)

◆ refract() [1/2]

void SLRay::refract ( SLRay refracted)

SLRay::refract calculates a secondary refracted ray, starting at the intersection point. All vectors must be normalized vectors, so the refracted vector T will be a unit vector too. If total internal refraction occurs a reflected ray is calculated instead. Index of refraction eta = Kn_Source/Kn_Destination (Kn_Air = 1.0) We are using a formula by Xavier Bec that is a little faster: http://www.realtimerendering.com/resources/RTNews/html/rtnv10n1.html#art3

SLRay::refract calculates a secondary refracted ray, starting at the intersection point. All vectors must be normalized vectors, so the refracted vector T will be a unit vector too. If total internal refraction occurs a reflected ray is calculated instead. Index of refraction eta = Kn_Source/Kn_Destination (Kn_Air = 1.0)

◆ refract() [2/2]

void SLRay::refract ( SLRay refracted)

◆ refractMC() [1/2]

void SLRay::refractMC ( SLRay refracted,
const SLMat3f rotMat 
) const

SLRay::refractMC scatters a ray around perfect transmissive direction according to translucency (for higher translucency the ray is less scattered). This is used for path tracing and distributed ray tracing as well as for photon scattering. The direction is calculated the same as with specular scattering (see reflectMC). The created direction is along z-axis and then transformed to lie along transmissive direction with rotationMatrix rotMat. The rotation matrix must be precalculated (stays the same for each ray sample, needs to be be calculated only once)

◆ refractMC() [2/2]

void SLRay::refractMC ( SLRay refracted,
SLMat3f  rotMat 
)

SLRay::refractMC scatters a ray around perfect transmissive direction according to translucency (for higher translucency the ray is less scattered). This is used for path tracing and distributed ray tracing as well as for photon scattering. The direction is calculated the same as with specular scattering (see reflectMC). The created direction is along z-axis and then transformed to lie along transmissive direction with rotationMatrix rotMat. The rotation matrix must be precalculated (stays the same for each ray sample, needs to be be calculated only once)

◆ setDir() [1/2]

void SLRay::setDir ( const SLVec3f Dir)
inline

Setter for the rays direction in world space also setting the inverse direction.

◆ setDir() [2/2]

void SLRay::setDir ( SLVec3f  Dir)
inline

◆ setDirOS() [1/2]

void SLRay::setDirOS ( const SLVec3f Dir)
inline

Setter for the rays direction in object space also setting the inverse direction.

◆ setDirOS() [2/2]

void SLRay::setDirOS ( SLVec3f  Dir)
inline

◆ totalNumRays()

static SLuint SLRay::totalNumRays ( )
inlinestatic

Total NO. of rays shot during RT.

Member Data Documentation

◆ avgDepth

static SLfloat SLRay::avgDepth = 0
static

average depth reached

◆ backgroundColor

SLCol4f SLRay::backgroundColor

Background color at pixel x,y.

◆ contrib

SLfloat SLRay::contrib

Current contribution of ray to color.

Current contibution of ray to color.

◆ depth

SLint SLRay::depth

Recursion depth for ray tracing.

◆ depthReached

static SLint SLRay::depthReached = 1
static

depth reached for a primary ray

◆ diffusePhotons

SLlong SLRay::diffusePhotons = 0
static

NO. of diffusely scattered photons on surfaces.

◆ dir

SLVec3f SLRay::dir

Direction vector of ray in WS.

◆ dirOS

SLVec3f SLRay::dirOS

Direction vector of ray in OS.

◆ emittedPhotons

SLlong SLRay::emittedPhotons = 0
static

NO. of emitted photons from all lightsources.

◆ hitAO

SLfloat SLRay::hitAO

Ambient occlusion factor at intersection point.

◆ hitMat

SLMaterial* SLRay::hitMat

Points to material of intersected node.

◆ hitMesh

SLMesh* SLRay::hitMesh

Points to the intersected mesh.

◆ hitNode

SLNode* SLRay::hitNode

Points to the intersected node.

◆ hitNormal

SLVec3f SLRay::hitNormal

Surface normal at intersection point.

◆ hitPoint

SLVec3f SLRay::hitPoint

Point of intersection.

◆ hitShape

SLShape* SLRay::hitShape

Points to the intersected shape.

◆ hitTexCol

SLCol4f SLRay::hitTexCol

Texture color at intersection point.

◆ hitTexColor

SLCol4f SLRay::hitTexColor

Color at intersection for texture or color attributes.

◆ hitTriangle [1/2]

SLint SLRay::hitTriangle

Points to the intersected triangle.

◆ hitTriangle [2/2]

SLFace* SLRay::hitTriangle

Points to the intersected triangle.

◆ hitU

SLfloat SLRay::hitU

◆ hitV

SLfloat SLRay::hitV

barycentric coords in hit triangle

◆ ignoredRays

SLuint SLRay::ignoredRays = 0
static

NO. of ignore refraction rays.

◆ ignoreLights

SLbool SLRay::ignoreLights = true
static

flag for gloss sampling

◆ intersections

static SLuint SLRay::intersections = 0
static

NO. of intersection.

◆ invDir

SLVec3f SLRay::invDir

Inverse ray dir for fast AABB hit in WS.

◆ invDirOS

SLVec3f SLRay::invDirOS

Inverse ray dir for fast AABB hit in OS.

◆ isInsideVolume

SLbool SLRay::isInsideVolume

Flag if ray is in Volume.

◆ isOutside

SLbool SLRay::isOutside

Flag if ray is inside of a material.

◆ length

SLfloat SLRay::length

length from origin to an intersection

◆ lightDist

SLfloat SLRay::lightDist

Distance to light for shadow rays.

◆ maxDepth

static SLint SLRay::maxDepth = 0
static

Max. recursion depth.

◆ maxDepthReached

static SLint SLRay::maxDepthReached = 0
static

max. depth reached for all rays

◆ minContrib

static SLfloat SLRay::minContrib = 1.0 / 256.0
static

Min. contibution to color (1/256)

◆ origin

SLVec3f SLRay::origin

Vector to the origin of ray in WS.

◆ originMat

SLMaterial* SLRay::originMat

Points to appearance at ray origin.

◆ originOS

SLVec3f SLRay::originOS

Vector to the origin of ray in OS.

◆ originShape

SLShape* SLRay::originShape

Points to the shape at ray origin.

◆ originTria

SLFace* SLRay::originTria

Points to the triangle at ray origin.

◆ primaryRays

SLuint SLRay::primaryRays = 0
static

NO. of primary rays shot.

◆ random

TRanrotBGenerator * SLRay::random = new TRanrotBGenerator((unsigned)time(NULL))
static

Random generator.

◆ reflectedPhotons

SLlong SLRay::reflectedPhotons = 0
static

NO. of reflected photons;.

◆ reflectedRays

static SLuint SLRay::reflectedRays = 0
static

NO. of reflected rays.

◆ refractedPhotons

SLlong SLRay::refractedPhotons = 0
static

NO. of refracted photons;.

◆ refractedRays

static SLuint SLRay::refractedRays = 0
static

NO. of refracted rays.

NO. of transmitted rays.

◆ shadowRays

static SLuint SLRay::shadowRays = 0
static

NO. of shadow rays.

◆ sign

SLint SLRay::sign

Sign of invDir for fast AABB hit in WS.

◆ signOS

SLint SLRay::signOS

Sign of invDir for fast AABB hit in OS.

◆ srcMesh

SLMesh* SLRay::srcMesh

Points to the mesh at ray origin.

◆ srcNode

SLNode* SLRay::srcNode

Points to the node at ray origin.

◆ srcTriangle

SLint SLRay::srcTriangle

Points to the triangle at ray origin.

◆ subsampledPixels

static SLuint SLRay::subsampledPixels = 0
static

NO. of of subsampled pixels.

◆ subsampledRays

static SLuint SLRay::subsampledRays = 0
static

NO. of of subsampled rays.

◆ sv

SLSceneView* SLRay::sv

Pointer to the sceneview.

◆ tests

static SLuint SLRay::tests = 0
static

NO. of intersection tests.

◆ tirPhotons

SLlong SLRay::tirPhotons = 0
static

NO. of total internal refraction photons.

◆ tirRays

static SLuint SLRay::tirRays = 0
static

NO. of TIR refraction rays.

◆ tmax

SLfloat SLRay::tmax

max. dist. of last AABB intersection

◆ tmin

SLfloat SLRay::tmin

min. dist. of last AABB intersection

◆ type

SLRayType SLRay::type

PRIMARY, REFLECTED, REFRACTED, SHADOW.

PRIMARY, REFLECTED, TRANSMITTED, SHADOW.

◆ x

SLfloat SLRay::x

◆ y

SLfloat SLRay::y

Pixel position for primary rays.


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