Colour sphere based on normal
This commit is contained in:
7
demo.c
7
demo.c
@@ -59,8 +59,11 @@ static double intersect(sphere_t sphere, ray_t ray)
|
|||||||
static vec3_t raycol(ray_t ray)
|
static vec3_t raycol(ray_t ray)
|
||||||
{
|
{
|
||||||
const double t = intersect(obj, ray);
|
const double t = intersect(obj, ray);
|
||||||
if (t > 0.0)
|
if (t > 0.0) {
|
||||||
return red;
|
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;
|
const double a = (ray.dir.y + 1.0) / 2.0;
|
||||||
return vec3_add(vec3_scale(lightblue, a), vec3_scale(white, 1 - a));
|
return vec3_add(vec3_scale(lightblue, a), vec3_scale(white, 1 - a));
|
||||||
|
|||||||
Reference in New Issue
Block a user