
Deciphering the postcard-sized raytracer - Impossible
https://fabiensanglard.net/postcard_pathtracer/
======
flafla2
Funny story! I'm an undergrad Computer Science student who received this
postcard raytracer from my Pixar recruiter back in November when they visited
my school (CMU). To try and woo my recruiter, I changed the "PIXAR" text to
say "HIRE ME" and sent it back to them. I also called fork() twice before the
render loop to use 4 cores (plus a spooky mmap call to share the memory).

Here's the gist of my modified code (clang-formatted with comments):
[https://gist.github.com/Flafla2/d2f44c9e5e5a0ff13e6071fb782d...](https://gist.github.com/Flafla2/d2f44c9e5e5a0ff13e6071fb782daa38)

And here's what it renders:
[https://i.imgur.com/Yhqt0Le.png](https://i.imgur.com/Yhqt0Le.png)

I didn't end up moving forward with my offer at Pixar, but I had a ton of fun
with this! Super awesome idea, Pixar sure knows how to get computer graphics
programmers thinking.

If anyone is interested in diving deeper into distance field ray marching and
using it in a production game engine, check out my article on the topic here:
[http://flafla2.github.io/2016/10/01/raymarching.html](http://flafla2.github.io/2016/10/01/raymarching.html)

~~~
ngcc_hk
Totally no idea. What is the logic behind all these? Is the word 3D model?

~~~
m1el
The words are defined using Signed Distance Field functions -- a function that
determines the distance to object's surface. It is quite simple to write down
an SDF for primitive objects like cube and sphere, cylinder, torus, then using
negation and min/max you can create unions, intersections and differences of
shapes defined by SDFs.

Inigo Quilez has in-depth explanations and plenty of examples for these:
[https://iquilezles.org/www/articles/distfunctions/distfuncti...](https://iquilezles.org/www/articles/distfunctions/distfunctions.htm)

~~~
userbinator
Incidentally, he also works at Pixar --- and I'm not sure if he was the one
who popularised using SDFs there, because I don't remember seeing this stuff
before he first put up those webpages explaining SDFs.

~~~
Impossible
Inigo Quilez works at Facebook (after Oculus story studio was shut down) and
is the creator/primary developer of the VR art tool Quill
([https://quill.fb.com](https://quill.fb.com)). He quit Pixar in 2014.

------
userbinator
_There are no vertices in the code. Everything is done with CSG functions. If
you are unfamiliar with them, let 's just say that they are functions
describing if a coordinate is inside or outside an object._

I believe this technique was first popularised in the demoscene, because it
makes for some _extremely_ concise procedural descriptions of 3D scenes:

[https://iquilezles.org/www/articles/distfunctions/distfuncti...](https://iquilezles.org/www/articles/distfunctions/distfunctions.htm)

~~~
EvanAnderson
The POVray ray tracer uses CSG in its scene descriptions as well. CSG is a
really neat way to visualize objects mentally, too.

------
sxp
The other interesting raytracer is
[http://www.kevinbeason.com/smallpt/](http://www.kevinbeason.com/smallpt/)
which is a path tracer in 100 lines of 80 column width C.

------
snazz
For anyone else who read the article and is itching for more, the
International Obfuscated C Code Contest[0] (IOCCC) is _the_ place for this
kind of compact, obfuscated trick code. Stuff like [1] reminds me how far I
still have to go with programming.

[0]: [https://www.ioccc.org/years-spoiler.html](https://www.ioccc.org/years-
spoiler.html) [1hint]:
[https://www.ioccc.org/2015/mills1/hint.html](https://www.ioccc.org/2015/mills1/hint.html)
[1code]:
[https://www.ioccc.org/2015/mills1/prog.c](https://www.ioccc.org/2015/mills1/prog.c)

~~~
userbinator
Fabrice Bellard has an entry there too!

[https://www.ioccc.org/2018/bellard/hint.html](https://www.ioccc.org/2018/bellard/hint.html)

I am not surprised what he chose to do. It may actually be the only entry that
uses patented technology.[1]

[1]
[https://news.ycombinator.com/item?id=17587684](https://news.ycombinator.com/item?id=17587684)

------
justinfrankel
This is awesome!

There’s a bug in the deobfuscated version — sizeof(letters) should be 60 or
sizeof(letters)-1 (that version reads past the end of the buffer otherwise).

------
miguelrochefort
This reminded me of these concise REBOL examples:

[https://easiestprogramminglanguage.com/easiest_programming_l...](https://easiestprogramminglanguage.com/easiest_programming_language.html)

------
ilaksh
Is the new 'ray tracing' support from Nvidia ray tracing or is it path
tracing?

~~~
mattnewport
It's hardware accelerated support for tracing rays efficiently. That can be
used to implement a variety of rendering approaches that make use of tracing
rays, including traditional Whitted ray tracing, path tracing and all sorts of
hybrid approaches.

~~~
gmueckl
To be more precise: RTX (like OptiX before it) makes no particular assumptions
about the applications. It concerns itself mostly with fast ray/scene
intersections while user code in the form of very specialized shaders form the
actual rendering algorithms around that core. That makes sense because
constructing acceleration structures and the intersection tests themselves
tend to dominate the runtime for these algorithms unless some particularly
fancy shading is applied to the surfaces.

------
saagarjha
> main() is the one symbol that cannot be obfuscated since it is called by
> libc's _start function

Who needs libc ;)

~~~
chrisseaton
> Who needs libc

This program does, for multiple things, regardless of how the entry point
works.

~~~
saagarjha
No program _needs_ libc. Most could use it, though.

~~~
chrisseaton
This program uses for example printf, which is provided by libc, so it needs
some form of libc to run.

~~~
saagarjha
It’s easy to swap out the limited use of printed in this program, which just
prints strings and integers, with a short loop and a syscall. Like I said,
nobody _needs_ libc; it’s just convenient to use.

~~~
chrisseaton
This program, as it is written, _needs_ libc to run. It would not run without
a libc.

If you wrote a different program, that didn't use libc, then it would not need
libc, that is correct. But would that program fit on a post card?

~~~
saagarjha
That’s my argument: it probably could; I think it would be a dozen or so more
characters.

~~~
chrisseaton
Even the AMD64 instruction names alone for fabsf, sqrtf, powf, fmodf, will add
up to more than a dozen characters. That's before you implement rand and
printf. I'm skeptical.

