added iTime uniform
parent
f850e3f082
commit
c5ee25113f
5
sdfps.c
5
sdfps.c
|
@ -59,10 +59,12 @@ void init(Sdfps* s) { /* TODO: Error checks */
|
||||||
|
|
||||||
/* viewport resolution (in pixels), z = 1 */
|
/* viewport resolution (in pixels), z = 1 */
|
||||||
"uniform vec3 iResolution;\n"
|
"uniform vec3 iResolution;\n"
|
||||||
|
/* playback time in seconds */
|
||||||
|
"uniform float iTime;\n"
|
||||||
|
|
||||||
"out vec4 out_color;\n"
|
"out vec4 out_color;\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
"vec2 xy = gl_FragCoord.xy;\n"
|
"vec2 xy = gl_FragCoord.xy + vec2(sin(iTime), cos(iTime));\n"
|
||||||
"out_color = vec4(sin(xy.x), sin(xy.y), sin(xy.x) + sin(xy.y), 1);\n"
|
"out_color = vec4(sin(xy.x), sin(xy.y), sin(xy.x) + sin(xy.y), 1);\n"
|
||||||
"if(xy.x > iResolution.x / 2.0) out_color = out_color.zxyw;\n"
|
"if(xy.x > iResolution.x / 2.0) out_color = out_color.zxyw;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
@ -120,6 +122,7 @@ void render(Sdfps *s) {
|
||||||
GLuint iResolution = glGetUniformLocation(s -> shader_program, "iResolution");
|
GLuint iResolution = glGetUniformLocation(s -> shader_program, "iResolution");
|
||||||
// TODO: error check?
|
// TODO: error check?
|
||||||
glUniform3f(iResolution, (f32) fb_w, (f32) fb_h, 1.0f);
|
glUniform3f(iResolution, (f32) fb_w, (f32) fb_h, 1.0f);
|
||||||
|
glUniform1f(glGetUniformLocation(s -> shader_program, "iTime"), 0.001f * (f32) SDL_GetTicks());
|
||||||
|
|
||||||
glClearColor(0.1f, 0.25f, 0.24f, 1);
|
glClearColor(0.1f, 0.25f, 0.24f, 1);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
Loading…
Reference in New Issue