wip demo mode

This commit is contained in:
2025-09-20 17:40:42 +02:00
parent 884f236e7e
commit 125c8fb324
10 changed files with 147 additions and 26 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
AUTOMAKE_OPTIONS = foreign subdir-objects -Wall
bin_PROGRAMS = forge
forge_SOURCES = src/main.c src/args.c src/forge.c src/file.c src/window.c src/shaders.c src/timer.c src/string.c src/config_file.c $(top_srcdir)/include/glad/gl.h $(top_srcdir)/hashmap.c/hashmap.c
forge_SOURCES = src/main.c src/args.c src/forge.c src/file.c src/window.c src/shaders.c src/timer.c src/string.c src/config_file.c src/rand.c $(top_srcdir)/include/glad/gl.h $(top_srcdir)/hashmap.c/hashmap.c
forge_CFLAGS = -Ofast -march=native -flto -funroll-loops -fprefetch-loop-arrays -fno-exceptions -fopenmp -I$(top_srcdir)/include -DGLFW_INCLUDE_NONE
forge_LDADD = -lm -lGL -lglfw
include_HEADERS = src/main.h src/args.h src/config.h src/types.h src/forge.h src/file.h src/constants.h src/window.h src/shaders.h src/logs.h src/timer.h src/string.h src/config_file.h $(top_srcdir)/include/glad/gl.h $(top_srcdir)/include/linmath.h $(top_srcdir)/include/hashmap.h
include_HEADERS = src/main.h src/args.h src/config.h src/types.h src/forge.h src/file.h src/constants.h src/window.h src/shaders.h src/logs.h src/timer.h src/string.h src/config_file.h src/rand.h $(top_srcdir)/include/glad/gl.h $(top_srcdir)/include/linmath.h $(top_srcdir)/include/hashmap.h
+1 -1
View File
@@ -1,6 +1,6 @@
TARGET ?= forge
INSTALL_DIR ?= $(HOME)/.local/bin
TEST_ARGS ?= --hot-reload --frag=./shaders --frag-config=./config/shaders.cfg
TEST_ARGS ?= --hot-reload --frag=./shaders --frag-config=./config/shaders.cfg --demo
SHELL := /bin/bash
.PHONY: build
+3
View File
@@ -112,6 +112,9 @@ make -f Makefile.dev release-arch
- [x] uniform config
- [x] fragment config
- [x] subroutines config
- [x] demo mode
- [ ] random seed injected into shaders
- [ ] internal texture size for speed
- [ ] Clean code and fix things
- [ ] Midi
- [ ] Read Midi events
+80 -8
View File
@@ -129,7 +129,7 @@ float divider(float k, int m)
float modTime(float k, int m, float k2)
{
return k * (m * 2 - 1) < 1 ? 0 : mod(divider(k, m) * iTime * iTempo * k2 / 120, 1);
return k * (m * 2 - 1) < 1 ? 0 : mod(divider(k, m) * iTime * iTempo * k2 / 240, 1);
}
float modTime(float k, int m)
@@ -1166,13 +1166,13 @@ subroutine(src_stage_sub) vec4 src_10(vec2 vUV, const float seed)
// logic
return vec4(0.0);
return texture(tex0, vUV);
}
// SRC 11 : video in 2 + thru
subroutine(src_stage_sub) vec4 src_11(vec2 vUV, const float seed)
{
return src_thru(vUV, tex2, 938);
return src_thru(vUV, tex2, seed);
}
// TODO SRC 12
@@ -1188,7 +1188,7 @@ subroutine(src_stage_sub) vec4 src_12(vec2 vUV, const float seed)
// logic
return vec4(0.0);
return texture(tex0, vUV);
}
// TODO SRC 13
@@ -1204,7 +1204,7 @@ subroutine(src_stage_sub) vec4 src_13(vec2 vUV, const float seed)
// logic
return vec4(0.0);
return texture(tex0, vUV);
}
// TODO SRC 14
@@ -1220,7 +1220,7 @@ subroutine(src_stage_sub) vec4 src_14(vec2 vUV, const float seed)
// logic
return vec4(0.0);
return texture(tex0, vUV);
}
// TODO SRC 15
@@ -1236,7 +1236,7 @@ subroutine(src_stage_sub) vec4 src_15(vec2 vUV, const float seed)
// logic
return vec4(0.0);
return texture(tex0, vUV);
}
// SRC 16 : debug
@@ -1254,7 +1254,7 @@ subroutine(src_stage_sub) vec4 src_16(vec2 vUV, const float seed)
// TODO tmp
return vec4(0.0);
return texture(tex0, vUV);
}
// 6. effects
@@ -1746,4 +1746,76 @@ subroutine(mix_stage_sub) vec4 mix_2(vec2 vUV, sampler2D ta, sampler2D tb, const
float k = mean(color_a);
return mix(color_b, color_a, step(mix_src, k));
}
// alternate mix 1 / 2 for random selection
subroutine(mix_stage_sub) vec4 mix_3(vec2 vUV, sampler2D ta, sampler2D tb, const float seed)
{
return mix_1(vUV, ta, tb, seed);
}
subroutine(mix_stage_sub) vec4 mix_4(vec2 vUV, sampler2D ta, sampler2D tb, const float seed)
{
return mix_2(vUV, ta, tb, seed);
}
subroutine(mix_stage_sub) vec4 mix_5(vec2 vUV, sampler2D ta, sampler2D tb, const float seed)
{
return mix_1(vUV, ta, tb, seed);
}
subroutine(mix_stage_sub) vec4 mix_6(vec2 vUV, sampler2D ta, sampler2D tb, const float seed)
{
return mix_2(vUV, ta, tb, seed);
}
subroutine(mix_stage_sub) vec4 mix_7(vec2 vUV, sampler2D ta, sampler2D tb, const float seed)
{
return mix_1(vUV, ta, tb, seed);
}
subroutine(mix_stage_sub) vec4 mix_8(vec2 vUV, sampler2D ta, sampler2D tb, const float seed)
{
return mix_2(vUV, ta, tb, seed);
}
subroutine(mix_stage_sub) vec4 mix_9(vec2 vUV, sampler2D ta, sampler2D tb, const float seed)
{
return mix_1(vUV, ta, tb, seed);
}
subroutine(mix_stage_sub) vec4 mix_10(vec2 vUV, sampler2D ta, sampler2D tb, const float seed)
{
return mix_2(vUV, ta, tb, seed);
}
subroutine(mix_stage_sub) vec4 mix_11(vec2 vUV, sampler2D ta, sampler2D tb, const float seed)
{
return mix_1(vUV, ta, tb, seed);
}
subroutine(mix_stage_sub) vec4 mix_12(vec2 vUV, sampler2D ta, sampler2D tb, const float seed)
{
return mix_2(vUV, ta, tb, seed);
}
subroutine(mix_stage_sub) vec4 mix_13(vec2 vUV, sampler2D ta, sampler2D tb, const float seed)
{
return mix_1(vUV, ta, tb, seed);
}
subroutine(mix_stage_sub) vec4 mix_14(vec2 vUV, sampler2D ta, sampler2D tb, const float seed)
{
return mix_2(vUV, ta, tb, seed);
}
subroutine(mix_stage_sub) vec4 mix_15(vec2 vUV, sampler2D ta, sampler2D tb, const float seed)
{
return mix_1(vUV, ta, tb, seed);
}
subroutine(mix_stage_sub) vec4 mix_16(vec2 vUV, sampler2D ta, sampler2D tb, const float seed)
{
return mix_2(vUV, ta, tb, seed);
}
+2 -2
View File
@@ -30,7 +30,7 @@ static void print_help(int status_code) {
" -s, --screen output screen number (default: primary)\n"
" -f, --frag fragment shaders directory (default: TODO)\n"
" -fc, --frag-config fragment shaders config file (default: TODO)\n"
" -t, --tempo base tempo (default: 120)\n"
" -t, --tempo base tempo (default: 60)\n"
" --demo demonstration mode\n");
exit(status_code);
}
@@ -84,7 +84,7 @@ Parameters args_parse(int argc, char **argv) {
params.frag_path = 0;
params.frag_config_path = 0;
params.hot_reload = false;
params.base_tempo = 120.0f;
params.base_tempo = 60.0f;
params.demo = false;
for (i = 1; i < argc; i++) {
+14 -12
View File
@@ -8,6 +8,7 @@
#include "file.h"
#include "forge.h"
#include "logs.h"
#include "rand.h"
#include "shaders.h"
#include "timer.h"
#include "types.h"
@@ -44,19 +45,20 @@ static unsigned int compute_fps(Window *window, Timer *timer) {
static void init_context(ShaderProgram program, Context *context,
Parameters params) {
int size;
int i;
context->tempo = params.base_tempo;
context->demo = params.demo;
// TODO temporary state
size = program.frag_count * program.sub_type_count * sizeof(unsigned int);
context->sub_state = malloc(size);
memset(context->sub_state, 0, size);
context->sub_state[program.sub_type_count * 0 + 0] = 1;
context->sub_state[program.sub_type_count * 1 + 0] = 1;
context->sub_state[program.sub_type_count * 2 + 1] = 1;
context->sub_state[program.sub_type_count * 3 + 1] = 3;
context->sub_state[program.sub_type_count * 5 + 1] = 6;
// TODO fix here ??
size = program.frag_count * program.sub_type_count;
context->sub_state = malloc(size * sizeof(unsigned int));
memset(context->sub_state, 0, sizeof(&context->sub_state));
if (params.demo) {
for (i = 0; i < size; i++) {
context->sub_state[i] = rand_uint(program.sub_variant_count);
}
}
}
static void hot_reload(ShaderProgram program, File *common_shader_code,
@@ -162,10 +164,10 @@ void forge_run(Parameters params) {
window_get_context(window, &context);
init_context(program, &context, params);
program = shaders_init(fragment_shaders, shader_config, context);
init_context(program, &context, params);
if (program.error) {
window_close(window, true);
exit(EXIT_FAILURE);
+4
View File
@@ -1,11 +1,13 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "args.h"
#include "config.h"
#include "forge.h"
#include "main.h"
#include "rand.h"
int main(int argc, char **argv) {
Parameters params;
@@ -14,6 +16,8 @@ int main(int argc, char **argv) {
puts(PACKAGE " " VERSION);
set_seed((unsigned long)time(NULL));
forge_run(params);
return EXIT_SUCCESS;
+31
View File
@@ -0,0 +1,31 @@
#include "rand.h"
static unsigned long long mcg_state = 0xcafef00dd15ea5e5u; // Must be odd
static unsigned long long const multiplier = 6364136223846793005u;
// https://en.wikipedia.org/wiki/Permuted_congruential_generator
static unsigned long rand(void) {
unsigned long long x = mcg_state;
unsigned count = (unsigned)(x >> 61);
mcg_state = x * multiplier;
x ^= x >> 22;
return (unsigned long)(x >> (22 + count));
}
void set_seed(unsigned long long seed) {
mcg_state = 2 * seed + 1;
(void)rand();
}
unsigned char rand_uchar(const unsigned int max) {
return max == 0 ? 0 : (unsigned char)(rand() % max);
}
unsigned short rand_ushort(const unsigned int max) {
return max == 0 ? 0 : (unsigned short)(rand() % max);
}
unsigned int rand_uint(const unsigned int max) {
return max == 0 ? 0 : (unsigned int)(rand() % max);
}
+9
View File
@@ -0,0 +1,9 @@
#ifndef RAND_H
#define RAND_H
void set_seed(unsigned long long seed);
unsigned char rand_uchar(unsigned int max);
unsigned short rand_ushort(unsigned int max);
unsigned int rand_uint(unsigned int max);
#endif
+1 -1
View File
@@ -345,5 +345,5 @@ void shaders_apply(ShaderProgram program, Context context) {
}
}
use_program(program, program.frag_monitor_index, true, context);
use_program(program, program.frag_output_index, true, context);
}