Light and Magic
The next natural step after getting basic shading to work is to have actual light sources, that can be tinted and positioned in the scene.
Enter the PointLight()
and DistantLight()
classes of lights. A point light can be translated to a position, and irradiates the scene spherically from that position, and will be attenuated by distance. A distant light on the other hand, irradiates the scene with parallel rays of light, with the same power, and direction all over (like the fake “camera light”).
Because we can’t have more than one surface in the world at the moment, nothing can obscure the light (cast shadows). Here we have three light sources, yellow above to the left, cyan above to the right, and magenta below in front.
Next related
All the things
One limitation so far was that there could only be one surface in a scene. To get past that, we add the Group meta-surface, that contains a number of surfaces, and intersects with rays on their behalf. To make this actually useful, surfaces also need transforms to translate them out of their shared origin.
Previous related
Working camera
So yesterday’s attempt at capturing an image didn’t turn out so well, because I messed up the camera, or rather the vector algebra behind everything. When I realized what I had done, I instantly remembered that similar lesson from last year; because points have w=1, while vectors have w=0, almost all vector operations will get messed up by the extra 1, if you accidentally use a point instead. Or vice versa.
Actual pixels
First actual image generated, using a “camera light”. The shading is too dark, for some reason I can’t figure out at the moment, so I guess tomorrow will be more of a debugging session than new feature creation.
Pixels on a canvas
Pretty much the whole point of a ray tracer such as this one is to render pretty pictures, and for that we’re going to need a canvas to render onto.