jamis

jamis

Author of Mazes for Programmers and 1 other title

The Ray Tracer Challenge: various errata

The following is cross-posted from the original Ray Tracer Challenge forum, from a post by garfieldnate. I’m cross-posting it so that the errata can be kept in a single place.

Original post here: https://forum.raytracerchallenge.com/thread/203/performance-tips-clarifications-book-errata

Possible/Definite Errata

These are points where following the book exactly caused incorrect behavior in my implementation.

  • The “A ray misses a cube” test needs one more case: the ray is cast away from the cube. Not implementing this will make cubes always appear in front of the camera, even if placed behind it. Here is another test case where the ray should miss the cube:

|point(0, 0, 2) | vector(0, 0, 1)|

Fixing the book’s algorithm: at the end of the method, if tmax is negative then no intersection should be reported. The algorithm given in the book allows tmax to be a negative number, indicating an intersection opposite the ray’s direction.

  • Cylinder cap intersection should NOT have object_ray.direction.y <= REALLY_SMALL_POSITIVE_NUMBER as a quick return.
  • Cone and cylinder side intersections required checking a.abs() and b.abs() against REALLY_SMALL_POSITIVE_NUMBER; exact checking against 0 did not work at all.
  • For the second test case given for “Intersecting a cone with a ray”, I had to change -5 to -4.999999 to get the ray to intersect with the cone.
  • The cylinder azimuth calculation should be performed with x and z, not x and y.
  • Bonus bounding box chapter: there is no bounding box specified for smooth triangles; though I did not end up implementing this, I’m certain the algorithm has to be different from that used for regular triangles.
  • Bonus UV mapping chapter: the provided cross diagram for UV mapping of a cube is wrong for up and down
  • Up and down should both map x positively. The tests are correct. I found another chart with the correct mapping on wikipedia: en.wikipedia.org/wiki/Cube_mapping#/media/File:Cube_map.svg, but it also makes intuitive sense. Looking up or down from inside the cube, the observer’s x never reverses from the absolute x.

Clarifications

  • In the cone section: “If a is nonzero, you’ll use the same algorithm, but with the new a, b, and c, that you used for the cylinders.” I found this sentence confusing and it took a while to understand it. I think it would be more clearly written like so: “If a is nonzero, you’ll use the same algorithm (but with the new a, b, and c) that you used for the cylinders.”
  • Where UV mappers use mod/%, a note should be made that there are several related operations that a programming language might represent with %; particularly, be careful to choose an implementation that always return positive values, even if the input is negative. See the treatment on Wikipedia here: en.wikipedia.org/wiki/Modulo_operation#In_programming_languages. In Rust, I needed to use the rem_euclid function instead of the % operator.
  • There isn’t any note in the UV chapter on how a cylinder has to be scaled for the texture to look correct, though Jamis demonstrates it in the provided scene YAMLs. As I found a similar issue reported on StackOverflow, I ended up doing a little writeup there to explain the issue and how to fix it: stackoverflow.com/a/60913088/474819
  • Test “Converting a point from world to object space” should scale by 1,2,3 instead of 2,2,2 to catch more programming errors.

Typos/Small Errata

These will only really be useful for Jamis :)

  • Typo in bounding boxes chapter: inculde -> include
  • Pseudocode for CubeMap’s pattern_at contains uv_cube_left, etc. but these should be cube_uv_left, etc. to be consistent with the previous declarations in the chapter
  • There are two scenarios named “Checker pattern in 2D” in the UV mapping chapter. The second one should probably be “UV mapping an image” or something like that.
  • Typo in UV chapter: “Experiment and see what you come up.” (missing “with”)
  • “non-cubic bounding box” is not a great name for the test in the bounding box chapter; maybe “bounding box not centered at origin” would be clearer.

Most Liked

PetroCoder

PetroCoder

In these two tests (p222 and p223):

Scenario: A smooth triangle uses u/v to interpolate the normal
  When i ← intersection_with_uv(1, tri, 0.45, 0.25)

Scenario: Preparing the normal on a smooth triangle
  When i ← intersection_with_uv(1, tri, 0.45, 0.25)

The first parameter t should be qual to 2. The ray intersects the triangle at distance 2, according to my calculations. Could this be an error?

jamis

jamis

Author of Mazes for Programmers and 1 other title

Hello!

For these two tests, there are no rays being cast—all we’re doing here is creating an intersection record which we’re arbitrarily saying exists at t=1. You could set t=2, but it would make no difference, because the normal calculation is independent of t. For these smooth triangles, the only parameters that matter are u and v (and, of course, the triangle itself).

Does that make sense? Is there something I could be describing better?

Thanks!

Jamis

PetroCoder

PetroCoder

Hi Jamis,

Thank you for this explanation. It makes perfect sense. In my code, I am also checking (just in case) that all parameters of the intersection are “consistent”, i.e. that there is indeed an intersection with the object at a given value of t. That is why I have spotted this case.

Kind regards,
Petro

Popular Prag Prog topics Top

sdmoralesma
Title: Web Development with Clojure, Third Edition - migrations/create not working: p159 When I execute the command: user=&gt; (create-...
New
mikecargal
Title: Hands-On Rust (Chapter 11: prefab) Just played a couple of amulet-less games. With a bit of debugging, I believe that your can_p...
New
herminiotorres
Hi @Margaret , On page VII the book tells us the example and snippets will be all using Elixir version 1.11 But on page 3 almost the en...
New
conradwt
First, the code resources: Page 237: rumbl_umbrella/apps/rumbl/mix.exs Note: That this file is missing. Page 238: rumbl_umbrella/app...
New
alanq
This isn’t directly about the book contents so maybe not the right forum…but in some of the code apps (e.g. turbo/06) it sends a TURBO_ST...
New
brunogirin
When running tox for the first time, I got the following error: ERROR: InterpreterNotFound: python3.10 I realised that I was running ...
New
jonmac
The allprojects block listed on page 245 produces the following error when syncing gradle: “org.gradle.api.GradleScriptException: A prob...
New
EdBorn
Title: Agile Web Development with Rails 7: (page 70) I am running windows 11 pro with rails 7.0.3 and ruby 3.1.2p20 (2022-04-12 revision...
New
bjnord
Hello @herbert ! Trying to get the very first “Hello, Bracket Terminal!" example to run (p. 53). I develop on an Amazon EC2 instance runn...
New
roadbike
From page 13: On Python 3.7, you can install the libraries with pip by running these commands inside a Python venv using Visual Studio ...
New

Other popular topics Top

AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
AstonJ
What chair do you have while working… and why? Is there a ‘best’ type of chair or working position for developers?
New
PragmaticBookshelf
Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
New
Exadra37
I am a Linux user since 2012, more or less, and I always use Ubuntu on my computers, and my last 2 laptops have been used Thinkpads, wher...
New
AstonJ
I ended up cancelling my Moonlander order as I think it’s just going to be a bit too bulky for me. I think the Planck and the Preonic (o...
New
Margaret
Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
New
mafinar
Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
New
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File &gt; New Rule: And select Deny, O...
New

Latest in PragProg

View all threads ❯