-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderingcmd-example-2.c
More file actions
49 lines (35 loc) · 1.1 KB
/
renderingcmd-example-2.c
File metadata and controls
49 lines (35 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "cmdtoymath.h"
#include "cmdtoyengine.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
vec3 mainImage(vec2 * fragCoord){
vec3 fragColor; //out, its vec3 and not vec4 like in shader toy
fragColor = (vec3){1.000,1.000,1.000};
float aspectRatio = iResolution.x / iResolution.y;
//printf("%f", iResolution.x);
// Normalized pixel coordinates (from 0 to 1)
vec2 fragCordScaled = vec2_scale(*fragCoord, 2.0);
fragCordScaled.x = fragCordScaled.x / iResolution.x;
fragCordScaled.y = fragCordScaled.y / iResolution.y;
vec2 uv = (vec2){fragCordScaled.x - 1., fragCordScaled.y - 1.};
// Correct for aspect ratio
uv.x = uv.x * aspectRatio;
vec2_scale_p(&uv, sin(iTime) * 50.);
uv.x = floor(uv.x);
uv.y = floor(uv.y);
if(fmod(uv.x + uv.y, 2.) == 0.){
if(sin(iTime + uv.x) + cos(iTime + uv.y) > sin(iTime))
fragColor = (vec3){.000,.000,.000};
}else{
if(fmod(uv.y, 2.) != 0.)
fragColor = (vec3){.000,.000,.000};
}
return fragColor;
}
int main(int argc, char const *argv[])
{
cmdToyRender(4, 10, mainImage);
return 0;
}