52 static std::atomic<SLuint> seedCounter{0};
54 thread_local std::mt19937 engine((
SLuint)std::time(
nullptr) * 2654435761u +
55 seedCounter.fetch_add(1u) * 40503u + 1u);
57 thread_local std::uniform_real_distribution<SLfloat> dist(0.0f, 1.0f);
129 SLRay* rayFromHitPoint)
147 x = rayFromHitPoint->
x;
148 y = rayFromHitPoint->
y;
150 sv = rayFromHitPoint->
sv;
162 SL_LOG(
"Ray: O(%.2f, %.2f, %.2f), D(%.2f, %.2f, %.2f), L: %.2f",
190 reflected->
length = FLT_MAX;
220 assert(
hitMesh &&
"hitMesh is null");
226 SLbool hitFrontSide = c1 > 0.0f;
242 eta = 1.0f / hitMat->
kn();
249 eta = hitMat->
kn() / hitMatOut->
kn();
258 eta = hitMatOut->
kn() / hitMat->
kn();
262 eta = srcMat->
kn() / hitMat->
kn();
268 eta = hitMat->
kn() / hitMatOut->
kn();
283 SLfloat c2 = 1.0f + (w - eta) * (w + eta);
314 refracted->
length = FLT_MAX;
425 SLfloat f1 = sqrt(1.0f - pow(eta1, 2.0f / (shininess + 1.0f)));
428 randVec.
set(f1 * cos(eta2),
430 pow(eta1, 1.0f / (shininess + 1.0f)));
435 reflected->
length = FLT_MAX;
443 reflected->
setDir(rotMat * randVec);
490 SLfloat f1 = sqrt(1.0f - pow(eta1, 2.0f / (translucency + 1.0f)));
493 randVec.
set(f1 * cos(eta2),
495 pow(eta1, 1.0f / (translucency + 1.0f)));
500 refracted->
length = FLT_MAX;
508 refracted->
setDir(rotMat * randVec);
564 eta1sqrt = sqrt(1 - eta1);
567 randVec.
set(eta1sqrt * cos(eta2),
568 eta1sqrt * sin(eta2),
572 scattered->
setDir(rotMat * randVec);
float SLfloat
analog to GLfloat
#define SL_LOG(...)
Some debugging and error handling macros.
unsigned int SLuint
analog to GLuint
bool SLbool
analog to GLbool
SLMat3< SLfloat > SLMat3f
Defines a standard CG material with textures and a shader program.
void translucency(SLfloat transl)
void shininess(SLfloat shin)
SLMaterial * matOut() const
void name(const SLstring &Name)
Ray class with ray and intersection properties.
static SLint maxDepth
Max. recursion depth.
static SLuint shadowRays
NO. of shadow rays.
SLint hitTriangle
Points to the intersected triangle.
static SLuint tirRays
NO. of TIR refraction rays.
SLVec3f origin
Vector to the origin of ray in WS.
static SLuint primaryRays
NO. of primary rays shot.
bool reflectMC(SLRay *reflected, const SLMat3f &rotMat) const
SLfloat lightDist
Distance to light for shadow rays.
SLRayType type
PRIMARY, REFLECTED, REFRACTED, SHADOW.
SLint srcTriangle
Points to the triangle at ray origin.
static SLuint intersections
NO. of intersection.
SLCol4f backgroundColor
Background color at pixel x,y.
static SLint depthReached
depth reached for a primary ray
static SLfloat minContrib
Min. contibution to color (1/256)
SLMesh * hitMesh
Points to the intersected mesh.
SLbool isOutside
Flag if ray is inside of a material.
static SLint maxDepthReached
max. depth reached for all rays
SLint depth
Recursion depth for ray tracing.
SLfloat hitAO
Ambient occlusion factor at intersection point.
SLVec3f dir
Direction vector of ray in WS.
SLMesh * srcMesh
Points to the mesh at ray origin.
void refract(SLRay *refracted)
static SLMat3f lobeToWorld(const SLVec3f &lobeAxis)
Rotation matrix that maps a sample drawn around +z onto lobeAxis.
SLint sign[3]
Sign of invDir for fast AABB hit in WS.
SLfloat length
length from origin to an intersection
SLNode * hitNode
Points to the intersected node.
static SLuint ignoredRays
NO. of ignore refraction rays.
SLfloat contrib
Current contribution of ray to color.
SLbool isInsideVolume
Flag if ray is in Volume.
SLVec3f hitPoint
Point of intersection.
void diffuseMC(SLRay *scattered) const
static SLuint subsampledPixels
NO. of of subsampled pixels.
SLNode * srcNode
Points to the node at ray origin.
void setDir(const SLVec3f &Dir)
Setter for the rays direction in world space also setting the inverse direction.
bool refractMC(SLRay *refracted, const SLMat3f &rotMat) const
static SLuint tests
NO. of intersection tests.
void reflect(SLRay *reflected) const
static SLuint reflectedRays
NO. of reflected rays.
SLCol4f hitTexColor
Color at intersection for texture or color attributes.
SLfloat y
Pixel position for primary rays.
SLVec3f hitNormal
Surface normal at intersection point.
SLSceneView * sv
Pointer to the sceneview.
static SLfloat avgDepth
average depth reached
SLRay(SLSceneView *sv=nullptr)
default ctor
static SLuint refractedRays
NO. of refracted rays.
static SLuint subsampledRays
NO. of of subsampled rays.
void skybox(SLSkybox *skybox)
SceneView class represents a dynamic real time 3D view onto the scene.
SLstring toString(SLstring delimiter=", ", int decimals=2)
Conversion to string.
void set(const T X, const T Y, const T Z)
T dot(const SLVec3 &v) const
string toString(float f, int roundedDecimals)
Returns a string from a float with max. one trailing zero.