2021-02-12 03:43:11 +01:00
|
|
|
#version 430 core
|
|
|
|
|
|
|
|
layout(location = 0) in vec3 vertexPosition;
|
|
|
|
layout(location = 1) in vec2 vertexTexCoord;
|
|
|
|
layout(location = 2) in vec3 vertexNormal;
|
|
|
|
layout (location = 3) in vec3 aTangent;
|
|
|
|
layout (location = 4) in vec3 aBitangent;
|
|
|
|
layout (location = 5) in mat4 aInstanceMatrix;
|
2021-02-15 23:15:35 +01:00
|
|
|
layout (location = 9) in mat3 normalMatrix;
|
2021-02-12 03:43:11 +01:00
|
|
|
|
|
|
|
struct PointLight {
|
|
|
|
vec3 position;
|
|
|
|
vec3 color;
|
|
|
|
float intensity;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MAX_POINT_LIGHTS 16
|
|
|
|
|
|
|
|
uniform mat4 projection;
|
|
|
|
uniform mat4 view;
|
|
|
|
uniform vec3 cameraPos;
|
|
|
|
uniform PointLight pointLights[MAX_POINT_LIGHTS];
|
|
|
|
uniform int LightsCount;
|
|
|
|
|
|
|
|
out vec3 fragPos;
|
|
|
|
out vec2 vTexCoord;
|
|
|
|
out vec3 LightPosTS[MAX_POINT_LIGHTS];
|
|
|
|
out vec3 CameraPosTS;
|
|
|
|
out vec3 FragPosTS;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
gl_Position = projection * view * aInstanceMatrix * vec4(vertexPosition, 1.0);
|
|
|
|
|
2021-02-15 23:15:35 +01:00
|
|
|
//mat3 normalMatrix = transpose(inverse(mat3(aInstanceMatrix)));
|
2021-02-12 03:43:11 +01:00
|
|
|
|
|
|
|
vec3 T = normalize(normalMatrix * aTangent);
|
|
|
|
vec3 N = normalize(normalMatrix * vertexNormal);
|
|
|
|
// re-orthogonalize T with respect to N
|
|
|
|
T = normalize(T - dot(T, N) * N);
|
|
|
|
// then retrieve perpendicular vector B with the cross product of T and N
|
|
|
|
vec3 B = cross(N, T);
|
|
|
|
|
2021-02-25 20:52:49 +01:00
|
|
|
mat3 TBN = transpose(mat3(T, B, N));
|
2021-02-12 03:43:11 +01:00
|
|
|
|
|
|
|
for(int i=0; i<LightsCount; i++)
|
|
|
|
LightPosTS[i] = TBN * pointLights[i].position;
|
2021-02-25 20:52:49 +01:00
|
|
|
fragPos = (aInstanceMatrix*vec4(vertexPosition,1)).xyz;
|
2021-02-12 03:43:11 +01:00
|
|
|
CameraPosTS = TBN * cameraPos;
|
|
|
|
FragPosTS = TBN * fragPos;
|
|
|
|
|
|
|
|
vTexCoord = vertexTexCoord;
|
|
|
|
}
|