One of the few real-time raytracers made entirely in Scratch w/ dynamic camera movement!
This project ONLY works in TurboWarp!
https://turbowarp.org/1110113480
WASD to move on X and Z axes
Up and down arrows to move on Y axis
All logic & math done by me.
-------------------------------------------------------------------------
How it works:
-------------------------------------------------------------------------
First I made a quick framebuffer system where 300 clones are made (because clones can run in parallel and therefore a frame can be drawn in a single frame) and each clone is assigned a region of exactly 576 pixels to draw (resulting in the entire 480x360 screen being drawn at the same time)
Once all clones receive a message to start drawing, it repeats a section of blocks 576 times that casts a ray in the direction of their assigned pixels and returns an RGB color, then takes that resulting color and sets it to the pen color, then does pen down & pen up very quickly (which draws 1 pixel exactly)
For the block that casts a ray, it first finds the closest sphere relative to that pixel, then checks its material and handles it (glass is done by simulating reflection & refraction), then applies diffuse shading & checks if the point is in a shadow (if it is, then lowers the color dramatically)
-------------------------------------------------------------------------
Time to make:
-------------------------------------------------------------------------
2 days of work for getting the raytracer itself to work, 3 days of getting the pixel buffer system to work + optimize it, 2 days to add skybox + glass (7 days total work)