Raytracer - Raylib
Let’s walk through src/main.c – a clean raytracer using raylib.
Check the project’s source code at Github
The materials#
- SphereMaterial: Holds Color, 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, GetScreenToWorldRay shoots ray from camera through pixels.
Intersection:
- Init nearest collision distance to FLT_MAX.
- For each sphere: GetRayCollisionSphere(ray, pos, radius).
- Track closest hit + sphere.
Miss: BLACK pixel.
Build & Run#
cmake -B build
cmake --build build
./build/Raytracer
Read other posts