Skip to content
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.
/ RTv1-42 Public archive

Ray Tracing Engine on C (project from school 42)

Notifications You must be signed in to change notification settings

Iipal/RTv1-42

Repository files navigation

RTv1-42

Ray Tracing Engine on C using SDL2. (project from school42(UNIT Factory))

made by tmaluh (_ipal)

screenshot

Addiitonal SDL2 pre-installation:

Ubuntu, Debian:

$> sudo apt-get install libsdl2-dev libsdl2-ttf-dev libsdl2-image-dev

Fedora:

$> sudo dnf install SDL2-devel SDL2_ttf-devel SDL2_image-devel

MacOS:

$> brew install sdl2 sdl2_image sdl2_ttf
I'm not tested this on other OS or distros.

Additional info:

This project inlcudes also a few my other projects. It's libraries libvectors, libft and libftsdl, and 1 other - forked parson

Compiling

Use make for compiling all files.

When you have already installed SDL2 library you can use this simple rules:

  • make: Compile all.
  • make clean: Delete all RTv1, libft and libftsdl temporary files.
  • make del: Delete temporary RTv1 files only.
  • make fclean: Expands make clean to delete also executable RTv1, libraries libft and libftsdl.
  • make re: It's rules - make fclean & make in one.
  • make pre: It's rules - make del & make in one.
  • make profie_all: Re-compile all RTv1 source files without optimization flags but with -no-pie -pg -O0 for profiling.
  • make debug_all: Re-compile all RTv1 source files without optimization flags but with -g3 for debug.
  • make profile: Compile RTv1 source files without optimization flags but with -no-pie -pg -O0 for profiling.
  • make debug: Compile RTv1 source files without optimization flags but with -g3 for debug.
  • make norme: Check all libft, libftsdl and RTv1 *.c and *.h files for norme errors. (Works only on MacOS in school42)

If you change RTv1 source code use: make del & make or equal rule - make pre for re-compile only RTv1 executable without re-compile libft and libftsdl.

If you chnage libft or libftsdl source code use: make -C libft or cd libft && make || make -C libftsdl or cd libftsdl && make

If you wants to re-compile libft and libftsdl for debug use: make -C libft debug_all and make -C libftsdl debug_all.

Usage:

$> ./bin/RTv1 [flags-params] scenes/<scene_name>.json

Flags:

Flag Description Shortcut Valid values Default value Value type Dependency on -dbg mode
--help Print short flags description. After print RTv1 will automatically close. -h none none none no
WITH PARAMS:
--viewportScale How many times will be increased viewport. -vps 0.000001-10.0 1.0 Float no
--ambientLight On how much shadow must be darker. (Greater - brighter) -al 0.000001-100.0 0.0 Float no
--fpsTextColor FPS counter info text color. -ftc All HEX values 0x7FFF00 HEX yes
--fpsRefreshTimer How often will refresh FPS counter. (in ms) -frt 0-500 25 Integer yes
--antiAliasing Enable simplified anti-aliasing algorithm. -aa 2-16 0 Integer no
BOOLEAN:
--debug Enable keybinds switcher(debug) mode. -dbg none not enabled none
--noCalcLight Disable calc all light origins. -ncl none not enabled none no
--textured Enable textured rendering. -t none not enabled none no
--randomLightsIntense Enable randomaize lights intense. -rli none not enabled none yes
--printUsage Print usage for -dbg mode. -pu none not enabled none yes
OTHER:
--noBorder Create window without borders. -nb none not enabled none no
Note: always put scene file in arguments line, because flags will parse only after successful read scene file.

Example:

$> ./bin/RTv1 --debug -vps 0.5 -t -pu -ftc 0x1 -frt 0 -al 10 -nb -aa 4 scenes/sphere.json

Keybinds:

All binds below works only with -dbg flag.

General keybinds what works in all keybind modes:

Description Keybinding
Toggle on\off rendering info. Z
Toggle on\off calculating and rendering shadows. (eShadows scene param) H
Toggle on\off rendering textures. (-t) Y
Toggle on\off calculating light origins. (-ncl) N
Exit. Esc
Name Description Keybinding
Switcher keybind mode to control all light origins or objects. After first press is active Lights Control Mode keybinds, after second press - Objects Control Mode. Keybinds after third press retruns to Default Camera Control Mode. All keybinds valid for all light origins or objects dependecny on mode. X
Increase speed value. Increase speed value for changing movements[default] or intensity\specular[optional]. LShift
Decrease speed value. Decrease speed value for changing movements[default] or intensity\specular[optional]. LCtrl
Description Keybinding
Move camera up. W
Move camera left. A
Move camera down. S
Move camera right. D
Move camera backward. Q
Move camera forward. E
Increase camera rotate by X-axis. R
Increase camera rotate by Y-axis. F
Increase camera rotate by Z-axis. V
Decrease camera rotate by X-axis. T
Decrease camera rotate by Y-axis. G
Decrease camera rotate by Z-axis. B
Description Keybinding
Move lights up. W
Move lights left. A
Move lights down. S
Move lights right. D
Move lights forward. [default] E
Move lights backward. [default] Q
Switch to control lights intensity. C
Decrease lights inensity. [optional] Q
Increase lights inensity. [optional] E
Description Keybinding
Move objects up. W
Move objects left. A
Move objects down. S
Move objects right. D
Move objects forward. [default] E
Move objects backward. [default] Q
Switch to control objects specular. C
Decrease objects specular. [optional] Q
Increase objects specular. [optional] E
Increase objects rotate by X-axis. R
Increase objects rotate by Y-axis. F
Increase objects rotate by Z-axis. V
Decrease objects rotate by X-axis. T
Decrease objects rotate by Y-axis. G
Decrease objects rotate by Z-axis. B

Profilig (with gprof, gprof2dot and graphviz):

For re-compile whole project for correct profiling use this command:

$> make profile_allr

After re-compile just run ./RTv1. More info about profiling on eax.me(RU).

Example on:

$> ./bin/RTv1 -dbg scenes/sphere.json

./RTv1 -dbg scenes/sphere.json

Example on:

$> ./bin/RTv1 -dbg scenes/all.json

./RTv1 -dbg scenes/all.json ./RTv1 -dbg scenes/all.json

Example on:

$> ./bin/RTv1 scenes/all.json

./RTv1 scenes/all.json

Example on:

$> ./bin/RTv1 scenes/sphere.json

./RTv1 scenes/sphere.json