This commit is contained in:
Rakarake 2025-12-10 19:07:35 +01:00
parent 1a190594fe
commit 90d565ff8d
3 changed files with 67 additions and 11 deletions

View file

@ -1,6 +1,5 @@
#version 330 core
out vec4 FragColor;
in vec2 uv;
uniform vec2 WindowSize;
uniform float time;
@ -8,7 +7,28 @@ float rand(vec2 co){
return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
}
float cell_size = 0.1;
void main() {
float glob = rand(gl_FragCoord.xy / WindowSize + time);
FragColor = vec4(glob * (sin(time)/2 + 0.5), glob, 1.0, 1.0); //vec4(gl_FragCoord.xy / WindowSize, 0.0, 1.0);
// We'll make origin in the top-left.
vec2 uv = gl_FragCoord.xy / WindowSize;
uv.y = 1.0 - uv.y;
vec2 grid_edge_offset = mod(uv, cell_size);
// c: corner
vec2 c_tl = uv - grid_edge_offset;
vec2 c_tr = uv - grid_edge_offset + vec2(cell_size, 0);
vec2 c_bl = uv - grid_edge_offset + vec2(0, cell_size);
vec2 c_br = uv - grid_edge_offset + vec2(cell_size, cell_size);
// random vectors
vec2 c_tl_ran = rand(c_tl);
vec2 c_tr_ran = rand(c_tr);
vec2 c_bl_ran = rand(c_bl);
vec2 c_br_ran = rand(c_br);
// offset vectors
vec2 c_tl_off = c_tl - uv;
vec2 c_tr_off = c_tr - uv;
vec2 c_bl_off = c_bl - uv;
vec2 c_br_off = c_br - uv;
FragColor =
}

35
main.c
View file

@ -13,8 +13,9 @@ void checkGlError() {
}
}
/// returns 0 if failed.
GLuint compile_shader(GLuint type, const char *src) {
GLuint id = glCreateShader(GL_FRAGMENT_SHADER);
GLuint id = glCreateShader(type);
glShaderSource(id, 1, &src, 0);
glCompileShader(id);
@ -34,16 +35,19 @@ GLuint compile_shader(GLuint type, const char *src) {
return id;
}
/// returns 0 if failed.
GLuint create_shader(const char *fragment_src) {
GLuint program = glCreateProgram();
GLuint fragment_shader = compile_shader(GL_FRAGMENT_SHADER, fragment_src);
glAttachShader(program, fragment_shader);
glLinkProgram(program);
glValidateProgram(program);
glDeleteShader(fragment_shader);
return program;
if (!(fragment_shader == 0)) {
glAttachShader(program, fragment_shader);
glLinkProgram(program);
glValidateProgram(program);
glDeleteShader(fragment_shader);
return program;
} else {
return 0;
}
}
GLuint load_shader(const char *path) {
@ -60,6 +64,21 @@ GLuint load_shader(const char *path) {
GLuint shader = create_shader(string);
if (shader == 0) {
// print file
int line_count = 1;
printf("%i\t", line_count);
line_count++;
for (int i = 0; i < length; i++) {
printf("%c", string[i]);
if (string[i] == '\n') {
printf("%i\t", line_count);
line_count++;
}
}
printf("\n");
}
free(string);
return shader;
}

17
pulsating-noise.glsl Normal file
View file

@ -0,0 +1,17 @@
#version 330 core
out vec4 FragColor;
uniform vec2 WindowSize;
uniform float time;
float rand(vec2 co){
return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
}
float cell_size = 0.1;
void main() {
vec2 uv = gl_FragCoord.xy / WindowSize;
// grid
float glob = rand(uv + time);
FragColor = vec4(glob * (sin(time)/2 + 0.5), glob, 1.0, 1.0); //vec4(gl_FragCoord.xy / WindowSize, 0.0, 1.0);
}