summaryrefslogtreecommitdiff
path: root/src/modules/voronoi
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-05-28 00:01:15 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-05-28 00:01:15 -0700
commitfead6a99d3fe4be0c1b654ed3f8fac10f5aff204 (patch)
tree6ea294de87df1e3363d6aa6bfbd36b16ea3d4944 /src/modules/voronoi
parent5480c8e49e1b8a67f27f8207538a6084f3628038 (diff)
modules/voronoi: make cell color randomization conditional
When voronoi is overlayed the colors get sampled, so randomizing them is pointless work every frame.
Diffstat (limited to 'src/modules/voronoi')
-rw-r--r--src/modules/voronoi/voronoi.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/modules/voronoi/voronoi.c b/src/modules/voronoi/voronoi.c
index 44e3f7c..5b86746 100644
--- a/src/modules/voronoi/voronoi.c
+++ b/src/modules/voronoi/voronoi.c
@@ -56,19 +56,33 @@ typedef struct voronoi_context_t {
#define VORONOI_DEFAULT_RANDOMIZE 0
-static void voronoi_randomize(voronoi_context_t *ctxt)
+/* TODO: stuff like this makes me think there needs to be support for threaded prepare_frame(),
+ * since this could just have per-cpu lists of cells and per-cpu rand_r seeds which could make
+ * a significant difference for large numbers of cells.
+ */
+static void voronoi_randomize(voronoi_context_t *ctxt, int do_colors)
{
float inv_rand_max= 1.f / (float)RAND_MAX;
- for (size_t i = 0; i < ctxt->setup->n_cells; i++) {
- voronoi_cell_t *p = &ctxt->cells[i];
+ if (!do_colors) {
+ /* we can skip setting the colors when overlayed since they get sampled */
+ for (size_t i = 0; i < ctxt->setup->n_cells; i++) {
+ voronoi_cell_t *p = &ctxt->cells[i];
- p->origin.x = ((float)rand_r(&ctxt->seed) * inv_rand_max) * 2.f - 1.f;
- p->origin.y = ((float)rand_r(&ctxt->seed) * inv_rand_max) * 2.f - 1.f;
+ p->origin.x = ((float)rand_r(&ctxt->seed) * inv_rand_max) * 2.f - 1.f;
+ p->origin.y = ((float)rand_r(&ctxt->seed) * inv_rand_max) * 2.f - 1.f;
+ }
+ } else {
+ for (size_t i = 0; i < ctxt->setup->n_cells; i++) {
+ voronoi_cell_t *p = &ctxt->cells[i];
+
+ p->origin.x = ((float)rand_r(&ctxt->seed) * inv_rand_max) * 2.f - 1.f;
+ p->origin.y = ((float)rand_r(&ctxt->seed) * inv_rand_max) * 2.f - 1.f;
- p->color = ((uint32_t)(rand_r(&ctxt->seed) % 256)) << 16;
- p->color |= ((uint32_t)(rand_r(&ctxt->seed) % 256)) << 8;
- p->color |= ((uint32_t)(rand_r(&ctxt->seed) % 256));
+ p->color = ((uint32_t)(rand_r(&ctxt->seed) % 256)) << 16;
+ p->color |= ((uint32_t)(rand_r(&ctxt->seed) % 256)) << 8;
+ p->color |= ((uint32_t)(rand_r(&ctxt->seed) % 256));
+ }
}
ctxt->distances.recalc_needed = 1;
@@ -86,7 +100,7 @@ static til_module_context_t * voronoi_create_context(const til_module_t *module,
ctxt->setup = (voronoi_setup_t *)setup;
ctxt->seed = seed;
- voronoi_randomize(ctxt);
+ voronoi_randomize(ctxt, 1);
return &ctxt->til_module_context;
}
@@ -300,7 +314,7 @@ static void voronoi_prepare_frame(til_module_context_t *context, til_stream_t *s
}
if (ctxt->setup->randomize)
- voronoi_randomize(ctxt);
+ voronoi_randomize(ctxt, !fragment->cleared);
/* if the fragment comes in already cleared/initialized, use it for the colors, producing a mosaic */
if (fragment->cleared)
© All Rights Reserved