From 12d449822ee41d447c09bcc44d05aa0bbe8aa2a1 Mon Sep 17 00:00:00 2001
From: Vito Caputo <vcaputo@pengaru.com>
Date: Mon, 4 Sep 2023 23:51:46 -0700
Subject: modules/flow: restore previous Z depth

While optimizing the threaded rendering in commit 6d6c141, the
pos.{xy} expanding from 0-1 to -1..+1 were eliminated from the
inner loops in favor of just having the positions always in
-1..+1 coordinates.  But I missed that it was only the x/y
coordinates which were being expanded, with .z being left in the
0-1 space, which had a desirable aesthetic effect of condensing
the Z space, flattening everything.

This commit undoes that, without reintroducing the expansion to
the inner loops.  It's a bit crufty because now .z is treated
exceptionally throughout as 0..1 while {.x,.y} are in -1..+1, but
it's fine for now.
---
 src/modules/flow/flow.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

(limited to 'src/modules')

diff --git a/src/modules/flow/flow.c b/src/modules/flow/flow.c
index ddbae52..431a839 100644
--- a/src/modules/flow/flow.c
+++ b/src/modules/flow/flow.c
@@ -98,9 +98,11 @@ static inline flow_element_t rand_element(unsigned *seed)
 {
 	flow_element_t	e = {
 				.lifetime = rand_within_range(seed, .5f, 20.f),
-				.position_a = v3f_rand(seed, -1.f, 1.f),
+				.position_a = v3f_rand(seed, 0.f, 1.f),
 			};
 
+	e.position_a.x = e.position_a.x * 2.f - 1.f;
+	e.position_a.y = e.position_a.y * 2.f - 1.f;
 	e.position_b = e.position_a;
 
 	return e;
@@ -236,7 +238,7 @@ static void flow_render_fragment(til_module_context_t *context, til_stream_t *st
 
 			if (e->position_b.x < -1.f || e->position_b.x > 1.f ||
 			    e->position_b.y < -1.f || e->position_b.y > 1.f ||
-			    e->position_b.z < -1.f || e->position_b.z > 1.f)
+			    e->position_b.z < 0.f || e->position_b.z > 1.f)
 				*e = rand_element(&ctxt->til_module_context.seed);
 
 			pos = e->position_a = e->position_b;
@@ -245,7 +247,7 @@ static void flow_render_fragment(til_module_context_t *context, til_stream_t *st
 				   &(v3f_t){ /* FIXME TODO: just make ff.[ch] use a -1..+1 coordinate system */
 					.x = pos.x * .5f + .5f,
 					.y = pos.y * .5f + .5f,
-					.z = pos.z * .5f + .5f,
+					.z = pos.z,
 				   }, w);
 			e->color = d.color;
 			d.direction = v3f_mult_scalar(&d.direction, .001f); /* XXX FIXME: magic number alert! */
@@ -346,7 +348,7 @@ static void flow_render_fragment(til_module_context_t *context, til_stream_t *st
 				pos = v3f_add(&pos, &v);
 
 				x1 = pos.x / (pos.z + ZCONST) * ffw + (ffw >> 1);
-				y1 = pos.y / (pos.z + ZCONST) * ffh + (ffh >> 1) ;
+				y1 = pos.y / (pos.z + ZCONST) * ffh + (ffh >> 1);
 
 				(void) til_fb_fragment_put_pixel_checked(fragment, TIL_FB_DRAW_FLAG_TEXTURABLE, x1, y1, pixel);
 			}
-- 
cgit v1.2.3