Hi! I've been working on a Raytracer on love2d. It is by no means meant to be a very optimized renderer, more like a learning project. But I cannot, for the love of everything holy, get it working. I've successfully made them in C++ using .bmp output, but when I ported it to love2d, the output is not what it should be! Im fairly new to this too so I'm stumped.
Here is the code for the intersection of the ray & the sphere (which I suspect is the culprit to my dilemma):
Code: Select all
-- Function to check if ray hits sphere
-- @param r - Ray object
-- @param s - Sphere object
-- @return 0 for no hit, 1 for hit
function rayHitSphere(r, s)
oc = subVec3(r.origin, s.origin)
b = 2 * dotVec3(oc, r.direction)
c = dotVec3(oc, oc) - (s.radius*s.radius)
disc = b*b - 4*c
if disc < 1e-4 then
And I've attached the full main.lua, and I suspect that if the intersection function isn't at fault, it might be something with the pixel rendering... Thanks in advance!