Live data from Hacker News

Deciphering the Business Card Raytracer

fabiensanglard.net

11–20 of 68 posts

Re: Deciphering the Business Card Raytracer

#11
post #4

The output file is .aek but I can't figure out what to do with it. My Google-fu is failing me this evening. How do you view the output?

The output is PPM, not AEK (that's Andrew Kensler's initials). Use PPM as the extension (similar to PGM, PNM and others http://en.wikipedia.org/wiki/Netpbm_format ). It's not very common in consumer products (too primitive) but you can open in Gimp, Preview.app, IrfanView, XV and lots of others.

FWIW I was not able to open it with Preview on OS X 10.8

Re: Deciphering the Business Card Raytracer

#12

Earlier quoted context omitted.

The output is PPM, not AEK (that's Andrew Kensler's initials). Use PPM as the extension (similar to PGM, PNM and others http://en.wikipedia.org/wiki/Netpbm_format ). It's not very common in consumer products (too primitive) but you can open in Gimp, Preview.app, IrfanView, XV and lots of others.

FWIW I was not able to open it with Preview on OS X 10.8

Eep, my mistake. You're right: it doesn't work. I thought I used to open PPMs with Preview back in Mac OS 10.3 or something else ancient. I could be mistaken on that.

Oh well. Everyone has Gimp and LibreOffice installed though, right? They both open the file without problems.

Re: Deciphering the Business Card Raytracer

#13
post #9
post #4

The output file is .aek but I can't figure out what to do with it. My Google-fu is failing me this evening. How do you view the output?

If you're using Linux or OSX, run it like this: ./aek > aek.ppm That will produce an image in .ppm format. ('The world's second-dumbest picture format.') You'll probably have to convert it to a more widely supported format. Make sure you have the netpbm package installed, and then run, say: pbmtopng aek.ppm > aek.bmp

The correct command is actually pnmtopng, FWIW.

Re: Deciphering the Business Card Raytracer

#14
If you want to make your own, like Fabian Sanglard did, take this block of binary numbers and draw your initials (left-justified) with 1's:

  0001110000010001110
  0010000000000010000
  0100000000010010000
  0100000000010001100
  0100000000010000100
  0010000010010000010
  0001110001100011100
That's my initials, cjs. If you unfocus your eyes, you can see the letters pretty clearly.

Take each line, top to bottom, and convert to decimal:

http://www.mathsisfun.com/binary-decimal-hexadecimal-convert...

Edit Paul Heckbert's code (lines 12-13, the "G" array), replacing the numbers from right to left with the decimal values. In other words, the last number in the array is the top line of the binary block above.

Clean up the justification and you have your business card raytracer, courtesy of Mr. Heckbert.

I probably could have coded this in the time that it took me to draw my initials in binary pixels.

Also, here's a version with the camera moved slightly farther out so that the letters don't clip:

https://gist.github.com/chrissnell/6656963

Re: Deciphering the Business Card Raytracer

#16

Earlier quoted context omitted.

FWIW I was not able to open it with Preview on OS X 10.8

Eep, my mistake. You're right: it doesn't work. I thought I used to open PPMs with Preview back in Mac OS 10.3 or something else ancient. I could be mistaken on that. Oh well. Everyone has Gimp and LibreOffice installed though, right? They both open the file without problems.

Ah. LibreOffice's Drawing program opened it. Thanks :)

Re: Deciphering the Business Card Raytracer

#18
Hi there, code author here. I've been lurking here for years, but couldn't resist an invitation like this.

I've always enjoyed Fabien's analyses so it's great fun to see what he makes of my own code. Anyway, a few clarifications from what I remember of this. (I wrote this '09, and I don't have my old notes in front of me right now):

* The `n` value returned by the trace function, `T()`, is the surface normal. It returns this whether it hit the plane or a sphere.

* The `r` vector in `S()` is the reflection vector off whatever was hit.

* The mystery `c` point in the `main()` function is the offset from the eye point (ignoring the lens perturbation `t`) to the corner of the focal plane. Note below that we're nominally tracing rays for pixel (x,y) in the direction of ax+by+c. At the image midpoint, this should be `g`.

* "although I suspect this to be a side effect: This is not how soft-shadows are done." True. There are true soft shadows in this, but this isn't where they're computed. That's the job of the randomization where `l` is computed in `S()`.

Anyway, please feel free to ask any questions about it.

Re: Deciphering the Business Card Raytracer

#19

Would the wasted empty space in a #define return make up for the several return statements that I see? That is why typedef statements are nice, you can ; terminate them!

The original is also 1337 bytes, which might explain any padding!

Guilty as charged!

I stopped trying to minimize it when I noticed that.

Re: Deciphering the Business Card Raytracer

#20
post #18

Hi there, code author here. I've been lurking here for years, but couldn't resist an invitation like this. I've always enjoyed Fabien's analyses so it's great fun to see what he makes of my own code. Anyway, a few clarifications from what I remember of this. (I wrote this '09, and I don't have my old notes in front of me right now): * The `n` value returned by the trace function, `T()`, is the surface normal. It retu…

Thanks Andrew, that 'c' variable was giving me a headache ;) ! I have updated the article with your remarks.

BTW, I have listed a few good resources about raytracing at the bottom of the page: Do you know any other good books/websites ?

Post reply on HN