Skip to content

Commit d2d07b4

Browse files
commit
1 parent abe09cc commit d2d07b4

File tree

1,035 files changed

+2352525
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,035 files changed

+2352525
-0
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
build/
2+
3+
*.exe
4+
*.lib
5+
*.pdb
6+
*.exp
7+
8+
lf.txt
9+
Makefile
10+
nob.c
11+
nob.exe
12+
nob.exe.old
13+
nob.h

assets_icons/clock.256x256.ico

264 KB
Binary file not shown.

assets_shaders/lighting.fs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#version 330
2+
3+
// Input vertex attributes (from vertex shader)
4+
in vec3 fragPosition;
5+
in vec2 fragTexCoord;
6+
//in vec4 fragColor;
7+
in vec3 fragNormal;
8+
9+
// Input uniform values
10+
uniform sampler2D texture0;
11+
uniform vec4 colDiffuse;
12+
13+
// Output fragment color
14+
out vec4 finalColor;
15+
16+
// NOTE: Add here your custom variables
17+
18+
#define MAX_LIGHTS 4
19+
#define LIGHT_DIRECTIONAL 0
20+
#define LIGHT_POINT 1
21+
22+
struct Light {
23+
int enabled;
24+
int type;
25+
vec3 position;
26+
vec3 target;
27+
vec4 color;
28+
};
29+
30+
// Input lighting values
31+
uniform Light lights[MAX_LIGHTS];
32+
uniform vec4 ambient;
33+
uniform vec3 viewPos;
34+
uniform vec4 texelColor;
35+
36+
void main()
37+
{
38+
vec3 lightDot = vec3(0.0);
39+
vec3 normal = normalize(fragNormal);
40+
vec3 viewD = normalize(viewPos - fragPosition);
41+
vec3 specular = vec3(0.0);
42+
43+
// NOTE: Implement here your fragment shader code
44+
45+
for (int i = 0; i < MAX_LIGHTS; i++)
46+
{
47+
if (lights[i].enabled == 1)
48+
{
49+
vec3 light = vec3(0.0);
50+
51+
if (lights[i].type == LIGHT_DIRECTIONAL)
52+
{
53+
light = -normalize(lights[i].target - lights[i].position);
54+
}
55+
56+
if (lights[i].type == LIGHT_POINT)
57+
{
58+
light = normalize(lights[i].position - fragPosition);
59+
}
60+
61+
float NdotL = max(dot(normal, light), 0.0);
62+
lightDot += lights[i].color.rgb*NdotL;
63+
64+
float specCo = 0.0;
65+
if (NdotL > 0.0) specCo = pow(max(0.0, dot(viewD, reflect(-(light), normal))), 16.0); // 16 refers to shine
66+
specular += specCo;
67+
}
68+
}
69+
70+
finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
71+
finalColor += texelColor*(ambient/10.0)*colDiffuse;
72+
73+
// Gamma correction
74+
finalColor = pow(finalColor, vec4(1.0/2.2));
75+
}

assets_shaders/lighting.vs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#version 330
2+
3+
// Input vertex attributes
4+
in vec3 vertexPosition;
5+
in vec2 vertexTexCoord;
6+
in vec3 vertexNormal;
7+
in vec4 vertexColor;
8+
9+
// Input uniform values
10+
uniform mat4 mvp;
11+
uniform mat4 matModel;
12+
uniform mat4 matNormal;
13+
14+
// Output vertex attributes (to fragment shader)
15+
out vec3 fragPosition;
16+
out vec2 fragTexCoord;
17+
out vec4 fragColor;
18+
out vec3 fragNormal;
19+
20+
// NOTE: Add here your custom variables
21+
22+
void main()
23+
{
24+
// Send vertex attributes to fragment shader
25+
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
26+
fragTexCoord = vertexTexCoord;
27+
fragColor = vertexColor;
28+
fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0)));
29+
30+
// Calculate final vertex position
31+
gl_Position = mvp*vec4(vertexPosition, 1.0);
32+
}

