I probably made some mistakes in the math + this code isn't suppost to be scalable, but it works and I'm happy about that! The SPP slider (Samples Per Pixel) decides how many Rays you shoot out per Pixel, which adds an Antialiasing effect (also I'm probably gonna make a more scalable version soon which will have actual Path Tracing)
it is recommended to turn on Turbo Mode by holding Shift and pressing the green flag! You can also use Turbowarp, to see how much faster it would be if Scratch decided to use a Compiler instead. You can find a Link here: https://turbowarp.org/870317111/fullscreen?turbo&hqpen (I would recommend using above 1 spp because it will become bugged with the higher quality pen)