The goal of this project is to render 3D objects on a screen.
I uses raymarching to render primitives (sphere, cylinder and rectangle). I'm able to render light, shadow and mirrors.
This simulation uses Processing for UI and GLSL to render. You can download the Processing application here. The file TIPE.pde
is the layout and manage UI. The file shader.glsl
render the screen with TIPE.pde
parameters.
Keyboard actions :
ESC
: exitEnter
: take a screenshotArrows
: move cameraZQSD
: change orientation1-9
: change the scenel
andm
: change the scene:
and=
: change the value of a parameter depending of the scene,
: change display mode : Simple raytracing, raytracing with light or raymarching (slow);
: change light mode : ambient light, ambiente and objects light, only objects lightn
: change background : day or night
This is a graphic engine on GPU. The engine use Ray Tracing and Ray Marching.
Features :
- Three primitives : sphere, cylinder and rectangle
- Textures for primitives
- Reflexion
- Blur
- Refraction
- Light & Shadow
- Ray Marching
Pink color is where the algorithm does not converge
- Terrain Generation
You can find more pictures in the pictures folder.
Here is a pseudo-code algorithm explaining the functionment of the raymarching :
def calc_color(R = None):
if R == None:
R = Ray( Origin = camera, Direction = pixel)
Obj = closest_intersection(R, Objects_list)
if Obj.reflexion:
R = reflect_ray()
reflect_color = calc_color(R)
if Obj.refraction:
R = refract_ray()
refract_color = calc_color(R)
return Obj.color + reflect_color + refract_color
And here is the algorithm for ray marching :
def Ray_Marching():
P = camera.position
u = Ray(Origin = camera, Direction = pixel)
v = normalize(u)
while True:
d = SDF(P)
if d < 0.001: break
P += v * d
obj = closest_object(P)
return obj.color