![]() |
SLProject
4.3.020
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
|
Ray class with ray and intersection properties. More...
#include <SLRay.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 |
| bool | 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... | |
Static Public Member Functions | |
| static SLMat3f | lobeToWorld (const SLVec3f &lobeAxis) |
| Rotation matrix that maps a sample drawn around +z onto lobeAxis. More... | |
| 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... | |
| SLNode * | srcNode |
| Points to the node at ray origin. More... | |
| SLMesh * | srcMesh |
| 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... | |
| SLSceneView * | sv |
| Pointer to the sceneview. More... | |
| SLfloat | hitU |
| SLfloat | hitV |
| barycentric coords in hit triangle More... | |
| SLNode * | hitNode |
| Points to the intersected node. More... | |
| SLMesh * | hitMesh |
| 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... | |
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... | |
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.
|
explicit |
default ctor
SLRay::SLRay default constructor
Definition at line 65 of file SLRay.cpp.
| 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
Definition at line 93 of file SLRay.cpp.
ctor for shadow rays
SLRay::SLRay constructor for shadow rays
Definition at line 127 of file SLRay.cpp.
SLRay::diffuseMC scatters a ray around the hit normal with a cosine distribution, which is the importance sampling of the Lambertian BRDF: the density is cos(theta)/PI, so it cancels the cosine of the rendering equation and every sample carries the same weight. SLPathtracer::trace is its only caller in this repository.
The random direction lies around the z-Axis and is then transformed by a rotation matrix to lie along the normal. The direction is calculated according to MCCABE.
Definition at line 542 of file SLRay.cpp.
|
inline |
Returns true if the hit material diffuse color is not black.
Definition at line 219 of file SLRay.h.
|
inline |
|
inline |
|
inline |
Rotation matrix that maps a sample drawn around +z onto lobeAxis.
SLRay::lobeToWorld returns the rotation matrix that maps a direction sampled around the +z axis onto lobeAxis. Its columns are an orthonormal basis whose third vector is lobeAxis, so that rotMat * v = v.x*t + v.y*b + v.z*lobeAxis.
This replaces the axis-angle construction that the scattering functions used to do themselves:
SLVec3f rotAxis((SLVec3f(0,0,1) ^ dir).normalize()); rotMat.rotation(acos(dir.z) * 180 * ONEOVERPI, rotAxis);
which fails exactly where it is used most. The cross product is (-dir.y, dir.x, 0) and its length is the sine of the angle, so it vanishes for a lobe axis along +-z. SLVec3::normalize guards with if (L > 0) and therefore returns the zero vector rather than a NaN, and the matrix built from a zero axis is diag(cos a, cos a, cos a) - a uniform scale, not a rotation. It happens to be usable at exactly +-z (identity and -I, and -I is fine for an azimuthally symmetric lobe) but the axis loses its precision continuously as the lobe approaches either pole, and acos(dir.z) additionally returns a NaN as soon as rounding pushes |dir.z| past 1. In the Muttenzer Box the box is axis aligned and the front and back walls face +-z, so this is the common case and not a corner one.
The basis is the branchless construction of Duff et al., "Building an Orthonormal Basis, Revisited", JCGT 6(1), 2017. It is exact and orthonormal for every unit vector including both poles, needs no trigonometry, and has no branch on a tolerance that has to be tuned.
Definition at line 372 of file SLRay.cpp.
|
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.
Definition at line 178 of file SLRay.h.
| void SLRay::print | ( | ) | 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
Definition at line 177 of file SLRay.cpp.
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, which SLRay::lobeToWorld builds from the perfect specular direction. The rotation matrix must be precalculated (stays the same for each ray sample, needs to be calculated only once).
reflected->dir must hold the perfect specular direction on entry, i.e. the caller must have run SLRay::reflect first, because it is the reference against which the sampled direction is tested.
Definition at line 413 of file SLRay.cpp.
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
Definition at line 218 of file SLRay.cpp.
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, which SLRay::lobeToWorld builds from the perfect transmissive direction. The rotation matrix must be precalculated (stays the same for each ray sample, needs to be calculated only once).
refracted->dir must hold the perfect transmissive direction on entry, i.e. the caller must have run SLRay::refract first.
Definition at line 478 of file SLRay.cpp.
|
inlinestatic |
| SLCol4f SLRay::backgroundColor |
|
static |
| SLfloat SLRay::hitAO |
| SLVec3f SLRay::hitNormal |
| SLCol4f SLRay::hitTexColor |
| SLint SLRay::hitTriangle |
|
static |
| SLVec3f SLRay::invDir |
| SLVec3f SLRay::invDirOS |
|
static |
|
static |
|
static |
|
static |
|
static |
| SLint SLRay::sign[3] |
| SLint SLRay::signOS[3] |
| SLint SLRay::srcTriangle |
|
static |
|
static |
| SLSceneView* SLRay::sv |
|
static |