Skip to content

Commit

Permalink
Better ordering of hit record in ray_color() func
Browse files Browse the repository at this point in the history
Originally due to GitHub user @sshaplygin.
  • Loading branch information
hollasch committed Oct 31, 2023
1 parent 52b6c0f commit 891e5ac
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
23 changes: 10 additions & 13 deletions books/RayTracingInOneWeekend.html
Original file line number Diff line number Diff line change
Expand Up @@ -2387,16 +2387,13 @@
...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
color ray_color(const ray& r, int depth, const hittable& world) const {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
hit_record rec;


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
// If we've exceeded the ray bounce limit, no more light is gathered.
if (depth <= 0)
return color(0,0,0);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++

hit_record rec;

if (world.hit(r, interval(0, infinity), rec)) {
vec3 direction = random_on_hemisphere(rec.normal);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
Expand Down Expand Up @@ -2462,12 +2459,12 @@
private:
...
color ray_color(const ray& r, int depth, const hittable& world) const {
hit_record rec;

// If we've exceeded the ray bounce limit, no more light is gathered.
if (depth <= 0)
return color(0,0,0);

hit_record rec;


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
if (world.hit(r, interval(0.001, infinity), rec)) {
Expand Down Expand Up @@ -2533,12 +2530,12 @@
class camera {
...
color ray_color(const ray& r, int depth, const hittable& world) const {
hit_record rec;

// If we've exceeded the ray bounce limit, no more light is gathered.
if (depth <= 0)
return color(0,0,0);

hit_record rec;

if (world.hit(r, interval(0.001, infinity), rec)) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
vec3 direction = rec.normal + random_unit_vector();
Expand Down Expand Up @@ -2594,12 +2591,12 @@
class camera {
...
color ray_color(const ray& r, int depth, const hittable& world) const {
hit_record rec;

// If we've exceeded the ray bounce limit, no more light is gathered.
if (depth <= 0)
return color(0,0,0);

hit_record rec;

if (world.hit(r, interval(0.001, infinity), rec)) {
vec3 direction = rec.normal + random_unit_vector();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
Expand Down Expand Up @@ -2983,12 +2980,12 @@
private:
...
color ray_color(const ray& r, int depth, const hittable& world) const {
hit_record rec;

// If we've exceeded the ray bounce limit, no more light is gathered.
if (depth <= 0)
return color(0,0,0);

hit_record rec;

if (world.hit(r, interval(0.001, infinity), rec)) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
ray scattered;
Expand Down
4 changes: 2 additions & 2 deletions books/RayTracingTheNextWeek.html
Original file line number Diff line number Diff line change
Expand Up @@ -3126,12 +3126,12 @@
private:
...
color ray_color(const ray& r, int depth, const hittable& world) const {
hit_record rec;

// If we've exceeded the ray bounce limit, no more light is gathered.
if (depth <= 0)
return color(0,0,0);

hit_record rec;


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
// If the ray hits nothing, return the background color.
Expand Down
16 changes: 8 additions & 8 deletions books/RayTracingTheRestOfYourLife.html
Original file line number Diff line number Diff line change
Expand Up @@ -1677,12 +1677,12 @@
private:
...
color ray_color(const ray& r, int depth, const hittable& world) const {
hit_record rec;

// If we've exceeded the ray bounce limit, no more light is gathered.
if (depth <= 0)
return color(0,0,0);

hit_record rec;

// If the ray hits nothing, return the background color.
if (!world.hit(r, interval(0.001, infinity), rec))
return background;
Expand Down Expand Up @@ -2384,12 +2384,12 @@
...
private:
color ray_color(const ray& r, int depth, const hittable& world) const {
hit_record rec;

// If we've exceeded the ray bounce limit, no more light is gathered.
if (depth <= 0)
return color(0,0,0);

hit_record rec;

// If the ray hits nothing, return the background color.
if (!world.hit(r, interval(0.001, infinity), rec))
return background;
Expand Down Expand Up @@ -2609,12 +2609,12 @@
private:
...
color ray_color(const ray& r, int depth, const hittable& world) const {
hit_record rec;

// If we've exceeded the ray bounce limit, no more light is gathered.
if (depth <= 0)
return color(0,0,0);

hit_record rec;

// If the ray hits nothing, return the background color.
if (!world.hit(r, interval(0.001, infinity), rec))
return background;
Expand Down Expand Up @@ -3204,12 +3204,12 @@
...
color ray_color(const ray& r, int depth, const hittable& world, const hittable& lights)
const {
hit_record rec;

// If we've exceeded the ray bounce limit, no more light is gathered.
if (depth <= 0)
return color(0,0,0);

hit_record rec;

// If the ray hits nothing, return the background color.
if (!world.hit(r, interval(0.001, infinity), rec))
return background;
Expand Down
4 changes: 2 additions & 2 deletions src/TheRestOfYourLife/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ class camera {

color ray_color(const ray& r, int depth, const hittable& world, const hittable& lights)
const {
hit_record rec;

// If we've exceeded the ray bounce limit, no more light is gathered.
if (depth <= 0)
return color(0,0,0);

hit_record rec;

// If the ray hits nothing, return the background color.
if (!world.hit(r, interval(0.001, infinity), rec))
return background;
Expand Down

0 comments on commit 891e5ac

Please sign in to comment.