Space-Project/shaders/shader_normal.vert

51 lines
1.1 KiB
GLSL
Raw Permalink Normal View History

#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;
struct PointLight {
vec3 position;
vec3 color;
float intensity;
};
#define MAX_POINT_LIGHTS 16
uniform mat4 transformation;
uniform mat4 modelMatrix;
uniform vec3 cameraPos;
uniform PointLight pointLights[MAX_POINT_LIGHTS];
uniform int LightsCount;
uniform mat3 normalMatrix;
out vec3 fragPos;
out vec2 vTexCoord;
out vec3 LightPosTS[MAX_POINT_LIGHTS];
out vec3 CameraPosTS;
out vec3 FragPosTS;
void main()
{
gl_Position = transformation * vec4(vertexPosition, 1.0);
vec3 T = normalize(normalMatrix * aTangent);
vec3 N = normalize(normalMatrix * vertexNormal);
T = normalize(T - dot(T, N) * N);
vec3 B = cross(N, T);
2021-02-25 20:52:49 +01:00
mat3 TBN = transpose(mat3(T, B, N));
for(int i=0; i<LightsCount; i++)
LightPosTS[i] = TBN * pointLights[i].position;
2021-02-25 20:52:49 +01:00
fragPos = (modelMatrix*vec4(vertexPosition,1)).xyz;
CameraPosTS = TBN * cameraPos;
FragPosTS = TBN * fragPos;
vTexCoord = vertexTexCoord;
}