1 Commits
Author SHA1 Message Date
klemek 118fc0d67e refactor(default): glsl cleaning (2/2) 2026-08-28 20:08:41 +02:00
13 changed files with 30 additions and 109 deletions
+12 -12
View File
@@ -133,7 +133,7 @@ make install
```shell
git clone --recursive https://git.klemek.fr/klemek/forge-steel
cd forge-steel
cd forge
makepkg -si
```
@@ -142,11 +142,11 @@ makepkg -si
```shell
git clone --recursive https://git.klemek.fr/klemek/forge-steel
cd forge-steel
cd forge
aclocal
autoconf
automake --add-missing
./configure --prefix=$HOME/.local
./configure
make
make install
```
@@ -174,7 +174,9 @@ These are configurable in the [`forge_project.cfg`](#forge_projectcfg).
### CLI arguments
```txt
usage: forge [-h] [-v] [-p=PROJECT_PATH] [-c=CFG_FILE] [-hr] [-s=SCREEN] [-m=SCREEN] [-mo] [-w] [-t=TEMPO] [-d] [-ar / -nar] [-arc=CYCLES] [-is=SIZE] [-ls / -nls] [-ss / -nss] [-mr / -nmr] [-tm] [-tf] [--x11] [--wayland] [--cocoa] [--win32] [-as / -nas] [-oma=MAJOR] [-omi=MINOR]
forge steel-dev
usage: forge [-h] [-v] [-p=PROJECT_PATH] [-c=CFG_FILE] [-hr] [-s=SCREEN] [-m=SCREEN] [-mo] [-w] [-t=TEMPO] [-d] [-ar / -nar] [-arc=CYCLES] [-vi=FILE] [-vs=SIZE] [-vb=COUNT] [-vr / -nvr] [-vf=FOURCC] [-is=SIZE] [-ls / -nls] [-ss / -nss] [-mr / -nmr] [-tm] [-tf]
Fusion Of Real-time Generative Effects.
@@ -193,23 +195,21 @@ options:
-ar, --auto-random randomize state every cycle (4 beats)
-nar, --no-auto-random do not randomize state (default)
-arc, --auto-random-cycle auto random cycle length (default: 4)
-vi, --video-in path to video capture device (multiple allowed)
-vb, --video-buffers number of video buffers to use (default: 1)
-vs, --video-size video capture desired height (default: internal texture height)
-vr, --video-reconnect auto-reconnect video (default)
-nvr, --no-video-reconnect do not auto-reconnect video
-vf, --video-fourcc video codec fourcc (default: YUYV)
-is, --internal-size internal texture height (default: 720)
-ls, --load-state load saved state (default)
-nls, --no-load-state do not load saved state
-ss, --save-state save state (default)
-nss, --no-save-state do not save state
-as, --auto-save continuously save state (every ~10ms)
-nas, --no-auto-save do not continuously save state (default)
-mr, --midi-reconnect auto-reconnect midi (default)
-nmr, --no-midi-reconnect do not auto-reconnect midi
-tm, --trace-midi print midi code and values
-tf, --trace-fps print fps status of subsystems
--x11 force X11 GLFW backend
--wayland force Wayland GLFW backend
--cocoa force Cocoa GLFW backend
--win32 force Win32 GLFW backend
-oma, --opengl-major-version OpenGL major version (default: 4)
-omi, --opengl-minor-version OpenGL minor version (default: 6)
```
## Default Project
-8
View File
@@ -7,17 +7,12 @@ in vec2 vUV;
out vec4 fragColor;
#include inc_map.glsl
#include inc_cp437.glsl
uniform sampler2D iTex0;
uniform vec3 iGroup2_4[7];
uniform vec3 iGroup2_5[7];
uniform vec3 iGroup2_6[7];
uniform vec3 iGroup2_7[7];
uniform int iFPS;
uniform int iDemo;
const int[] textDEMO = int[5](0x44, 0x45, 0x4D, 0x4F, 0x00);
void main() {
bool visible = (iGroup2_4[4].x + iGroup2_5[4].x + iGroup2_6[4].x + iGroup2_7[4].x) > 0;
@@ -109,9 +104,6 @@ void main() {
vec4 color = texture(iTex0, invert ? vUV : uv);
color = mix(color, 1. - color, iDemo * write_int_left(uv * 20., vec2(1., 1.), iFPS, 3));
color = mix(color, 1. - color, iDemo * write_5(uv * 20., vec2(1., 18.), textDEMO));
if (visible) {
float mask = step(0.0001, length(uv));
color *= mix(mask, 1 - mask, invert ? 1 : 0);
-1
View File
@@ -381,7 +381,6 @@ float write_int_left(vec2 uv, vec2 pos, int value, int magnitude)
int i;
int m = 1;
float d = 0.;
pos.x -= magnitude;
for (i = 0; i < magnitude; i++) {
if (i == 0 || value >= m) {
pos.x += 1.;
+1 -1
View File
@@ -222,7 +222,7 @@ vec4 debug(vec2 vUV)
// show mix
f += char_at(uv2, vec2(1.55, -.6), mix_type ? 0x4B : 0x4D);
f = mix(f, 1 - f, rect(uv2, vec2(2., -.9 + .9 * mix_value), vec2(.9, .9 * mix_value)));
f = mix(f, 1 - f, rect(uv2, vec2(.2, -.9 + .9 * mix_value), vec2(.9, .9 * mix_value)));
// show debug info
float v = 0.;
+2 -1
View File
@@ -1,7 +1,6 @@
#include inc_res.glsl
#include inc_magic.glsl
#include inc_functions.glsl
#include inc_cp437.glsl
#ifndef INC_FX
#define INC_FX
@@ -246,6 +245,8 @@ subroutine(fx_stage_sub) vec4 fx_8(vec2 vUV, sampler2D previous, sampler2D feedb
return fx_master(c0, c, seed, m0);
}
#include inc_cp437.glsl
// FX 9 : cp437
subroutine(fx_stage_sub) vec4 fx_9(vec2 vUV, sampler2D previous, sampler2D feedback, int seed, vec3 b1, vec2 f1, vec3 b2, vec2 f2, vec3 b3, vec2 f3, vec3 m0)
{
+5 -11
View File
@@ -1,20 +1,14 @@
#ifndef INC_RAND
#define INC_RAND
// https://thebookofshaders.com/10/
// https://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/
float rand(float seed){
const float c = 43758.5453;
return fract(sin(seed) * c);
float v = pow(abs(seed), .8571429); // 6. / 7.
v *= sin(v) + 1.;
return fract(v);
}
float rand(vec2 co)
{
const float a = 12.9898;
const float b = 78.233;
float dt= dot(co.xy ,vec2(a,b));
return rand(dt);
float rand(vec2 n){
return rand(n.x * 1234. + n.y * 9876.);
}
#endif
-8
View File
@@ -49,7 +49,6 @@ static void print_help(int status_code) {
"[--wayland] "
"[--cocoa] "
"[--win32] "
"[-as / -nas] "
"[-oma=MAJOR] "
"[-omi=MINOR] "
"\n\n"
@@ -88,8 +87,6 @@ static void print_help(int status_code) {
" -nls, --no-load-state do not load saved state\n"
" -ss, --save-state save state (default)\n"
" -nss, --no-save-state do not save state\n"
" -as, --auto-save continuously save state (every ~10ms)\n"
" -nas, --no-auto-save do not continuously save state (default)\n"
" -mr, --midi-reconnect auto-reconnect midi (default)\n"
" -nmr, --no-midi-reconnect do not auto-reconnect midi\n"
" -tm, --trace-midi print midi code and values\n"
@@ -171,7 +168,6 @@ void args_parse(Parameters *params, int argc, char **argv) {
params->internal_size = 720;
params->load_state = true;
params->save_state = true;
params->auto_save = false;
params->midi_reconnect = true;
params->trace_midi = false;
params->trace_fps = false;
@@ -238,10 +234,6 @@ void args_parse(Parameters *params, int argc, char **argv) {
params->save_state = true;
} else if (is_arg(arg, "-nss") || is_arg(arg, "--no-save-state")) {
params->save_state = false;
} else if (is_arg(arg, "-as") || is_arg(arg, "--auto-save")) {
params->auto_save = true;
} else if (is_arg(arg, "-nas") || is_arg(arg, "--no-auto-save")) {
params->auto_save = false;
} else if (is_arg(arg, "-mr") || is_arg(arg, "--midi-reconnect")) {
params->midi_reconnect = true;
} else if (is_arg(arg, "-nmr") || is_arg(arg, "--no-midi-reconnect")) {
-7
View File
@@ -87,12 +87,6 @@
#define MAX_TAP_VALUES 10
#endif
/* STATE */
#ifndef STATE_AUTO_SAVE_SECONDS
#define STATE_AUTO_SAVE_SECONDS 0.1
#endif
/* OPENGL */
#ifndef OPENGL_MAJOR_VERSION
@@ -104,7 +98,6 @@
#endif
/* GLFW CONSTANTS */
#ifndef GLFW_BACKENDS
#define GLFW_BACKEND_ANY 0
#define GLFW_BACKEND_X11 1
+1 -3
View File
@@ -109,12 +109,10 @@ void file_dump(const char *path, const char *content) {
fclose(file_pointer);
}
void file_write(const char *path, const StringArray *lines, const bool log) {
void file_write(const char *path, const StringArray *lines) {
FILE *file_pointer;
if (log) {
log_info("Writing %s...", path);
}
// open file
file_pointer = fopen(path, "w");
+1 -1
View File
@@ -9,7 +9,7 @@ bool file_should_update(const File *file);
bool file_update(File *file);
void file_write(const char *path, const StringArray *lines, const bool log);
void file_write(const char *path, const StringArray *lines);
void file_dump(const char *path, const char *content);
-1
View File
@@ -207,7 +207,6 @@ static void start_state_background_write() {
process_args->context = &context;
process_args->state_config = project.state_config;
process_args->midi = &midi;
process_args->auto_save = init_params.auto_save;
if (pthread_create(&thread, NULL, state_background_write, process_args) ==
0) {
pthread_detach(thread);
+6 -51
View File
@@ -12,7 +12,6 @@
#include "rand.h"
#include "state.h"
#include "tempo.h"
#include "timer.h"
static void safe_midi_write(MidiDevice midi, unsigned int code,
unsigned char value) {
@@ -180,44 +179,13 @@ static void load_from_index_file(Context *context, StateConfig state_config,
}
static void save_to_file(const Context *context, StateConfig state_config,
const char *state_file, const bool log) {
const char *state_file) {
StringArray lines;
if (log) {
log_info("Saving state to '%s'...", state_file);
}
lines.length = 0;
snprintf(lines.values[lines.length++], STR_LEN, "time=%f", context->time);
if (lines.length > ARRAY_SIZE) {
log_error("Too many values to save");
return;
}
snprintf(lines.values[lines.length++], STR_LEN, "beats=%f",
context->tempo_total);
if (lines.length > ARRAY_SIZE) {
log_error("Too many values to save");
return;
}
snprintf(lines.values[lines.length++], STR_LEN, "demo=%d",
context->demo ? 1 : 0);
if (lines.length > ARRAY_SIZE) {
log_error("Too many values to save");
return;
}
snprintf(lines.values[lines.length++], STR_LEN, "auto_random=%d",
context->auto_random ? 1 : 0);
if (lines.length > ARRAY_SIZE) {
log_error("Too many values to save");
return;
}
snprintf(lines.values[lines.length++], STR_LEN, "auto_random_cycle=%d",
context->auto_random_cycle);
if (lines.length > ARRAY_SIZE) {
log_error("Too many values to save");
return;
}
snprintf(lines.values[lines.length++], STR_LEN, "tempo=%d",
(unsigned int)context->tempo.tempo);
if (lines.length > ARRAY_SIZE) {
@@ -281,16 +249,16 @@ static void save_to_file(const Context *context, StateConfig state_config,
}
}
file_write(state_file, &lines, log);
file_write(state_file, &lines);
}
static void save_to_default_file(const Context *context,
StateConfig state_config, const bool log) {
StateConfig state_config) {
char state_file[STR_LEN];
snprintf(state_file, STR_LEN, "%s.txt", state_config.save_file_prefix);
save_to_file(context, state_config, state_file, log);
save_to_file(context, state_config, state_file);
}
static void save_to_index_file(const Context *context, StateConfig state_config,
@@ -300,7 +268,7 @@ static void save_to_index_file(const Context *context, StateConfig state_config,
snprintf(state_file, STR_LEN, "%s.%d.txt", state_config.save_file_prefix,
index);
save_to_file(context, state_config, state_file, true);
save_to_file(context, state_config, state_file);
}
void state_parse_config(StateConfig *state_config, const ConfigFile *config) {
@@ -759,20 +727,16 @@ void *state_background_write(void *args) {
Context *context = process_args->context;
StateConfig state_config = process_args->state_config;
MidiDevice *midi = process_args->midi;
bool auto_save = process_args->auto_save;
bool beat_active;
bool last_active;
bool change;
bool last_change;
bool do_auto_save;
bool last_auto_save;
log_info("(state) background writing started");
last_active = false;
last_change = false;
last_auto_save = false;
while (!context->stop) {
beat_active = tempo_progress(&context->tempo, 1.0) < 0.5;
@@ -798,15 +762,6 @@ void *state_background_write(void *args) {
}
last_change = change;
do_auto_save = fmod(context->time, STATE_AUTO_SAVE_SECONDS) <
STATE_AUTO_SAVE_SECONDS * 0.5;
if (auto_save && do_auto_save && !last_auto_save) {
save_to_default_file(context, state_config, false);
}
last_auto_save = do_auto_save;
}
log_info("(state) background writing stopped by main thread");
@@ -847,5 +802,5 @@ void state_init(Context *context, StateConfig state_config, bool demo,
}
void state_save(const Context *context, StateConfig state_config) {
save_to_default_file(context, state_config, true);
save_to_default_file(context, state_config);
}
-2
View File
@@ -55,7 +55,6 @@ typedef struct Parameters {
unsigned int internal_size;
bool load_state;
bool save_state;
bool auto_save;
bool midi_reconnect;
bool trace_midi;
bool trace_fps;
@@ -280,7 +279,6 @@ typedef struct StateBackgroundWriteArgs {
Context *context;
StateConfig state_config;
MidiDevice *midi;
bool auto_save;
} StateBackgroundWriteArgs;
// timer.c