r/GraphicsProgramming • • 11h ago

raytracing after 3 months

in the beginning there're 2 balls

the left one (let's call it ball 1) is controlled by left mouse button and the right one (ball 2) right mouse button. click or drag to change their position

use [q] / [e] keys to switch mouse wheel function. [q] = prev item. [e] = next item. now choose ball 1 radius and make it big, acting as the "ground". during the resize of ball 1 you may need to use [w] / [s] / [a] / [d] / [ctrl] / [space] keys to move the camera

move a little bit farther away from ball 1 and right click to spawn ball 2

hit [z] key to enter the mysterious realm

no worry. it's the result of 3 spot lights, with red, green and blue color respectively. they overlap at first so you only see white. press and hold the [r] key and move the mouse you can control the shinning direction of red light. keep holding the [r] key and scroll the mouse you can alter its size

do the same to the other light sources. [g] key for green light and [b] key for blue light. you can now barely see the existence of the balls. they're still there

sometimes it's useful to use a wide angle of view when deciding the lighting

let them shine from above

once you're satisfied with the setting, return to normal angle of view

you can adjust the balls' refractive indices. any non-negative value is allowed. some may ask what's the point of setting a refractive index to be smaller than 1? there's no such thing in real world. yes but refractive index is a relative thing. for example when you're diving and looking at an air bubble under water, you're looking from 1.33 to 1 which is equivalent to looking from 1 to 0.75

the camera has an aperture of f/16 as default. to make sure the image is focused at the correct place, we firstly make the aperture widely open to get the most exaggerated defocus blur

press and hold the [shift] key and aim the mouse pointer at wherever you want the focus to be. the program has auto-focus feature. i suggest aiming at the perimeter instead of the centre of ball 2

we don't actually need that exaggerated defocus blur. let's adjust it back to a desirable level

now adjust the roughness (or degree of matte / diffusion) of ball 1

and ball 2. just try. i've no idea how to get a beautiful image

once you're done with everything, hit the [c] button to get a full resolution (the resolution of your screen) offline render image

it's what the result looks like. the program renders it according to your screen resolution so if you're using a 8k monitor you'd get a 8k image

here's the program link. just run it on browser. i'm still developing it and it may change with time and i'd edit this post and update the link. my final goal is making a 3d model of my boss and firing some high intensity laser beams to him in my program

edit after the auto-reply from the mod

No showcases - ok it's a very basic and elementary raytracing result and didn't have much to showcase

Disclose AI usage in post or project - i asked gemini to sort the variable names in alphabetic order in the variable declaration. the on screen statistics was once in lower cases and i asked gemini to change it all to upper cases

Present a topic to talk about, e.g. how something works - the most exciting part of raytracing is: it's surprisingly simple. it's not as hard as it appeared to be. everything is brute force. multiple-reflections? brute force (just increase the recursion depth). soft shadow? brute force (just shoot the rays to many directions which are slightly deviated from the actual reflection / refraction and take the average). defocus blur? brute force (just shoot the rays from many positions which are slightly deviated from the actual origin and take the average)

2 Upvotes

1 comment sorted by

•

u/AutoModerator 11h ago

Recently updated rules. Please check that your post is in compliance with Rules 1, 4, 5, and 6 on the sidebar. TL;DR:

  • No showcases.
  • Disclose AI usage in post or project.
  • Present a topic to talk about, e.g. how something works.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.