In raytracer news, I made a couple of improvements. First, raytracing is scripted via a render() function, so I can no generate animation sequences. Secondly, raytracing is now multithreaded. Since all the scene objects are constant, and the only non-constant thing is the output buffer, it works pretty well with multithreading. It defaults to one worker thread per CPU, but you can override that if you want. There's a noticible improvement with 2 threads (I'm on a dual core CPU). I also got silly and set it to create 400 threads, and it got 44% of the way through rendering before it had even finished creating all the threads (And then crashed because WaitForMultipleObjects() can only cope with 64 handles at once).
So, I made a little video that loops over, changing the refractive index of a sphere from 0.5 to 1.5, in steps of 0.01. Here's the script:
-- Set camera (pos, lookat, up, fov (Degrees))set_camera({0, 0, -9}, {0, 0, 1}, {0, 1, 0}, 45);-- Set quality params (samples per pixel, reflection depth, [num worker threads])set_scene_params(1, 10);-- Create directional lights (dir, colour)create_directional_light({1, 0, 5}, {1, 1, 1});-- Create point lights (pos, colour, intensity)create_point_light({0, 5, 5}, {0.4, 0.4, 0.4}, 0.1);create_point_light({-3, 5, 1}, {0.6, 0.6, 0.8}, 0.1);-- Init objects (colour, diffuse, specular, reflection, refraction, absorbance, refractive idx)name, obj = create_sphere({-0.5, -0.5, 4}, 0.4);create_object(name, obj, {1.0, 1.0, 1.0}, 1.0, 0.8, 20, 0, 0, 0, 0);name, obj = create_sphere({-0.5, 0.5, 4}, 0.4);create_object(name, obj, {1.0, 1.0, 1.0}, 1.0, 0.8, 20, 0, 0, 0, 0);name, obj = create_sphere({0.5, -0.5, 4}, 0.4);create_object(name, obj, {1.0, 1.0, 1.0}, 1.0, 0.8, 20, 0, 0, 0, 0);name, obj = create_sphere({0.5, 0.5, 4}, 0.4);create_object(name, obj, {1.0, 1.0, 1.0}, 1.0, 0.8, 20, 0, 0, 0, 0);name, obj = create_plane({0, 1, 0}, 4.4);create_object(name, obj, {0.4, 0.3, 0.3}, 1.0, 0, 20, 0, 0);name, obj = create_plane({0.4, 0, -1}, 12);create_object(name, obj, {0.5, 0.3, 0.5}, 0.6, 0, 20, 0, 0, 0, 1);name, obj = create_plane({0, -1, 0}, 7.4);create_object(name, obj, {0.4, 0.7, 0.7}, 0.5, 0, 20, 0, 0, 0, 1);refIdx = 0.75;nImg = 0;for i=0.5, 1.5, 0.01 do name, obj = create_sphere({0, 0, 0}, 2); objSphere = create_object(name, obj, {1.0, 0.5, 0.5}, 0.2, 0.8, 20, 0.0, 0.8, 0.1, refIdx); set_output_file(string.format("out%03d.bmp", nImg), 640, 480) render(); delete_object(objSphere); nImg = nImg + 1; refIdx = refIdx + 0.05;end
And here's the video (DivX codec)
Next up are textures I think. That should be pretty simple (Maybe). I should really optimise the scene by using some sort of spatial partitioning, but I can't really be bothered. Maybe once I get annoyed with it being so slow at rendering [smile]
EDIT: And yep, I'm an idiot again. The code doesn't give refractive indices of 0.5 to 1.5, it's 0.5 to 5.5 [sad]