

Gloss – A Bidirectional Path Tracer in C - binarycrusader
http://geon.github.io/programming/2013/08/22/gloss-my-bidirectional-path-tracer/

======
kybernetyk
> I have been interested in pure C lately, and I really need to level up my
> experience.

> I wanted to use a object oriented style with constructors and polymorphism.
> Since it isn’t supported directly, you are free to implement it as you feel
> like.

I've been there in the "pure C" land some time ago. I drank all the 'C++ is
shit' koolaid that was spread some time ago all over the net. And I hacked
away quite a few projects in C - with my own implementation of polymorphism,
strings, etc.

But then I got really really tired of it. It's all extra work you don't have
to do in C++. Yes, C++ can be a horrendous mess if you use all features. But
it also offers awesome syntactic sugar for "structs with methods" style
programming.

std::string and vector alone save you so much time. And RAII + shared_ptr will
free up another huge chunk of time you otherwise would have spent thinking
about memory and resource management issues.

I think everyone who's doing C++ work should go C-only for some time just to
appreciate what the lovely monster called C++ actually did for programmer
productivity.

* This is no flame against C. It has its place and I appreciate its existence.

~~~
niuzeta
I actually find it more interesting that you had to postscript which says an
indifferent discourse on your experience on C and C++ was not a flame against
C.

While I agree with your remark wholeheartedly(Yes, C++ has a lot of toolchain,
but no one decreed that you _have_ to use everything in your toolbox), I think
had I written this response, I would've added that defence somewhere. I guess
it's telling how far the C vs C++ discussion went and how long it raged on...

~~~
xyzzy123
C++ advocate here. It doesn't seem to be a strongly represented opinion here,
so I think it's actually worth me chiming in.

All the criticisms are valid. Yes, C++ is like "making an octopus by nailing 4
extra legs onto a dog". None of us like having to remember that we need
virtual destructors if we have derived classes, because otherwise deleting a
class through the wrong derived pointer type would cause complicated problems.
There's a bunch of crap there.

But I spent years coding C and I hate going back.

I miss smart pointers when I'm stuck with C. I miss containers that don't
suck. I miss lame stuff like log4cpp and boost::asio.

If you're willing to accept a bunch of dependencies and can handle serious
(sometimes grevious) conceptual overheads, you can write native code with an
expressiveness approaching Python. To me, that makes it all worth it.

------
thuijzer
Nice writeup!

3D rendering helped me a lot to learn new programming languages because the
visual outcome is more pleasing than seeing "hello world" in your console.

For those interested, here is the source of my Java "path tracer" (with
Blender exporter):
[https://bitbucket.org/thuijzer/thrender001pt/](https://bitbucket.org/thuijzer/thrender001pt/)

Note that I'm not a very good programmer, don't know very much about Java and
math and didn't even know how to program a camera. But Jeffrey Ventrella
helped me with some basics and also his document "Intuitive Computer Graphics
Camera" helped me a lot:
[http://www.ventrella.com/Ideas/index.html](http://www.ventrella.com/Ideas/index.html)

------
berkut
If you're really interested in Raytracing, get hold of the Book "Physically-
based Rendering" by Matt Pharr and Greg Humphreys.

It's pretty-much the bible for raytracing theory at close to production level
rendering, and has pbrt - an open source raytracer - which ships with it which
is a relatively capable renderer, and an excellent example of how to design a
renderer in an object-orientated way.

------
Geee
Same (and more) in real-time:
[http://raytracey.blogspot.co.nz/](http://raytracey.blogspot.co.nz/)

------
tfgg
It looks like low-discrepancy sequences ([http://en.wikipedia.org/wiki/Low-
discrepancy_sequence](http://en.wikipedia.org/wiki/Low-discrepancy_sequence))
might be applicable for your quasi-Monte Carlo sampling of the scattering.

------
Qantourisc
You might be interested in energy conservative BRDF's.

~~~
geon
The BRDF functions I implemented are supposed to be energy conservative.
However, the most important part is the photon importance sampled bouncing,
which is by definition energy conservative.

------
aaren
Thanks, that was fun!

------
c0deporn
Awesome read.

