Path Tracing
Loading...
Searching...
No Matches
intersection.glsl File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

float planeT (Ray ray, vec3 normal, float offset)
float planeT_Z (Ray ray, float offset)
float planeT_X (Ray ray, float offset)
 Specific X-axis plane, with only offset.
float planeT_Y (Ray ray, float offset)
 Specific Y-axis plane, with only offset.
float sphereT (Ray ray, vec3 center, float radius)
float boxT (Ray ray, vec3 center, vec3 half_size, float pitch, float yaw, out vec3 out_normal)
float boxTAxisAligned (Ray ray, vec3 center, vec3 half_size, out vec3 out_normal)
 Fast axis-aligned box intersect, same result as boxT, but skips unused math Skips OBB rotation match, used for BVH traversal, which never rotates.
float triangleT (Ray ray, vec3 v0, vec3 v1, vec3 v2, out vec3 out_normal, out vec3 out_bary)
float triangleT (Ray ray, vec3 v0, vec3 v1, vec3 v2, out vec3 out_normal)
vec3 terminatorLift (vec3 p, vec3 a, vec3 b, vec3 c, vec3 na, vec3 nb, vec3 nc, vec3 w)
 Shadow terminator lifts a hit from the flat triangle onto the smooth surface implied by the vertex normals. p is projected onto each vertex's tangent plane it lies under (convex areas only) and the projections are blended with the barycentrics.

Function Documentation

◆ boxT()

float boxT ( Ray ray,
vec3 center,
vec3 half_size,
float pitch,
float yaw,
out vec3 out_normal )

AABBIntersect from https://alelievr.github.io/Modern-Rendering-Introduction/AABBIntersection/
Also based on knightcrawler25's GLSL-PATHTRACER. But applied OBB for rotation. Rotation is calculated from pitch and yaw for simplification

Note
Don't use boxT for BVH, since rotation will be unused computation

◆ boxTAxisAligned()

float boxTAxisAligned ( Ray ray,
vec3 center,
vec3 half_size,
out vec3 out_normal )

Fast axis-aligned box intersect, same result as boxT, but skips unused math Skips OBB rotation match, used for BVH traversal, which never rotates.

Note
Keeping boxT() only for rotated boxes
See also
boxT

◆ planeT()

float planeT ( Ray ray,
vec3 normal,
float offset )

General plane function using normal vector to give facing direction

Note
needs dot product for normal orientation, slower.

◆ planeT_X()

float planeT_X ( Ray ray,
float offset )

Specific X-axis plane, with only offset.

◆ planeT_Y()

float planeT_Y ( Ray ray,
float offset )

Specific Y-axis plane, with only offset.

◆ planeT_Z()

float planeT_Z ( Ray ray,
float offset )

Specific Z-axis plane, with only offset

Note
More optimized than planeT that needs extra normal vec operations

◆ sphereT()

float sphereT ( Ray ray,
vec3 center,
float radius )

Interseção raio-esfera ||o + t·v - c||² = r² Expande para t²(v·v) + 2t(v·(o-c)) + (||o-c||² - r²) = 0 Onde o = ray_origin v = ray_dir c = center r = radius Solução t = (-b ±sqrt(b² - 4ac)) / (2a) Em que coeficientes são a = v·v b = 2v·(o - c) c = ||o - c||² - r² Simplificado para b' = v·(o - c) → float b t = -b' ±sqrt(b'² - c) → float t Assumindo que ray.direction está normalizado v·v=1 → a=1

◆ terminatorLift()

vec3 terminatorLift ( vec3 p,
vec3 a,
vec3 b,
vec3 c,
vec3 na,
vec3 nb,
vec3 nc,
vec3 w )

Shadow terminator lifts a hit from the flat triangle onto the smooth surface implied by the vertex normals. p is projected onto each vertex's tangent plane it lies under (convex areas only) and the projections are blended with the barycentrics.

Note
See J. Hanika, "Hacking the Shadow Terminator", Ray Tracing Gems II, ch. 4, 2021
Parameters
wbarycentric weights matching a, b, c
na,nb,ncvertex normals, on the same side as the geometric normal
Returns
offset to add to p for rays leaving the surface, zero on flat or concave areas

◆ triangleT() [1/2]

float triangleT ( Ray ray,
vec3 v0,
vec3 v1,
vec3 v2,
out vec3 out_normal )

◆ triangleT() [2/2]

float triangleT ( Ray ray,
vec3 v0,
vec3 v1,
vec3 v2,
out vec3 out_normal,
out vec3 out_bary )

Möller-Trumbore ray-triangle intersect.