gles triangle

This commit is contained in:
Rakarake 2025-12-13 01:56:09 +01:00
parent bd699f2183
commit 9cbcd7acca
3 changed files with 294 additions and 263 deletions

View file

@ -1,69 +1,76 @@
#version 330 core
out vec4 FragColor;
uniform vec2 WindowSize;
uniform float time;
float rand(ivec2 co) {
return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
}
float cell_size = 0.01;
#define PI 3.1415926538
// whatever that corner contributes
float c_dot(vec2 point, vec2 corner) {
ivec2 c = ivec2(round(corner * 100));
float angle = rand(c) * 2*PI;
vec2 random_corner_vec = vec2(cos(angle), sin(angle));
vec2 offset = (point - corner) / cell_size;
float dot_product = dot(random_corner_vec, offset);
// for now just return something
return dot_product;
}
float lerp(float a, float b, float x) {
return a + x*(b-a);
}
// better than built in smoothstep.
float fade(float t) {
return ((6*t - 15)*t + 10)*t*t*t;
}
precision mediump float;
void main() {
// 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);
float c_tl_dot = c_dot(uv, c_tl);
float c_tr_dot = c_dot(uv, c_tr);
float c_bl_dot = c_dot(uv, c_bl);
float c_br_dot = c_dot(uv, c_br);
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
// the uv within the tile (0 to 1)
vec2 tile_uv = (uv - c_tl) / cell_size;
// lerp index
float u = fade(tile_uv.x);
float v = fade(tile_uv.y);
//float u = tile_uv.x;
//float v = tile_uv.y;
//float u = smoothstep(0, 1, tile_uv.x);
//float v = smoothstep(0, 1, tile_uv.y);
//float val = smoothstep(tile_uv.x, smoothstep(tile_uv.y, c_bl_dot, c_tl_dot), smoothstep(tile_uv.y, c_br_dot, c_tr_dot));
float val = lerp(lerp(c_tl_dot, c_bl_dot, v), lerp(c_tr_dot, c_br_dot, v), u);
//float val = tile_uv.y;
//float val = c_bl_dot*2 + 0.5;
//val = val * 20;
float out_val = val /2 + 0.5;
FragColor = vec4(out_val, out_val, out_val, 1);
//float yes = 0.5 + (c_dot(uv, c_tl) + c_dot(uv, c_tr) + c_dot(uv, c_bl) + c_dot(uv, c_br)) / 2;
//FragColor = vec4(yes, yes, yes, 1);
}
//#version 330 core
//out vec4 FragColor;
//uniform vec2 WindowSize;
//uniform float time;
//
//float rand(ivec2 co) {
// return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
//}
//
//float cell_size = 0.01;
//
//#define PI 3.1415926538
//
//// whatever that corner contributes
//float c_dot(vec2 point, vec2 corner) {
// ivec2 c = ivec2(round(corner * 100));
// float angle = rand(c) * 2*PI;
// vec2 random_corner_vec = vec2(cos(angle), sin(angle));
// vec2 offset = (point - corner) / cell_size;
// float dot_product = dot(random_corner_vec, offset);
// // for now just return something
// return dot_product;
//}
//
//float lerp(float a, float b, float x) {
// return a + x*(b-a);
//}
//
//// better than built in smoothstep.
//float fade(float t) {
// return ((6*t - 15)*t + 10)*t*t*t;
//}
//
//void main() {
// // 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);
// float c_tl_dot = c_dot(uv, c_tl);
// float c_tr_dot = c_dot(uv, c_tr);
// float c_bl_dot = c_dot(uv, c_bl);
// float c_br_dot = c_dot(uv, c_br);
//
// // the uv within the tile (0 to 1)
// vec2 tile_uv = (uv - c_tl) / cell_size;
//
// // lerp index
// float u = fade(tile_uv.x);
// float v = fade(tile_uv.y);
// //float u = tile_uv.x;
// //float v = tile_uv.y;
// //float u = smoothstep(0, 1, tile_uv.x);
// //float v = smoothstep(0, 1, tile_uv.y);
// //float val = smoothstep(tile_uv.x, smoothstep(tile_uv.y, c_bl_dot, c_tl_dot), smoothstep(tile_uv.y, c_br_dot, c_tr_dot));
// float val = lerp(lerp(c_tl_dot, c_bl_dot, v), lerp(c_tr_dot, c_br_dot, v), u);
// //float val = tile_uv.y;
// //float val = c_bl_dot*2 + 0.5;
// //val = val * 20;
// float out_val = val /2 + 0.5;
// FragColor = vec4(out_val, out_val, out_val, 1);
//
// //float yes = 0.5 + (c_dot(uv, c_tl) + c_dot(uv, c_tr) + c_dot(uv, c_bl) + c_dot(uv, c_br)) / 2;
// //FragColor = vec4(yes, yes, yes, 1);
//}