Week #5

14 07 2008

Last week the code was simplified, with the intention for it to work as a simple ray tracer. The view_pixel() function was pretty simple, something like if it hits, paint it black, else paint it white. Frame buffer set and the first images consisted of three, equally spaced lines. There was something wrong.

Further hacking in view.c and I found that the pixel width was a problem. When it was set, in view_2init(), the first images were shrinked horizontally, but that was some bug with ap->a_x not being multiplied by pwidth. This was the result:

D
First Rendering. This is a cube 😀

Next step – flat shaded images. Back to hacking view.c.

At first I thought it had something to do with kut_planes (because RT_HIT_NORMAL was there) so I tried to use it, but only got segmentation errors. After I realized that handling normals shouldn’t be optional (there was a big if (do_kut_plane) block), I found out how to use RT_HIT_NORMAL (and there needed to be a for loop, to find valid partitions), that code was used and this happened (also, color identification was moved back to rayhit() and view_pixel() just handled ap->a_color):

Isnt that a beautiful cube?

Isn't that a beautiful cube?

That was a big motivation for me.

Rayhit() wasn’t saving the hit points properly – when it got to the memory de-allocation, in view_end(), rtmlt crashed. So, in order to create those images, that part of the code was commented and I only gave some attention to that after the flat shaded images. It was leaking big chunks of memory per rendering, but now it is fixed and the paths are being recorded. But not correctly – currently, it saves every point in a single path (the point recording is important for path tracing, this will be changed in the coming weeks).

Also, allocating memory in each rayhit() function is a problem – performance will be much better if the allocation is done somewhere else, as Sean mentioned. Another thing pending is the file writing, that was cut in order to create the images (in the three lines days, it created a 128mb file).
Moving on to path tracing now.