Skip to content
Snippets Groups Projects
Commit e0eacdf3 authored by Alex Laptop's avatar Alex Laptop
Browse files

Slight refactor

parent bfbd4296
No related branches found
No related tags found
1 merge request!101Path tracing
Pipeline #27260 passed
...@@ -67,6 +67,7 @@ struct Intersection{ ...@@ -67,6 +67,7 @@ struct Intersection{
Material material; Material material;
}; };
// https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection
Intersection raySphereIntersect(Ray ray, Sphere sphere){ Intersection raySphereIntersect(Ray ray, Sphere sphere){
Intersection intersection; Intersection intersection;
...@@ -75,18 +76,19 @@ Intersection raySphereIntersect(Ray ray, Sphere sphere){ ...@@ -75,18 +76,19 @@ Intersection raySphereIntersect(Ray ray, Sphere sphere){
vec3 L = sphere.center - ray.origin; vec3 L = sphere.center - ray.origin;
float tca = dot(L, ray.direction); float tca = dot(L, ray.direction);
float d2 = dot(L, L) - tca * tca; float d2 = dot(L, L) - tca * tca;
if (d2 > sphere.radius * sphere.radius){ if (d2 > sphere.radius * sphere.radius){
return intersection; return intersection;
} }
float thc = float(sqrt(sphere.radius * sphere.radius - d2)); float thc = float(sqrt(sphere.radius * sphere.radius - d2));
float t0 = tca - thc; float t0 = tca - thc;
float t1 = tca + thc; float t1 = tca + thc;
if (t0 < 0) {
if (t0 < 0)
t0 = t1; t0 = t1;
}
if (t0 < 0){ if (t0 < 0)
return intersection; return intersection;
}
intersection.hit = true; intersection.hit = true;
intersection.distance = t0; intersection.distance = t0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment