shadertoy: wip

This commit is contained in:
Zack Buhman 2025-11-11 08:30:23 -06:00
parent 50f2babca9
commit 7da080c6cc
3 changed files with 58 additions and 40 deletions

View File

@ -143,7 +143,7 @@ int main()
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
//glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
GLFWwindow* window = glfwCreateWindow(1600, 1200, "LearnOpenGL", NULL, NULL);
GLFWwindow* window = glfwCreateWindow(720, 480, "LearnOpenGL", NULL, NULL);
if (window == NULL) {
const char* description;
glfwGetError(&description);
@ -153,7 +153,7 @@ int main()
}
glfwMakeContextCurrent(window);
glViewport(0, 0, 1600, 1200);
glViewport(0, 0, 720, 480);
//glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
unsigned int vertex_buffer = make_buffer(GL_ARRAY_BUFFER,

View File

@ -1,54 +1,73 @@
#version 120
varying vec2 pos_out;
varying vec2 uv0;
uniform float time;
/*
vec3 palette(float t) {
vec3 a = vec3(0.5, 0.5, 0.5);
vec3 b = vec3(0.5, 0.5, 0.5);
vec3 c = vec3(1.0, 1.0, 1.0);
vec3 d = vec3(0.263, 0.416, 0.557);
return a + b * cos(6.28318548202514648438 * (c * t + d));
vec3 palette(float d) {
vec3 v = d + vec3(0.25, 0.40625, 0.5625); // 40 45 49
v = v * 6.28318548202514648438;
v = cos(v);
return vec3(0.5, 0.5, 0.5) * v + vec3(0.5, 0.5, 0.5); // 48
}
float length2(vec2 v)
{
float n = dot(v, v);
n = 1.0 / sqrt(n);
return 1.0 / n;
}
float pow_(float x, float n)
{
x = log2(x);
x = x * n;
return exp2(x);
}
float sin_(float x)
{
x = x * 0.159154936671257019043 + 0.5; // 48
x = fract(x); // nop
x = sin((x - 0.5) * 6.28318548202514648438); // presubtract (omod)
return x;
}
*/
void main()
{
vec2 uv = pos_out;
//gl_FragColor = vec4(uv, 0, 1);
//gl_FragColor = gl_Color;
float d = length(uv);
vec2 uv = uv0; // temp[1]
//d -= 0.5;
//d = abs(d);
//d = step(0.1, d);
//d = smoothstep(0.0, 0.1, d);
vec4 final_color = vec4(0, 0, 0, 1);
gl_FragColor = vec4(d, 0, 0, 1);
vec3 col2;
/*
vec3 col = vec3(1.0, 2.0, 3.0);
for (float i = 0.0; i < 1.0; i++) {
uv = uv * 1.5; // 60
uv = fract(uv);
uv = uv - 0.5; // 48
d = sin(d * 8.0 + time)/8.0;
d = abs(d);
d = 0.02 / d;
float l = length2(uv0);
col *= d;
float d = i * 0.4 + l; // const[0].a
d = time * 0.4 + d; // const[0].a
gl_FragColor = vec4(col, 1);
*/
/*
vec3 col = palette(d + time);
vec3 col = palette(d);
col2 = col;
break;
d = sin(d * 8.0 + time)/8.0;
d = abs(d);
d = 0.02 / d;
d = exp(-l);
col *= d;
l = length2(uv);
d = l * d;
d = d * 8.0 + time; // 80
d = 0.125 * sin_(d); // omod
d = 1.0 / abs(d);
d = 0.01 * d; // const[0].b
d = pow_(d, 1.2); // const[0].g
gl_FragColor = vec4(col, 1);
*/
final_color.xyz = col * d + final_color.xyz;
}
//gl_FragColor = final_color;
gl_FragColor = vec4(col2, 1);
}

View File

@ -2,11 +2,10 @@
attribute vec3 position;
varying vec2 pos_out;
varying vec2 uv0;
void main()
{
gl_Position = vec4(position, 1);
pos_out = vec2(position.x * 4.0 / 3.0, pos_out.y);
//gl_FrontColor = vec4(position.xy, 0, 1);
uv0 = vec2(position.x * 720.0 / 480.0, position.y);
}