smallpaint

by károly zsolnai - zsolnai@iit.bme.hu

smallpaint

 

this is a renderer program implementing the classic monte carlo path tracing global illumination algorithm. looking at the above picture you may not see what you would expect from a such a renderer: it has an interesting look which resembles the viewer of a painting (full size image). please meet smallpaint.

features

scene description

you can freely alter the scene description (or even build a new one) by adjusting the following attributes:

add(new Sphere(1.05, 			// radius
		Vec(1.45,-0.75,-4.4)),  // position
		Vec(4,8,4), 		// color
		0, 			// emission
		2);			// type (1=diff, 2=spec, 3=refr)       

add(new Plane(2.5,			// position
		Vec(-1,0,0)),		// normal
		Vec(6,4,6),		// color
		0,			// emission
		1);			// type  

usage

you can compile the program using >=gcc-4.5.0 (or lower with the more compatible version at the downloads), and it has also been tried out in VS2010 with success, though it's built-in OpenMP library may have compatibility issues.

 g++ smallpaint.cpp -O3 -std=gnu++0x -fopenmp

...or my personal preferred command line:
g++ smallpaint.cpp -O3 -std=gnu++0x -ffast-math -msse -msse2 -msse3
-msse4 -Wall -Wextra -funroll-loops -static-libgcc -static-libstdc++
-fopenmp -fno-exceptions -fno-rtti -pedantic && a && ray.ppm

knobs and switches


what's causing this?

the cause of the painterly look is actually a bug - there's an incorrect usage of the Halton-series with correlating dimensions, and the errors are spread throughout the screen with an equally wrong sampling function. one would wish that every bug could look just as beautiful as this one.

how to fix it? - new!

just change the following line:

                 - ray.d = (N+hemisphere(hal.get(),hal2.get()));
                 + ray.d = (N+hemisphere(RND2,RND2));

Please note that the painterly version still lacks a lot of important features (Schlick's approximation to the Fresnel-equation, Russian Roulette path termination and such), which are included in a separate source file in the package.

important note

if you take a closer look at the source code, you may notice that the program doesn't do any kind of tone mapping - it directly writes the measured values into the image file. also, there are some magic constants used as scaling factors here and there.

when doing ray tracing, the goal is to compute the radiance returning to the eye along rays of light through each pixel of an image. as a last step, we map these values to - for example - RGB values for visualization. trying to measure RGB values directly does not make any sense, and is also scientifically unacceptable. the reason for omitting this from smallpaint is solely to save a few lines of code. your computer graphics professor would probably be throwing lightning bolts at you for this.

changelog

fixes @ 2010.11.11  


fixes @ 2013.03.08  


fixes @ 2013.05.11 - new!  


fixes @ 2013.05.18 - new!  


download

get the code from here and have a lot of fun! It also contains the fixed version of the code with more added features.

Please note that the painterly version still lacks a lot of important features (Schlick's approximation to the Fresnel-equation, Russian Roulette path termination and such), which are included in a separate source file in the package. It also has a substantial amount of comments added.

thanks to