Colour sphere based on normal

This commit is contained in:
Camden Dixie O'Brien
2025-09-21 10:08:55 +01:00
parent 9048039be0
commit 88dc098db2

7
demo.c
View File

@@ -59,8 +59,11 @@ static double intersect(sphere_t sphere, ray_t ray)
static vec3_t raycol(ray_t ray)
{
const double t = intersect(obj, ray);
if (t > 0.0)
return red;
if (t > 0.0) {
const vec3_t p = vec3_add(ray.orig, vec3_scale(ray.dir, t));
const vec3_t normal = vec3_unit(vec3_sub(p, obj.centre));
return vec3_scale(vec3_add(normal, white), 0.5);
}
const double a = (ray.dir.y + 1.0) / 2.0;
return vec3_add(vec3_scale(lightblue, a), vec3_scale(white, 1 - a));