Soo, i decided to make my own raycaster, and it’s work, i also did a shadows, i work on it around 2-3 days and learned everything i can. I did it just for fun and personal research.
Look, when our raycast for single pixel hit the object:
local result = workspace:Raycast...
if result then
we shoot another ray to light sources (for i, lightSource in pairs(lightSources))
local shadowRay = workspace:Raycast(result.Position, lightSourcePosition * lightSourceDistance)
and if he hit something
if shadowRay then
IsInShadow = true
we can say that here will be placed shadow:
local shadowColor = Color3.new()
if IsInShadow then
shadowColor = pixelColor:Lerp(Color3.new(0, 0, 0), 0.5) -- we make color darker because here will be shadow
else
shadowColor = pixelColor:Lerp(Color3.new(1, 1, 1), sourceLightIntensivity) -- we making color lighter because it's no shadow here.
end
I hope it helped you
But i found a one bug, no matter where u stand, shadow will be turn always in one way, i don’t know how to fix it.
Thanks, im in search for any raycast algorithms that can help me make it more faster, most problem, raycast count and alot of gui instances(roblox just can’t handle it normally), if we got no shadows/reflections and other, by small math we can calculate resolution(128x64) and get 8192 rays per FRAME, and if you got alot of lighting sources, pc just blow up haha
So this is a form of raytracing, but in real-time (which is cool).
one thing though, i noticed that your shadows are a bit glitchy when they hit the ball (or just the back of surfaces).
This happens because you are raycasting your shadows from the intersection point of the ball. This casuses issues because the ray origin is 50% in the ball and out, and raycasts dont work if they are inside parts.
A simple solution to this is to slightly offset the shadow ray’s origin away from the object
e.g. Origin = Intersection + (ObjectNormal / 1000)
What is your method for pixels? If you are using frames for each pixel, that pretty slow, and I have a much more efficient and faster way to draw pixels to the screen if your interested