Raytracer - Raylib
Table of Contents
Let’s walk through src/main.c – a clean raytracer using raylib.
Check the project’s source code at Github
The materials#
SphereMaterial: HoldsColor,specular(0-1),shininess.Sphere: Material +Vector3 position+float radius.
Render Loop#
Per frame, recompute all pixels (brute-force, no acceleration):
Ray Generation: For each
x,y,GetScreenToWorldRayshoots ray from camera through pixels.Intersection:
- Init nearest collision distance to
FLT_MAX. - For each sphere:
GetRayCollisionSphere(ray, pos, radius). - Track closest hit + sphere.
- Init nearest collision distance to
Miss:
BLACKpixel.
Build & Run#
cmake -B build
cmake --build build
./build/Raytracer
Read other posts