random seed

This commit is contained in:
2025-09-20 18:24:20 +02:00
parent 125c8fb324
commit 66404d0df6
12 changed files with 118 additions and 110 deletions
+12 -1
View File
@@ -44,6 +44,7 @@ static unsigned int compute_fps(Window *window, Timer *timer) {
static void init_context(ShaderProgram program, Context *context,
Parameters params) {
int size;
int i;
@@ -59,6 +60,16 @@ static void init_context(ShaderProgram program, Context *context,
context->sub_state[i] = rand_uint(program.sub_variant_count);
}
}
context->seeds = malloc(program.frag_count * sizeof(unsigned int));
for (i = 0; i < (int)program.frag_count; i++) {
context->seeds[i] = rand_uint(1000);
}
}
static void free_context(Context context) {
free(context.sub_state);
free(context.seeds);
}
static void hot_reload(ShaderProgram program, File *common_shader_code,
@@ -188,5 +199,5 @@ void forge_run(Parameters params) {
window_close(window, true);
free(context.sub_state);
free_context(context);
}
+17
View File
@@ -138,6 +138,7 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
char name[32];
char *tex_prefix;
char *sub_prefix;
char *seed_prefix;
program->programs[i] = glCreateProgram();
@@ -162,6 +163,14 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
program->programs[i],
config_file_get_str(shader_config, "UNIFORM_DEMO", "iDemo"));
seed_prefix =
config_file_get_str(shader_config, "UNIFORM_SEED_PREFIX", "seed");
for (j = 0; j < program->frag_count; j++) {
sprintf(name, "%s%d", seed_prefix, j + 1);
program->iseed_locations[i * program->frag_count + j] =
glGetUniformLocation(program->programs[i], name);
}
for (j = 0; j < program->sub_type_count; j++) {
sprintf(name, "SUB_%d_PREFIX", j + 1);
sub_prefix = config_file_get_str(shader_config, name, 0);
@@ -204,6 +213,8 @@ static void init_programs(ShaderProgram *program, ConfigFile shader_config) {
program->ifps_locations = malloc(program->frag_count * sizeof(GLuint));
program->ires_locations = malloc(program->frag_count * sizeof(GLuint));
program->idemo_locations = malloc(program->frag_count * sizeof(GLuint));
program->iseed_locations =
malloc(program->frag_count * program->frag_count * sizeof(GLuint));
program->vpos_locations = malloc(program->frag_count * sizeof(GLuint));
program->textures_locations =
malloc(program->frag_count * program->tex_count * sizeof(GLuint));
@@ -314,6 +325,12 @@ static void use_program(ShaderProgram program, int i, bool output,
glUniform1i(program.idemo_locations[i], (const GLint)(context.demo ? 1 : 0));
glUniform2fv(program.ires_locations[i], 1, (const GLfloat *)&resolution);
// set seeds uniforms
for (j = 0; j < program.frag_count; j++) {
glUniform1i(program.iseed_locations[i * program.frag_count + j],
(const GLint)context.seeds[j]);
}
// set subroutines for fragment
for (j = 0; j < program.sub_type_count; j++) {
k = context.sub_state[i * program.sub_type_count + j];
+2
View File
@@ -57,6 +57,7 @@ typedef struct ShaderProgram {
GLuint *ifps_locations;
GLuint *ires_locations;
GLuint *idemo_locations;
GLuint *iseed_locations;
GLuint *vpos_locations;
@@ -77,6 +78,7 @@ typedef struct Context {
float tempo;
unsigned int *sub_state;
bool demo;
unsigned int *seeds;
} Context;
typedef struct Timer {