summaryrefslogtreecommitdiff
path: root/src/modules/flow/flow.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-09-03 01:02:14 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-09-03 01:02:14 -0700
commit62a08f9e7b9b1d258caf6680b2978fce4dc303d3 (patch)
tree5b6921c7b16c723af4b54c58c0dede7ecb2d332f /src/modules/flow/flow.c
parent7e2d6bf6304ef22ce8f35bc6c5eac323f2f39d01 (diff)
modules/flow: add colors
This is a first stab at colorizing the output. The flow field now has two v3f_t datums per cell, direction and color. It's a bit pastel-y and color choice/palettes definitely needs work, at least some gamma correction would make sense. But I kind of like the pastel look actually, some of the combinations start looking very 80s aesthetic. A good way to watch flow's possibilities is: --module=rtv,channels=flow,duration=10,context_duration=10,caption_duration=0 \ --video=sdl,fullscreen=on --defaults --go The long-ish duration really gives a chance to get into the groove of things before switching
Diffstat (limited to 'src/modules/flow/flow.c')
-rw-r--r--src/modules/flow/flow.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/modules/flow/flow.c b/src/modules/flow/flow.c
index 636458f..973fad0 100644
--- a/src/modules/flow/flow.c
+++ b/src/modules/flow/flow.c
@@ -48,7 +48,7 @@ typedef struct flow_setup_t {
} flow_setup_t;
-static void populator(void *context, unsigned size, const v3f_t *other, v3f_t *field)
+static void populator(void *context, unsigned size, const ff_data_t *other, ff_data_t *field)
{
flow_context_t *ctxt = context;
unsigned *seedp = &ctxt->til_module_context.seed;
@@ -58,9 +58,11 @@ static void populator(void *context, unsigned size, const v3f_t *other, v3f_t *f
for (y = 0; y < size; y++) {
for (z = 0; z < size; z++) {
v3f_t v = v3f_rand(seedp, -1.0f, 1.0f);
+ v3f_t c = v3f_rand(seedp, 0.f, 1.0f);
size_t idx = x * size * size + y * size + z;
- field[idx] = v3f_lerp(&other[idx], &v, .75f);
+ field[idx].direction = v3f_lerp(&other[idx].direction, &v, .75f);
+ field[idx].color = v3f_lerp(&other[idx].color, &c, .75f);
}
}
}
@@ -150,22 +152,19 @@ static void flow_render_fragment(til_module_context_t *context, til_stream_t *st
for (unsigned j = 0; j < ctxt->n_elements; j++) {
flow_element_t *e = &ctxt->elements[j];
v3f_t pos = e->position;
- v3f_t v = ff_get(ctxt->ff, &pos, w * .5f + .5f);
+ ff_data_t d = ff_get(ctxt->ff, &pos, w * .5f + .5f);
- v = v3f_mult_scalar(&v, .001f);
+ d.direction = v3f_mult_scalar(&d.direction, .001f);
for (unsigned k = 0; k < ctxt->n_iters; k++) {
unsigned x, y;
- v3f_t color;
- pos = v3f_add(&pos, &v);
+ pos = v3f_add(&pos, &d.direction);
#define ZCONST 1.0f
x = (pos.x * 2.f - 1.f) / (pos.z + ZCONST) * fragment->width + (fragment->width >> 1);
y = (pos.y * 2.f - 1.f) / (pos.z + ZCONST) * fragment->height + (fragment->height >> 1) ;
- color.x = color.y = color.z = e->lifetime;
-
- if (!til_fb_fragment_put_pixel_checked(fragment, TIL_FB_DRAW_FLAG_TEXTURABLE, x, y, color_to_uint32_rgb(color)) ||
+ if (!til_fb_fragment_put_pixel_checked(fragment, TIL_FB_DRAW_FLAG_TEXTURABLE, x, y, color_to_uint32_rgb(d.color)) ||
pos.x < 0.f || pos.x > 1.f ||
pos.y < 0.f || pos.y > 1.f ||
pos.z < 0.f || pos.z > 1.f)
© All Rights Reserved