8 ms·
Deciphering the Business Card Raytracer
- dinkumthinkum 13y agoVery nice article and straight to the point. It's really nice to see a pithy discussion and impressive demonstration.
- jevinskie 13y agoWould the wasted empty space in a #define return <pick a single character> make up for the several return statements that I see? That is why typedef statements are nice, you can ; terminate them!
- Rangi42 13y agoThe original ended on line 35, column 28. By #defining return as u, it ends at line 35, column 19. Although I had to split the number 231184 across two lines (2311\84) to avoid a gap at the end of the line. http://pastebin.com/6rM895SC http://pastebin.com/6rM895SC
- matthew-wegner 13y agoThe original is also 1337 bytes, which might explain any padding!
- a_e_k 13y agoGuilty as charged! I stopped trying to minimize it when I noticed that.
- milesf 13y agoThe 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?
- gilgoomesh 13y agoThe 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 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.
- tnorthcutt 13y agoFWIW I was not able to open it with Preview on OS X 10.8
- gilgoomesh 13y agoEep, 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.
- milesf 13y agoAh. LibreOffice's Drawing program opened it. Thanks :)
- eridius 13y agoGraphic Converter can open PPMs, and that used to ship with every Mac. That's probably what you used.
- ubernostrum 13y agoOr just install ImageMagick, and do 'convert card.ppm card.png'.
- Sharlin 13y agoIf you have IM, just use 'display' to open it directly.
- chrissnell 13y agoIf 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-converter.html 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 https://gist.github.com/chrissnell/6656963
- logicallee 13y agothanks. what exactly were you referring to with "I probably could have coded this in the time that it took me to draw my initials in binary pixels."?
- chrissnell 13y agoI could have coded something to generate customized versions of the original source, given three ASCII initials.
- logicallee 13y agoCome on, Chris. I'm a big fan of the humblebrag, but you would still have to draw the binary pixel version of each letter (because C doesn't come with binary pixel array versions of the 26 letters) - so it would be 8 times as much work at an absolute minimum (26 characters versus the 3 that you did), even if the code to embed them in the array were a completely obvious 1-liner, and so was the code to clean up the justification. Let's not flatter ourselves :)
- eaxitect 13y agoThis is really single piece of sh*t I like most for a while... simple and elegant
- a_e_k 13y agoHi 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.
- fabien_sanglard 13y agoThanks 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 ?
- antirez 13y agoSome 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 https://github.com/antirez/jsrt/blob/master/rt.html Demo here: http://antirez.com/misc/rt.html http://antirez.com/misc/rt.html
- Uchikoma 13y agoNice! We did a real time raytracer with 2 spheres where you could move around one with C and a cluster of DEC Alphas 20 years ago, funny to see this on my laptop in Javascript (!) now.
- 13y ago
- ggambetta 13y agoI love this kind of thing. I've made a similar one (minus texturing) in Javascript, drawing to a Canvas; my current version is 975 bytes. Output, full source and live demo here: http://gabrielgambetta.com/tiny_raytracer.html http://gabrielgambetta.com/tiny_raytracer.html
- thenomad 13y agoAlong the same lines, albeit much less compact - a 99-line Path Tracer (the next evolution from a straight-up raytracer, performing global illumination calculations): http://www.kevinbeason.com/smallpt/ http://www.kevinbeason.com/smallpt/
- xioxox 13y agoI like this extremely short postscript raytracer I saw quite a few years ago: http://www.is.titech.ac.jp/~sadayosi/lab/h-takasi/ops.html http://www.is.titech.ac.jp/~sadayosi/lab/h-takasi/ops.html %!IOPSC-1993 %%Creator: HAYAKAWA Takashi <h-takasi@is.titech.ac.jp> /C/neg/d/mul/R/rlineto/E/exp/H{{cvx def}repeat}def/T/dup/g/gt/r/roll/J/ifelse 8 H/A/copy(z&v4QX&93r9AxYQOZomQalxS2w!!O&vMYa43d6r93rMYvx2dca!D&cjSnjSnjjS3o!v&6A X&55SAxM1CD7AjYxTTd62rmxCnTdSST0g&12wECST!&!J0g&D1!&xM0!J0g!l&544dC2Ac96ra!m&3A F&&vGoGSnCT0g&wDmlvGoS8wpn6wpS2wTCpS1Sd7ov7Uk7o4Qkdw!&Mvlx1S7oZES3w!J!J!Q&7185d Z&lx1CS9d9nE4!k&X&MY7!&1!J!x&jdnjdS3odS!N&mmx1C2wEc!G&150Nx4!n&2o!j&43r!U&0777d ]&2AY2A776ddT4oS3oSnMVC00VV0RRR45E42063rNz&v7UX&UOzF!F!J![&44ETCnVn!a&1CDN!Y&0M V1c&j2AYdjmMdjjd!o&1r!M){( )T 0 4 3 r put T(/)g{T(9)g{cvn}{cvi}J}{($)g{[}{]}J}J cvx}forall/moveto/p/floor/w/div/S/add 29 H[{[{]setgray fill}for Y}for showpage
- szc 13y agoThere are two other small ray tracers that can be examined. Both are winners of the International Obfuscated C Code Contest. Matt Zucker won in 2011 and Anders Gavare won in 2004. They can be found here, http://www.ioccc.org/years-spoiler.html http://www.ioccc.org/years-spoiler.html (The 22nd IOCCC is open for entries until 2013-Oct-03)
- kid0m4n 13y agoThe same thing, implemented in Go: https://github.com/kid0m4n/gorays https://github.com/kid0m4n/gorays
- chii 13y agoIt looks like his site is taken down due to bandwidth limit reached. Use http://webcache.googleusercontent.com/search?q=cache:http://fabiensanglard.net/rayTracing_back_of_business_card/index.php http://webcache.googleusercontent.com/search?q=cache:http://... till it's back up.