-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshader.h
43 lines (38 loc) · 823 Bytes
/
shader.h
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
typedef struct
{
int x;
int y;
int z;
} v3;
v3 vec(int x, int y, int z)
{
v3 vec;
vec.x = x;
vec.y = y;
vec.z = z;
return vec;
}
char clamp(int value)
{
if(value < 0) return 0;
else if(value > 255) return 255;
return value;
}
char* genrgbdata(void (*func)(v3 *value, int x, int y), int width, int height)
{
int size = width * height * 3;
char* rgb = (char*)calloc(size, 1);
for(int y = 0; y < height; y++)
{
for(int x = 0; x < width; x++)
{
int index = (x + y * width) * 3;
v3 v;
func(&v, x, -(y - height));
rgb[index + 0] = clamp(v.x);
rgb[index + 1] = clamp(v.y);
rgb[index + 2] = clamp(v.z);
}
}
return rgb;
}