assets_shaders/lighting_es.fs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#version 100
2+
3+
precision mediump float;
4+
5+
// Input vertex attributes (from vertex shader)
6+
varying vec3 fragPosition;
7+
varying vec2 fragTexCoord;
8+
//varying vec4 fragColor;
9+
varying vec3 fragNormal;
10+
11+
// Input uniform values
12+
uniform sampler2D texture0;
13+
uniform vec4 colDiffuse;
14+
15+
// NOTE: Add here your custom variables
16+
17+
#define MAX_LIGHTS 4
18+
#define LIGHT_DIRECTIONAL 0
19+
#define LIGHT_POINT 1
20+
21+
struct Light {
22+
int enabled;
23+
int type;
24+
vec3 position;
25+
vec3 target;
26+
vec4 color;
27+
};
28+
29+
// Input lighting values
30+
uniform Light lights[MAX_LIGHTS];
31+
uniform vec4 ambient;
32+
uniform vec3 viewPos;
33+
uniform vec4 texelColor;
34+
35+
void main()
36+
{
37+
// Texel color fetching from texture sampler
38+
vec3 lightDot = vec3(0.0);
39+
vec3 normal = normalize(fragNormal);
40+
vec3 viewD = normalize(viewPos - fragPosition);
41+
vec3 specular = vec3(0.0);
42+
43+
// NOTE: Implement here your fragment shader code
44+
45+
for (int i = 0; i < MAX_LIGHTS; i++)
46+
{
47+
if (lights[i].enabled == 1)
48+
{
49+
vec3 light = vec3(0.0);
50+
51+
if (lights[i].type == LIGHT_DIRECTIONAL)
52+
{
53+
light = -normalize(lights[i].target - lights[i].position);
54+
}
55+
56+
if (lights[i].type == LIGHT_POINT)
57+
{
58+
light = normalize(lights[i].position - fragPosition);
59+
}
60+
61+
float NdotL = max(dot(normal, light), 0.0);
62+
lightDot += lights[i].color.rgb*NdotL;
63+
64+
float specCo = 0.0;
65+
if (NdotL > 0.0) specCo = pow(max(0.0, dot(viewD, reflect(-(light), normal))), 16.0); // 16 refers to shine
66+
specular += specCo;
67+
}
68+
}
69+
70+
vec4 finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
71+
finalColor += texelColor*(ambient/10.0);
72+
73+
// Gamma correction
74+
gl_FragColor = pow(finalColor, vec4(1.0/2.2));
75+
}

assets_shaders/lighting_es.vs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#version 100
2+
3+
// Input vertex attributes
4+
attribute vec3 vertexPosition;
5+
attribute vec2 vertexTexCoord;
6+
attribute vec3 vertexNormal;
7+
attribute vec4 vertexColor;
8+
9+
// Input uniform values
10+
uniform mat4 mvp;
11+
uniform mat4 matModel;
12+
13+
// Output vertex attributes (to fragment shader)
14+
varying vec3 fragPosition;
15+
varying vec2 fragTexCoord;
16+
varying vec4 fragColor;
17+
varying vec3 fragNormal;
18+
19+
// NOTE: Add here your custom variables
20+
21+
// https://github.com/glslify/glsl-inverse
22+
mat3 inverse(mat3 m)
23+
{
24+
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
25+
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
26+
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
27+
28+
float b01 = a22*a11 - a12*a21;
29+
float b11 = -a22*a10 + a12*a20;
30+
float b21 = a21*a10 - a11*a20;
31+
32+
float det = a00*b01 + a01*b11 + a02*b21;
33+
34+
return mat3(b01, (-a22*a01 + a02*a21), (a12*a01 - a02*a11),
35+
b11, (a22*a00 - a02*a20), (-a12*a00 + a02*a10),
36+
b21, (-a21*a00 + a01*a20), (a11*a00 - a01*a10))/det;
37+
}
38+
39+
// https://github.com/glslify/glsl-transpose
40+
mat3 transpose(mat3 m)
41+
{
42+
return mat3(m[0][0], m[1][0], m[2][0],
43+
m[0][1], m[1][1], m[2][1],
44+
m[0][2], m[1][2], m[2][2]);
45+
}
46+
47+
void main()
48+
{
49+
// Send vertex attributes to fragment shader
50+
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
51+
fragTexCoord = vertexTexCoord;
52+
fragColor = vertexColor;
53+
54+
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
55+
fragNormal = normalize(normalMatrix*vertexNormal);
56+
57+
// Calculate final vertex position
58+
gl_Position = mvp*vec4(vertexPosition, 1.0);
59+
}

assets_sounds/tick.wav

97.2 KB
Binary file not shown.

assets_sounds/ticking_clock.wav

2.69 MB
Binary file not shown.

assets_sounds/tock.wav

90.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)