So my "project" after chapters 4 & 5 was a simple ray tracer that allows configuring rendering options via menus. It currently only supports spheres (cause they're easy), and supports diffuse and specular shading, as well as reflections, basic shadows, and basic refraction/transparency. Refraction/transparency doesn't look quite right, so I've probably got a bug in there somewhere, but it's honestly too slow to be practical anyways
Also, it exclusively uses fixed-point numbers (as opposed to floating-point). I kind of just did that for grins...I don't know if it's any faster than it would have been with floating-point math (obviously the floating-point capabilities of the machine would play into that), especially since several of the fixed-point math functions I'm currently using are very very sub-optimal. I also haven't put much effort into optimizing the rendering code. Still, it's a neat toy project that I can augment as I work my way through the rest of the book by adding things like file I/O, etc (the PICT-related menu options don't currently do anything for example). Also, the scene with the four spheres is currently hard-coded, so the ability to specify or import scene definitions would be another thing I could add.
This was developed entirely on an 040-accelerated IIci with a RasterOps PaintBoard Prism GT video card for 24-bit color support. The included code has only been built with ThinkC 6, and I'm not sure how portable the project file is. Still, you can always just make a new project file and link all the .c files and the MacTraps lib. Add some more spheres! Change material properties! Go nuts and make your mac melt! A built executable is also included.
Note, by default, all of the optional render features are ON, and the number of recursive ray bounces is MAXED. I recommend turning everything off/down before hitting "Render" for the first time and then incrementally enabling things unless you want to sit there forever (it's pretty fast under Basilisk II though). Shrinking the window will also reduce the render time (fewer pixels = fewer rays). Don't drag anything over your rendered image either after waiting for it to complete...this currently draws directly to the window's graphics port, so there's no offscreen rendering available to repaint the window
Resizing the window will also clear the current rendered image. Also, it'll obviously look best in "millions" of colors if your machine can do it, but "thousands" or 256 will just have the usual banding.
RayTracer.sit.hqx was created with Stuffit Deluxe 4.5.
View attachment 9368 View attachment 9369 View attachment 9370 View attachment 9371