My renderer in real-time with raycast

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.

But for first: lighting errors.

Lighting that killed my brain

First - ok good, just fix colors and the vectors
image

Second - what is that lol

and alot of seconds more later…

At now it works good:


UPD1: Here video with dynamic light source

The other attemps to light and etc…

attemps lol


(i have recorded video with it lol)

So, i will happy to any critique

12 Likes

I forgot to said: current resolution is 128x64 pixels, yes bad, but my pc almost blow up lol, and i don’t know how to make it better

1 Like

Two light sources on cube, AND 4 FPS

3 Likes

Nice! This is very cool! sadly, it’s not as good as Robloxs rendering, but I still like what you did, Keep up the good work!

1 Like

That is so cool! I just wonder, how did you get the shadows using raycasts!?

1 Like

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.

2 Likes

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

That is actually so smart. And what do you mean? In the video I saw you turned the camera and it turned.

i mean, rn im testing it, and get that result:



and if i ever stan “behind” the light source(if orient by shadows) it go in one direction.

maybe im did something wrong with code lol

1 Like

Just fixed shadows, added two types of light:

  1. point
  2. directional
point

image

directional

image

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)

1 Like

Hi, yes my shadows really lag because of this, but at the moment I don’t use parts, I use pure vectors for every light in raycaster:

function pointLight.new(position : Vector3, radius : number, intensity : number)
	local self = setmetatable({}, pointLight)
	self.position = position
	self.radius = radius
	self.intensity = intensity
	self.lightType = "point"
	
	return self
end

For now im gonna fix noise(idk how), and add lighting(lighting != shaows) lol, should be easy, just dot_products andd color math

I also would try get higher resolutions, and transparent parts renderer

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

1 Like

Thanks, maybe later im move my renderer to your module, but not now, im trying make my lighting work fine lol
image
why a half of sphere, why so “foggy” lol

Hey, i mind, what method you using for pixels?

1 Like