summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2022-12-13 08:15:47 -0800
committerVito Caputo <vcaputo@pengaru.com>2022-12-13 08:15:47 -0800
commit6a1c41149ad50d975b6ed5d7a5ef248c1ccba4cf (patch)
treec5122db4dbf96ec9bc72e436e4b759bcb8eb7ce8 /src
parent659b8b07abba9bc439fed682b274284759977fc6 (diff)
plasma-node,game: wire up and implement maga plasma
This is a bit janky on the integration side, may cleanup later. When game_t.is_maga is true, plasma-node now goes nationalist with red white and blue stripes.
Diffstat (limited to 'src')
-rw-r--r--src/game.c2
-rw-r--r--src/plasma-node.c52
-rw-r--r--src/plasma-node.h2
3 files changed, 47 insertions, 9 deletions
diff --git a/src/game.c b/src/game.c
index 9c3f11d..ae2cc1f 100644
--- a/src/game.c
+++ b/src/game.c
@@ -1148,7 +1148,7 @@ static void * game_init(play_t *play, int argc, char *argv[], unsigned flags)
game->sars = sars;
game->stage = sars->stage;
- game->plasma_node = plasma_node_new(&(stage_conf_t){ .parent = sars->stage, .name = "plasma", .alpha = 1 }, &sars->projection_x, &game->infections_rate_smoothed);
+ game->plasma_node = plasma_node_new(&(stage_conf_t){ .parent = sars->stage, .name = "plasma", .alpha = 1 }, &sars->projection_x, &game->infections_rate_smoothed, &game->is_maga);
game->ix2 = ix2_new(NULL, 4, 4, 2 /* support two simultaneous searches: tv_search->baby_search */);
diff --git a/src/plasma-node.c b/src/plasma-node.c
index 0d276ba..27100cf 100644
--- a/src/plasma-node.c
+++ b/src/plasma-node.c
@@ -22,8 +22,13 @@
#include "glad.h"
#include "plasma-node.h"
#include "shader-node.h"
+#include "macros.h"
#include "m4f.h"
+typedef struct plasma_node_t {
+ int *maga;
+ float *gloom;
+} plasma_node_t;
static const char *plasma_vs = ""
#ifdef __EMSCRIPTEN__
@@ -69,6 +74,7 @@ static const char *plasma_fs = ""
"uniform float alpha;"
"uniform float time;"
"uniform float gloom;"
+ "uniform int maga;"
"void main() {"
" float v;"
@@ -92,33 +98,65 @@ static const char *plasma_fs = ""
" v += sin(sqrt(c.x * c.x + c.y * c.y + 1.0) + stime);"
- " vec3 col = vec3(cos(PI * v + sin(time)), sin(PI * v + cos(time * .33)), cos(PI * v + sin(time * .66)));"
- " gl_FragColor = vec4((col * .5 + .5) * (1.f - gloom), alpha);"
+ " if (maga == 1) {"
+ " float r, g, b;"
+
+ " r = smoothstep(.25, .8, cos(PI * v + sin(time)));"
+ " g = smoothstep(.25, .8, cos(1.333 * PI + PI * v + sin(time)));"
+ " b = smoothstep(.25, .8, cos(2.666 * PI + PI * v + sin(time)));"
+
+ " gl_FragColor = vec4(r + g, g, b + g, 1.);"
+ " } else {"
+ " vec3 col = vec3(cos(PI * v + sin(time)), sin(PI * v + cos(time * .33)), cos(PI * v + sin(time * .66)));"
+ " gl_FragColor = vec4((col * .5 + .5), 1.);"
+ " }"
"}"
"";
static void plasma_uniforms(void *uniforms_ctxt, void *render_ctxt, unsigned n_uniforms, const int *uniforms, const m4f_t *model_x, float alpha)
{
- float *gloom = uniforms_ctxt;
- play_t *play = render_ctxt;
+ plasma_node_t *plasma = uniforms_ctxt;
+ play_t *play = render_ctxt;
glUniform1f(uniforms[0], alpha);
glUniform1f(uniforms[1], play_ticks(play, PLAY_TICKS_TIMER0) * .001f); // FIXME KLUDGE ALERT
glUniformMatrix4fv(uniforms[2], 1, GL_FALSE, &model_x->m[0][0]);
- glUniform1f(uniforms[3], *gloom);
+ glUniform1f(uniforms[3], *(plasma->gloom));
+ glUniform1i(uniforms[4], *(plasma->maga));
}
/* create plasma rendering stage */
-stage_t * plasma_node_new(const stage_conf_t *conf, m4f_t *projection_x, float *gloom)
+stage_t * plasma_node_new(const stage_conf_t *conf, m4f_t *projection_x, float *gloom, int *maga)
{
- return shader_node_new_src(conf, plasma_vs, plasma_fs, projection_x, plasma_uniforms, gloom, 4,
+ plasma_node_t *ctxt;
+
+ /* FIXME TODO:
+ * shader-node doesn't cleanup uniforms_ctxt, so this is being leaked currently.
+ * but that doesn't really matter since plasma-node is only created once per game.
+ * The shortest path to cleaning this up would be to publicize the shader-node struct
+ * and implementation functions, and stitch it all together here, maybe with a nested
+ * shader_node_t in plasma_node_t. That's rather annoying, and perhaps highlights a
+ * shortcoming in the existing stage_t composability. It'd be nice if uniforms_ctxt
+ * could be typed with something embedding an optional free func, which shader_node_free()
+ * would then call to cleanup when set. It's unclear if that should just be a bespoke
+ * shader-node type, or something more generally defined by libstage. Either way, it's
+ * not terribly important for SARS in this singleton plasma-node case.
+ */
+ ctxt = calloc(1, sizeof(plasma_node_t));
+ fatal_if(!ctxt, "unable to allocate plasma_node_t");
+
+ ctxt->gloom = gloom;
+ ctxt->maga = maga;
+
+ return shader_node_new_src(conf, plasma_vs, plasma_fs, projection_x, plasma_uniforms, ctxt, 5,
(const char *[]){
"alpha",
"time",
"projection_x",
"gloom",
+ "maga",
}
);
}
diff --git a/src/plasma-node.h b/src/plasma-node.h
index 9f2dc47..8db8664 100644
--- a/src/plasma-node.h
+++ b/src/plasma-node.h
@@ -21,6 +21,6 @@ typedef struct m4f_t m4f_t;
typedef struct stage_t stage_t;
typedef struct stage_conf_t stage_conf_t;
-stage_t * plasma_node_new(const stage_conf_t *conf, m4f_t *projection_x, float *gloom);
+stage_t * plasma_node_new(const stage_conf_t *conf, m4f_t *projection_x, float *gloom, int *maga);
#endif
© All Rights Reserved