I like the walls made of spheres! The real Cornell box is about 2 feet cubed IIRC... that would make the units of this scene file something close to centimeters... which would mean the walls are spheres with a diameter of about 1.2 miles.
Last time I saw the box in person, I made sure to leave some fingerprints. :P
> Realistic Ray Tracing, by Peter Shirley
> Almost 100% of smallpt is derived from this book.
FWIW, Peter Shirley distilled all the fun parts of Realistic Ray Tracing into an easy quick e-book available for $3, or free with the trial. "Ray Tracing in One Weekend."
I don't understand the fascination with writing/presenting the code with as few lines as possible. I'd be just as impressed if they said the code was 120 lines and formatted so it was just a bit more pleasant to read.
I've recently had to deal with some code that did this for work (and also used operator* for dot product) and it made the equations incredibly difficult to read. Please don't make the mistake of doing this in your own code.
This a good example of the kind of computational tasks that have me staying on the top of the line of the latest generation of intel's desktop chips, and overclock them when I'm running compute intensive stuff.
If I want to try out something new like this and play around with it, I want it to be snappy.
I am vehemently opposed to the idea that PC's are "fast enough" -- more speed, less waiting!
The only compromise I make is avoiding the extreme versions of their chips, as they can almost $1,000 more. But in the future I might change my mind on that.
Very cool with small code pieces that does a lot. I was a big fan of the Amiga Boot sector intro's back in the 80-90s where the programmers had to make entertaining pieces of digital art where compiled code, music, and graphics all had to fit inside 1 KB boot sector of a 3.5" floppy disks. Here are some examples https://www.youtube.com/watch?v=GPTkTobvsaw&list=PLDAE2D6D92... . Thanks for sharing! :)
I personally wish the code was just written cleanly and idiomatically. I wouldn't mind "300 lines of simple, idiomatic C++". What's the use of making code dense if you're going to reformat it anyway?
(I say this in contrast to something which was explicitly "code golfed", which this code seems not to be.)
I actually went through that exercise if anyone is interested.
It ended up at probably 500 lines at first, and then 800 or so lines because I tried to port it to CUDA. It was mainly an exercise in learning CUDA -- i.e. how is CUDA different than C++? I got something running on my graphics card, but it didn't completely work and I moved onto other things.
I haven't run this code since 2015 but I did have a lot of fun learning from it.
It's written in a similarly condensed style. I'm inclined to agree with you at first, but honestly I find that reformatting code helps me get a feel for it! It is a mechanical exercise that reminds you of everything that's there. Going through and renaming functions and types to "your style" seems kinda frivolous but it actually helps IMO.
I understand production and community code demands a most simple format but for me this program is just a few braces and vertical breaks short of perfection.
Simple, right? I can see how it would look like garbage if you miss the three separate variables being initialized, but that should be familiar to most people with C/C++ experience.
No its fine and Im certainly no genius. I just dont need whitespace to 'reinforce' code expression - its a visual familiarity thing, quite a general reading skill.
The only confusing thing in this line is the % operator being overloaded on Vecs to mean the cross product. What the calculation is actually for is what takes time to grok, but you cant expect that to be revealed by familiar formatting and expansive variable names.
It's easy to read through the parts of the PBRT[0] book that Smallpt implements in an afternoon. Of course, PBRT also implements a bunch of other stuff Smallpt doesn't which you can skip until you're ready.
PBRT was created for pedagogical reasons and has very easy to follow code with full documentation of everything relevant. Smallpt is designed to be super small and doesn't really say why it works; PBRT does.
As a bonus, a lot of other physically-based renderers you'll find on GitHub follow PBRT's overall architecture closely (such as Embree[1]), so they're also easy to read/understand if you already know PBRT.
Looks like it would make a nice glsl/WebGL fragment shader (might be even shorter as the vector operations are predefined). Can't see one listed on the page, but then it's mostly from a few years back.
Great work and thanks for sharing the source! I love when I can see the output from someone's program, get the source code, compile it myself and then get the same results! :)
3325. I'm not quite sure why you're asking. This isn't about the size of the library, it's about the lines of code the programmer needs to write to express an idea.
If you are concerned about the size of the final binary, then as the author states, it's under 4k with a few optimizations.
It's the standard library. It's not a library for graphics. Might as well credit your OS as well for providing a kernel that runs the program, and your CPU manufacturer for making a CPU that executes the instructions.
If someone claimed "a string formatting tool in 2 lines of C++" and it was just fprintf, that's clearly the standard library doing the work, not the promoted file. In this case the standard library is not doing any global illumination or anything related. It's just doing IO.
'Except as noted in Clauses 18 through 30 and Annex D, the contents of each header c name shall be the same as that of the corresponding header name .h, as specified in the C standard library (1.2) or the C Unicode TR, as appropriate, as if by inclusion'
Among other bits. It's made very clear that the standard libraries are valid 'C++'.
Even that aside, here are the used symbols from those libs:
atoi
fopen
FILE
fprintf
M_PI
fabs
sqrt
cos
sin
erand48
Which are all resonable functionality to expect in any programming environment. The first 4 are only used for I/O which are not exposed in the language otherwise. And can also be safely removed and "GI" still functions. It's just nice to be able to see the result.
The rest of the math functions are generally replaceable with varying amounts of code or by calling platform native instructions.
The only real stand out is erand48 which isn't actually part of the standard, but is easily replaceable by many other standard pseudo random implementations something like 'double erand48(){return (double)rand()/(double)MAX_RAND;}' or some such, or by implementing one of many pseudo random number generators.
In all, it's very fair to consider this 99 lines of C++ all the algorithmic components of a path tracer are shown in the code. External code is well within expectations. And there is no reason to consider the usage of stdio.h as something to be counted, while discounting all the code that goes into actually compiling and executing the code. Where the line is now is the most obvious place to draw it and where all sane C++ programmers would.
The part where it references what someone else wrote is the 'of C++' part. The C++ language standard describes the standard library. The OpenMP enhancements aren't actually required (the code will compile as standard C++).
As such, it's pretty pure C++ really and anyone who writes the language commonly will understand what is meant.
Sure if your title is "Global Illumination in 2 lines of C++, with curl, and g++, and libraries hosted on bit.ly". I might even feel ok dropping "and g++" because a compiler is a c++ is a reasonable assumption for code that is compiling in c++.
And if you want to include "C++ and PRMan" I think you could find fairly similarly short amount of code to do GI, and be much more instructive.
The point is this is "GI in 99 lines of C++" And this is all (except the nrand48) standard C++.
Last time I saw the box in person, I made sure to leave some fingerprints. :P
> Realistic Ray Tracing, by Peter Shirley > Almost 100% of smallpt is derived from this book.
FWIW, Peter Shirley distilled all the fun parts of Realistic Ray Tracing into an easy quick e-book available for $3, or free with the trial. "Ray Tracing in One Weekend."
https://www.amazon.com/gp/product/B01B5AODD8/
Blog post about it w/ more code & lots of resources: http://in1weekend.blogspot.com/2016/01/ray-tracing-in-one-we...