add fps uniform
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
uniform float iTime;
|
uniform float iTime;
|
||||||
uniform float iTempo;
|
uniform float iTempo;
|
||||||
|
uniform int iFPS;
|
||||||
uniform vec2 iResolution;
|
uniform vec2 iResolution;
|
||||||
|
|
||||||
// 2. other frames
|
// 2. other frames
|
||||||
|
|||||||
+1
-1
@@ -12,5 +12,5 @@ void main() {
|
|||||||
vec2 uv1 = (uv0 - .5) * vec2(ratio, 1);
|
vec2 uv1 = (uv0 - .5) * vec2(ratio, 1);
|
||||||
vec3 color = vec3(vUV, sin(iTime * 0.5) * 0.5 + 0.5);
|
vec3 color = vec3(vUV, sin(iTime * 0.5) * 0.5 + 0.5);
|
||||||
color *= 1 - step(cos(iTime) * 0.1 + 0.4, length(uv1));
|
color *= 1 - step(cos(iTime) * 0.1 + 0.4, length(uv1));
|
||||||
fragColor = color + texture(frame0, vUV - 0.04).xyz * 0.5;
|
fragColor = color + texture(frame0, vUV - 0.01).xyz * 0.5;
|
||||||
}
|
}
|
||||||
+17
-1
@@ -7,5 +7,21 @@ in vec2 vUV;
|
|||||||
layout(location = 4) out vec3 fragColor;
|
layout(location = 4) out vec3 fragColor;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
fragColor = vec3(vUV, 0.0) * step(0.3, vUV.x) * step(-0.4, -vUV.x);
|
vec2 uv0 = vUV.st;
|
||||||
|
float ratio = iResolution.x / iResolution.y;
|
||||||
|
vec2 uv1 = uv0 * vec2(ratio, 1);
|
||||||
|
vec2 uv2 = uv1 * 20;
|
||||||
|
|
||||||
|
// uv2 = mod(uv2, 1);
|
||||||
|
|
||||||
|
bool v = false;
|
||||||
|
|
||||||
|
v = v || iFPS > 99 && char(uv2 - vec2(0.5, 0.5), 0x30 + (iFPS % 1000) / 100);
|
||||||
|
v = v || iFPS > 9 && char(uv2 - vec2(1.5, 0.5), 0x30 + (iFPS % 100) / 10);
|
||||||
|
v = v || char(uv2 - vec2(2.5, 0.5), 0x30 + (iFPS % 10));
|
||||||
|
v = v || char(uv2 - vec2(4.0, 0.5), 0x66);
|
||||||
|
v = v || char(uv2 - vec2(5.0, 0.5), 0x70);
|
||||||
|
v = v || char(uv2 - vec2(6.0, 0.5), 0x73);
|
||||||
|
|
||||||
|
fragColor = vec3(v ? 1 : 0);
|
||||||
}
|
}
|
||||||
+1
-1
@@ -7,5 +7,5 @@ in vec2 vUV;
|
|||||||
layout(location = 5) out vec3 fragColor;
|
layout(location = 5) out vec3 fragColor;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
fragColor = texture(frame3, vUV).xyz;
|
fragColor = gauss2(frame3, vUV, 0.001); //texture(frame3, vUV).xyz;
|
||||||
}
|
}
|
||||||
+8
-5
@@ -1,4 +1,5 @@
|
|||||||
#include <linmath.h>
|
#include <linmath.h>
|
||||||
|
#include <math.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@@ -25,8 +26,8 @@ static void key_callback(Window *window, int key,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void compute_fps(Window *window, Timer *timer) {
|
int compute_fps(Window *window, Timer *timer) {
|
||||||
double fps;
|
static double fps;
|
||||||
char title[100];
|
char title[100];
|
||||||
|
|
||||||
if (inc_timer(timer)) {
|
if (inc_timer(timer)) {
|
||||||
@@ -34,6 +35,8 @@ void compute_fps(Window *window, Timer *timer) {
|
|||||||
sprintf(title, PACKAGE " " VERSION " - %.0ffps", fps);
|
sprintf(title, PACKAGE " " VERSION " - %.0ffps", fps);
|
||||||
update_window_title(window, title);
|
update_window_title(window, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (int)round(fps);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hot_reload(ShaderProgram program, File *common_shader_code,
|
void hot_reload(ShaderProgram program, File *common_shader_code,
|
||||||
@@ -59,14 +62,14 @@ void loop(Window *window, ShaderProgram program, bool hr,
|
|||||||
File *common_shader_code, File *fragment_shaders, Timer *timer) {
|
File *common_shader_code, File *fragment_shaders, Timer *timer) {
|
||||||
Context context;
|
Context context;
|
||||||
|
|
||||||
compute_fps(window, timer);
|
|
||||||
|
|
||||||
if (hr) {
|
if (hr) {
|
||||||
hot_reload(program, common_shader_code, fragment_shaders);
|
hot_reload(program, common_shader_code, fragment_shaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
context = get_window_context(window);
|
context = get_window_context(window);
|
||||||
|
|
||||||
|
context.fps = compute_fps(window, timer);
|
||||||
|
|
||||||
apply_program(program, context);
|
apply_program(program, context);
|
||||||
|
|
||||||
refresh_window(window);
|
refresh_window(window);
|
||||||
@@ -132,7 +135,7 @@ void forge_run(Parameters params) {
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
timer = create_timer(60);
|
timer = create_timer(30);
|
||||||
|
|
||||||
while (!window_should_close(window)) {
|
while (!window_should_close(window)) {
|
||||||
loop(window, program, params.hot_reload, &common_shader_code,
|
loop(window, program, params.hot_reload, &common_shader_code,
|
||||||
|
|||||||
+5
-1
@@ -142,6 +142,8 @@ void init_single_program(ShaderProgram *program, int i, bool output) {
|
|||||||
glGetUniformLocation(program->programs[i], "iTime");
|
glGetUniformLocation(program->programs[i], "iTime");
|
||||||
program->itempo_locations[i] =
|
program->itempo_locations[i] =
|
||||||
glGetUniformLocation(program->programs[i], "iTempo");
|
glGetUniformLocation(program->programs[i], "iTempo");
|
||||||
|
program->ifps_locations[i] =
|
||||||
|
glGetUniformLocation(program->programs[i], "iFPS");
|
||||||
program->ires_locations[i] =
|
program->ires_locations[i] =
|
||||||
glGetUniformLocation(program->programs[i], "iResolution");
|
glGetUniformLocation(program->programs[i], "iResolution");
|
||||||
}
|
}
|
||||||
@@ -245,7 +247,9 @@ void apply_program(ShaderProgram program, Context context) {
|
|||||||
|
|
||||||
// set fragment uniforms
|
// set fragment uniforms
|
||||||
glUniform1f(program.itime_locations[i], (const GLfloat)context.time);
|
glUniform1f(program.itime_locations[i], (const GLfloat)context.time);
|
||||||
glUniform1f(program.itempo_locations[i], (const GLfloat)120); // TODO TMP
|
glUniform1f(program.itempo_locations[i],
|
||||||
|
(const GLfloat)120.0f); // TODO TMP
|
||||||
|
glUniform1i(program.ifps_locations[i], (const GLint)context.fps);
|
||||||
glUniform2fv(program.ires_locations[i], 1, (const GLfloat *)&resolution);
|
glUniform2fv(program.ires_locations[i], 1, (const GLfloat *)&resolution);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ typedef struct ShaderProgram {
|
|||||||
|
|
||||||
GLuint itime_locations[FRAG_COUNT];
|
GLuint itime_locations[FRAG_COUNT];
|
||||||
GLuint itempo_locations[FRAG_COUNT];
|
GLuint itempo_locations[FRAG_COUNT];
|
||||||
|
GLuint ifps_locations[FRAG_COUNT];
|
||||||
GLuint ires_locations[FRAG_COUNT];
|
GLuint ires_locations[FRAG_COUNT];
|
||||||
GLuint frames_locations[FRAG_COUNT + 1][TEX_COUNT];
|
GLuint frames_locations[FRAG_COUNT + 1][TEX_COUNT];
|
||||||
GLuint vpos_locations[FRAG_COUNT + 1];
|
GLuint vpos_locations[FRAG_COUNT + 1];
|
||||||
@@ -61,6 +62,7 @@ typedef struct Context {
|
|||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
double time;
|
double time;
|
||||||
|
int fps;
|
||||||
} Context;
|
} Context;
|
||||||
|
|
||||||
typedef struct Timer {
|
typedef struct Timer {
|
||||||
|
|||||||
Reference in New Issue
Block a user