Live data from Hacker News

Deciphering the Business Card Raytracer

fabiensanglard.net

21–30 of 68 posts

Re: Deciphering the Business Card Raytracer

#21
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…

#define op operator

#define rt return

Then replacing the corresponding inline tokens shaves off another 25 bytes from the source without affecting the output or (arguably) the readability.

Sorry, my inner obfuscator couldn't resist :-)

Beautiful bit of coding, btw.

Re: Deciphering the Business Card Raytracer

#22
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…

How come you decided for a coordinate system with Z pointing up instead of the traditional right hand/left hands coordinate systems ?

Re: Deciphering the Business Card Raytracer

#23
post #21
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…

#define op operator #define rt return Then replacing the corresponding inline tokens shaves off another 25 bytes from the source without affecting the output or (arguably) the readability. Sorry, my inner obfuscator couldn't resist :-) Beautiful bit of coding, btw.

Can you pastebin.com it so we can see what it looks like ?

Re: Deciphering the Business Card Raytracer

#24
post #21
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…

#define op operator #define rt return Then replacing the corresponding inline tokens shaves off another 25 bytes from the source without affecting the output or (arguably) the readability. Sorry, my inner obfuscator couldn't resist :-) Beautiful bit of coding, btw.

#defines have to be one to a line, though - in this case, where you're optimising for layout rather than bytes, i'm not sure it would be a net win. counting, there are 5 instances of "operator", so that's a saving of 36 chars versus 40 taken up by the #define (including the whitespace at the end). there are 10 "return"s, so saving 40 chars there just about draws you even.

Re: Deciphering the Business Card Raytracer

#25
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 ?

Some time ago I wrote a raytracing program in javascript that is supposed to be very simple to understand: https://github.com/antirez/jsrt/blob/master/rt.html

Demo here: http://antirez.com/misc/rt.html

Re: Deciphering the Business Card Raytracer

#26
post #21
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…

#define op operator #define rt return Then replacing the corresponding inline tokens shaves off another 25 bytes from the source without affecting the output or (arguably) the readability. Sorry, my inner obfuscator couldn't resist :-) Beautiful bit of coding, btw.

Thanks, glad you liked it!

Yes, it's true that even more could have been shaved off and I did explore some #defines. As I recall, there were also some other changes I could have made to shave off yet more. Ultimately, I decided against them for two main reasons. First, they'd need to occupy lines by themselves which I felt created a bigger gap at the top that ruined the aesthetics somewhat. I wanted something that would look nice and roughly fill the 1.75 aspect ratio of a typical US business card. Secondly, as noted in my reply to matthew-wegner below, I'd noticed the file size that I had achieved.

Re: Deciphering the Business Card Raytracer

#27
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…

How come you decided for a coordinate system with Z pointing up instead of the traditional right hand/left hands coordinate systems ?

Actually, Z-up coordinate systems can also be called right or left handed depending on which way Y points. :-)

But really, it was just personal preference. Way back when I was learning 3D graphics, I found it easiest to visualize Z as elevation above the XY plane. I'd also used some software that followed that convention (like trueSpace and later 3D Studio Max).

These days, I mainly work with software that tends to favor a Y-up convention by default.

Re: Deciphering the Business Card Raytracer

#28
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…

How come you decided for a coordinate system with Z pointing up instead of the traditional right hand/left hands coordinate systems ?

In non-programming math contexts, it's pretty standard for Z to point up. I have no idea why, as it seems to me like the typical way it works in graphics programming is the more obvious extension of 2D plotting into 3D.

Re: Deciphering the Business Card Raytracer

#29

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.

Graphic Converter can open PPMs, and that used to ship with every Mac. That's probably what you used.

Re: Deciphering the Business Card Raytracer

#30
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 ?

You're welcome!

Scratchapixel was new to me, so thanks for that link. PBRT (which you already have) is definitely a favorite. You also cited Graphics Gems IV but I enjoy dipping into all of them. Other suggestions:

* http://tog.acm.org/resources/RTNews/html/ (Somewhat dead, but the archives are great)

* http://ompf2.com/ (Active, lots of ray tracing specific discussion)

* http://www.realtimerendering.com/ (I'm fond of the book as well)

* http://kesen.realtimerendering.com/ (Especially the sections for "Symposium on Interactive Ray Tracing" and it's successor, "High Performance Graphics")

If I had to pick one, though, it'd be PBRT since it's a unified work that starts from the ground up.

Post reply on HN