Ray tracer in Roblox

Since around mid-december, ive been slowly chipping away at a ray tracer that runs in roblox.

not stupidly complex but it is quite laggy as of current. looking for feedback on it right now with stuff that isnt obvious issues like reflection colours not being what the should be.

also dont expect nvidia level quality in a 20 year old engine, especially from a 16 year old with an intermediate skill level trying to just straight up calculate light traversal

also has an option to enable a (very laggy) real time version of it upon joining (CURRENTLY DISABLED). you will however have to rejoin if you wanna change it which ill change once i get a parameters menu working. the screen divisions text box also has no functionality yet since i cant quite get the screen to clear and repopulate correctly

(you WILL experience lag no matter your specs)

oh and just as a quick thing to mention, you will have to make around 4 renders before images become actually good since for some reason the first 4-5 renders are way bright than they should be. ill look into it at some point though

also, buttons for rendering are on the bottom left, character/viewport visibility is on the bottom right

2 Likes

Lag just on lower end devices? I’m on a 3060 and lagging, also where is the raytracing? All I see is a very unoptimized game, maybe make the rays visible for easier interpretation.

2 Likes

will this work on 4gb ram ddr3, intel i7 4th gen?

1 Like

you have an i7 but ddr3 4gb? btw it wont, i have 8gb ddr4 with a gx 1660 and an i5 and i do max20 fps

edit: with the tracer on i do 5 fps

1 Like

when you said “ray tracer” i tought about a next gen lighting, however you made a pixelated effect (which is cool ngl)

however, the tracing doesnt work in slightly dark places, as it will only generate a very dark green pixels.

i found another post time ago of “ray tracing” which runs a 128x128 at like 60-100 fps

1 Like

@bobertus00 i do think it depends more on your cpu since roblox can (for some dumb reason) only run cpu based code. there is unfortunately no support for actual shaders or gpu code, which we clearly need due to how laggy synthesising a shader is. also if you wanna see the raytracing, theres 2 buttons in the bottom corners, 'Toggle Viewport' and 'Render Scene'. if you dont have the 'viewport' enabled then you wont see it

and i would like to add, i do have code to show the rays when a specific variable is enabled in the tracers module, but turning it on WILL VERY LIKELY cause you to crash even on a 40 series since its hundreds of thousands of rays being sent due to the high pixel count and 3 ray bounces im doing. if you have a stupid amount of pixels over smtn like 50k then you are going to lag since im forced to use frames until i actually have access to an ID that roblox will take. i do wanna have smtn to dynamically change the pixel count depending on screen size or device but thats low priority rn as im still tryna figure out how to speed it up and make it look good

@nix102on i have every doubt in my mind that it will considering it nearly crashes on a standard spec pc

@deaconstjohn03 thanks for pointing out the dark lighting. im aware it doesnt look amazing but i think its because my colour blending math isnt exactly the best. the weird green darkness is probably due to the green mirror in the spawn room being weird and reflecting too much light or the green light wall outside (which idk why reflective surfaces reflect so much light cause they shouldnt). same with the reflection colouring, not sure why all the colours get set to a monochromatic colour scheme in reflective objects

this ray tracer is also decently complex and not well optimised. ive done a bit of optimisation work which is why it doesnt immediately crash when pressing the render button, stuff like approximating a square root does help speed it up. however, the reason it practically freezes for a bit when rendering is cause i have to store all the pixel locations and rotations in 3d space with 2 separate tables to put into the function which sends out rays. i do wanna move away from that approach though since its obviously quite slow

i am currently working on fixing up my code to support more things like transparency, and to weed out any of the weird colouring/lighting artefacts which are currently present. and i think i have a better way to calculate shadows using the Lamberts Cosine Law which just picks up the cosine of the angle between a rays incoming angle and the normal direction of that rays hit surface, and then multiplying the main light value by that value

i also wont be able to do nvidia level ray tracing because, as i mentioned, roblox annoyingly has no shader support or a way to run code on the gpu when it really should have both


i did also start writing this in december so a lot of my code is pretty outdated optimisation wise. do gotta redo some blocks but it shouldnt be hellishly difficult

I am also working on a denoising algorithm for this. just need to figure out why its doing this

nvm i think its better to just use multiple rays per pixel

might have to not do it for real time tho

just pushed out an update to implement the lamberts cosine law and the multiple ray bounces. might take a sec to render, and the first couple of images you render will be insanely bright yet will be just fine after the 4th one. ill try find a fix for that eventually

i also had to disable real time rendering for now due to a bug im tryna figure out

(i should also mention you will likely be legless after using this cause your pc will likely explode)

Would that be path tracing now

kinda i think

not too sure about the difference between path tracing and ray tracing but it seems path tracing is using multiple rays per pixel to achieve effects like global illumination and depth of field while ray tracing is just one ray per pixel

im kind of using multiple rays per pixel by taking 12 screen samples and averaging out all the final colours of all the rays allocated to each pixel

it does give the same effects as path tracing such as motion blur and some ability for depth of field as you can see here since pixels are blurred
image

really wish i could do this on the gpu to make it far quicker. but unfortunately roblox can only run code on the cpu so its kinda hard to get good looking visual effects without killing performance

hell with my screen dimensions its a 166x166 display, but that means 1.7 million rays for one full render considering the 12 samples, 3 ray bounces, and the extra 2 rays that are used for sun shadows and setting the initial colour of a pixel so its excruciatingly laggy even on powerful systems according to the first commenter


i also forgot to disable the denoising ._.

that has some rlly weird indexing issues where it skips over pixels and still does what i posted on the 12th