** Use Turbo Mode (<Shift> key + Green Flag) ** This Raytracer project shows 3 spheres. The green sphere is partly inside the blue sphere! A "Ray Tracer" traces rays from the viewer through each pixel on the screen and calculates which object it hits first in 3D space (ie. which object is closest). The pixel is coloured with the colour of that object. More advanced Ray Tracers add different types of lighting, shadows and reflections of other objects. They also include not just spheres (which have easier math) but other 3D objects. The Math for this Project --------------------------------- With pen and paper I worked out where a ray from the viewer intersected each sphere. I used a parallel projection where the viewer looks straight at all pixels on the stage (ie. looks parallel to the Z axis) to keep the math simpler. The equation of a sphere at the origin is: x^2 + y^2 + z^2 = r^2 As rays are parallel to the Z axis, a ray through (x,y) on the stage intersects the sphere at: x, y, and z = sqrt (r^2 - x^2 - y^2) Inside the project, this equation is easily adjusted for spheres not being at the origin.
* My second Ray Tracer with some lighting will be: https://scratch.mit.edu/projects/382631103/ * Huge thanks to @Geotale (14 years old). After always thinking that raytracing projects would be too hard, I was inspired by their project: "How to Make Your Own Raytracer" https://scratch.mit.edu/projects/377006401 @Geotale also made part 2 including lighting and shadows: https://scratch.mit.edu/projects/377492127/ I have yet to try shadows. Wikipedia - Ray Tracing: https://en.wikipedia.org/wiki/Ray_tracing_(graphics)