Skip to content

Commit 19c2d64

Browse files
Merge pull request #19 from ProtectedVariable/animation-system
Animation system
2 parents 4c083c7 + cf4c115 commit 19c2d64

Some content is hidden

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

63 files changed

+2401
-5739
lines changed

Assets/Shaders/frag_uniforms.glsl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#define MAX_LIGHTS 16
2+
3+
struct Light {
4+
vec3 position;
5+
vec3 rotation;
6+
vec3 color;
7+
float distance_dropoff;
8+
int type;
9+
};
10+
11+
layout(std140, binding = 1) uniform SceneLightsUBO {
12+
Light lights[MAX_LIGHTS];
13+
vec4 ambient_light;
14+
int light_count;
15+
};

Assets/Shaders/lastpass.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#version 330 core
1+
#version 420 core
22

33
out vec4 fragColor;
44

Assets/Shaders/lastpass.vs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#version 330 core
1+
#version 420 core
22
layout (location = 0) in vec3 aPos;
33
layout (location = 1) in vec2 aUV;
44

Assets/Shaders/normal.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#version 330 core
1+
#version 420 core
22

33
out vec4 frag_color;
44

Assets/Shaders/normal.vs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
#version 330 core
1+
#version 420 core
2+
3+
#include "vert_uniforms.glsl"
24

35
layout (location = 0) in vec3 vertex;
46
layout (location = 1) in vec3 normal;
57

6-
uniform mat4 projection;
7-
uniform mat4 view;
88
uniform mat4 model;
99

1010
out vec3 f_normal;
1111

1212
void main() {
1313
f_normal = abs(normal);
14-
gl_Position = projection * view * model * vec4(vertex, 1.0);
14+
gl_Position = uProjection * uView * model * vec4(vertex, 1.0);
1515
}

Assets/Shaders/phong.fs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
#version 330 core
2-
#define ICE_MAX_LIGHTS (16)
1+
#version 420 core
32

4-
out vec4 frag_color;
3+
#include "frag_uniforms.glsl"
54

6-
struct Light {
7-
vec3 position;
8-
vec3 rotation;
9-
vec3 color;
10-
int type; //0 = Point, 1 = Directional, 2 = Spot
11-
float distance_dropoff;
12-
};
5+
out vec4 frag_color;
136

147
struct Material {
158
vec4 albedo;
@@ -26,9 +19,6 @@ struct Material {
2619
sampler2D normal_map;
2720
};
2821

29-
uniform vec3 ambient_light;
30-
uniform Light lights[ICE_MAX_LIGHTS];
31-
uniform int light_count;
3222
uniform Material material;
3323

3424
in vec3 fnormal;
@@ -88,7 +78,7 @@ void main() {
8878
normal = fnormal;
8979
}
9080
//ambient
91-
vec4 color_accumulator = material.ambient * vec4(ambient_light, 1.0);
81+
vec4 color_accumulator = material.ambient * ambient_light;
9282
if(material.use_ambient_map) {
9383
color_accumulator *= texture(material.ambient_map, ftex_coords);
9484
}

Assets/Shaders/phong.vs

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,67 @@
1-
#version 330 core
1+
#version 420 core
2+
3+
#include "vert_uniforms.glsl"
4+
#define MAX_BONES 100
5+
#define MAX_BONE_INFLUENCE 4
26

37
layout (location = 0) in vec3 vertex;
48
layout (location = 1) in vec3 normal;
59
layout (location = 2) in vec2 tex_coords;
10+
layout (location = 3) in vec3 tangent;
11+
layout (location = 4) in vec3 bitangent;
12+
layout (location = 5) in ivec4 bone_ids;
13+
layout (location = 6) in vec4 bone_weights;
614

7-
uniform mat4 projection;
8-
uniform mat4 view;
915
uniform mat4 model;
16+
uniform mat4 bonesTransformMatrices[MAX_BONES];
17+
uniform mat4 bonesOffsetMatrices[MAX_BONES];
1018

1119
out vec3 fnormal;
20+
out vec3 ftangent;
21+
out vec3 fbitangent;
1222
out vec3 fposition;
1323
out vec3 fview;
1424
out vec2 ftex_coords;
1525

1626
void main() {
17-
fview = (inverse(view) * vec4(0, 0, 0, 1)).xyz;
18-
fnormal = normalize(mat3(transpose(inverse(model))) * normal);
19-
fposition = (model * vec4(vertex, 1.0)).xyz;
27+
vec4 totalPosition = vec4(0.0f);
28+
vec3 totalNormal = vec3(0.0f);
29+
vec3 totalTangent = vec3(0.0f);
30+
vec3 totalBitangent = vec3(0.0f);
31+
32+
if(bone_ids == ivec4(-1)) {
33+
totalPosition = vec4(vertex, 1.0f);
34+
totalNormal = normal;
35+
} else {
36+
for(int i = 0 ; i < MAX_BONE_INFLUENCE ; i++) {
37+
if(bone_ids[i] == -1) continue;
38+
39+
if(bone_ids[i] >= MAX_BONES) {
40+
totalPosition = vec4(vertex, 1.0f);
41+
totalNormal = normal;
42+
break;
43+
}
44+
45+
mat4 finalBonesMatrix = bonesTransformMatrices[bone_ids[i]] * bonesOffsetMatrices[bone_ids[i]];
46+
47+
totalPosition += finalBonesMatrix * vec4(vertex, 1.0f) * bone_weights[i];
48+
49+
mat3 normalMatrix = mat3(transpose(inverse(finalBonesMatrix)));
50+
totalNormal += normalMatrix * normal * bone_weights[i];
51+
totalTangent += normalMatrix * tangent * bone_weights[i];
52+
totalBitangent += normalMatrix * bitangent * bone_weights[i];
53+
}
54+
}
55+
56+
57+
fposition = (model * totalPosition).xyz;
58+
mat3 normalModelMatrix = mat3(transpose(inverse(model)));
59+
fnormal = normalize(normalModelMatrix * totalNormal);
60+
ftangent = normalize(normalModelMatrix * totalTangent);
61+
fbitangent = normalize(normalModelMatrix * totalBitangent);
62+
63+
gl_Position = uProjection * uView * model * totalPosition;
64+
65+
fview = (inverse(uView) * vec4(0, 0, 0, 1)).xyz;
2066
ftex_coords = tex_coords;
21-
gl_Position = projection * view * model * vec4(vertex, 1.0);
2267
}

Assets/Shaders/picking.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#version 330 core
1+
#version 420 core
22

33
uniform int objectID;
44

Assets/Shaders/picking.vs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#version 330 core
1+
#version 420 core
2+
3+
#include "vert_uniforms.glsl"
24

35
layout (location = 0) in vec3 vertex;
46
layout (location = 1) in vec3 normal;
57

6-
uniform mat4 projection;
7-
uniform mat4 view;
88
uniform mat4 model;
99

1010
void main() {
11-
gl_Position = projection * view * model * vec4(vertex, 1.0);
11+
gl_Position = uProjection * uView * model * vec4(vertex, 1.0);
1212
}

Assets/Shaders/skybox.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#version 330 core
1+
#version 420 core
22
out vec4 FragColor;
33

44
in vec3 TexCoords;

0 commit comments

Comments
 (0)