5 ms·
Deciphering the postcard-sized raytracer
- justinfrankel 8y agoThis 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).
- saagarjha 8y ago> main() is the one symbol that cannot be obfuscated since it is called by libc's _start function Who needs libc ;)
- chrisseaton 8y ago> Who needs libc This program does, for multiple things, regardless of how the entry point works.
- saagarjha 8y agoNo program needs libc. Most could use it, though.
- chrisseaton 8y agoThis program uses for example printf, which is provided by libc, so it needs some form of libc to run.
- saagarjha 8y agoIt’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 8y agoThis 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 8y agoThat’s my argument: it probably could; I think it would be a dozen or so more characters.
- chrisseaton 8y agoEven 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.
- userbinator 8y agoThere 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/distfunctions.htm https://iquilezles.org/www/articles/distfunctions/distfuncti...
- EvanAnderson 8y agoThe POVray ray tracer uses CSG in its scene descriptions as well. CSG is a really neat way to visualize objects mentally, too.
- snazz 8y agoFor 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
- snazz 8y agoOh, and of course the 2KB flight simulator: https://news.ycombinator.com/item?id=15058723 https://news.ycombinator.com/item?id=15058723
- userbinator 8y agoFabrice 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
- miguelrochefort 8y agoThis reminded me of these concise REBOL examples: https://easiestprogramminglanguage.com/easiest_programming_language.html https://easiestprogramminglanguage.com/easiest_programming_l...
- sxp 8y agoThe 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.
- ilaksh 8y agoIs the new 'ray tracing' support from Nvidia ray tracing or is it path tracing?
- mattnewport 8y agoIt'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 8y agoTo 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.
- flafla2 8y agoFunny 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/d2f44c9e5e5a0ff13e6071fb782daa38 https://gist.github.com/Flafla2/d2f44c9e5e5a0ff13e6071fb782d... 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 8y agoTotally no idea. What is the logic behind all these? Is the word 3D model?
- m1el 8y agoThe 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/distfunctions.htm https://iquilezles.org/www/articles/distfunctions/distfuncti...
- userbinator 8y agoIncidentally, 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.