From 3b9a4861d6937a66b03791b5b497e47c52189a7d Mon Sep 17 00:00:00 2001
From: Vito Caputo <vcaputo@pengaru.com>
Date: Wed, 28 Feb 2018 20:24:30 -0800
Subject: ray: implement distance-based light brightness

---
 src/modules/ray/ray.c        | 2 +-
 src/modules/ray/ray_render.c | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/modules/ray/ray.c b/src/modules/ray/ray.c
index bb9c042..1e58f3b 100644
--- a/src/modules/ray/ray.c
+++ b/src/modules/ray/ray.c
@@ -83,7 +83,7 @@ static ray_object_t	lights[] = {
 	{
 		.light = {
 			.type = RAY_OBJECT_TYPE_LIGHT,
-			.brightness = 1.0,
+			.brightness = 15.0f,
 			.emitter = {
 				.point.type = RAY_LIGHT_EMITTER_TYPE_POINT,
 				.point.center = { .x = 3.0f, .y = 3.0f, .z = 3.0f },
diff --git a/src/modules/ray/ray_render.c b/src/modules/ray/ray_render.c
index 4ca168f..8b930f6 100644
--- a/src/modules/ray/ray_render.c
+++ b/src/modules/ray/ray_render.c
@@ -88,6 +88,7 @@ static inline ray_color_t shade_intersection(ray_render_t *render, ray_render_ob
 		if (lvec_normal_dot > 0) {
 #if 1
 			float		rvec_lvec_dot = ray_3f_dot(&ray->direction, &lvec);
+			float		intensity = light->light.brightness * (1.0 / (ldist * ldist));
 			ray_color_t	diffuse;
 
 			diffuse = ray_3f_mult_scalar(&surface.color, lvec_normal_dot);
@@ -102,6 +103,8 @@ static inline ray_color_t shade_intersection(ray_render_t *render, ray_render_ob
 				specular = ray_3f_mult_scalar(&specular, surface.specular);
 				color = ray_3f_add(&color, &specular);
 			}
+
+			color = ray_3f_mult_scalar(&color, intensity);
 #else
 			ray_color_t	diffuse;
 
-- 
cgit v1.2.3