2024-01-11 00:53:24 +01:00
|
|
|
#version 430 core
|
|
|
|
|
|
|
|
layout(location = 0) in vec3 vertexPosition;
|
|
|
|
layout(location = 1) in vec3 vertexNormal;
|
|
|
|
layout(location = 2) in vec2 vertexTexCoord;
|
2024-01-12 14:49:53 +01:00
|
|
|
layout(location = 3) in vec3 vertexTangent;
|
|
|
|
layout(location = 4) in vec3 vertexBitangent;
|
2024-01-11 00:53:24 +01:00
|
|
|
|
|
|
|
uniform mat4 transformation;
|
|
|
|
uniform mat4 modelMat;
|
|
|
|
|
2024-01-12 14:49:53 +01:00
|
|
|
uniform vec3 cameraPos;
|
|
|
|
uniform vec3 sunPos;
|
|
|
|
uniform vec3 reflectorPos;
|
|
|
|
|
|
|
|
out vec3 vertexPosWld;
|
2024-01-11 00:53:24 +01:00
|
|
|
out vec2 vertexTexCoordOut;
|
2024-01-12 14:49:53 +01:00
|
|
|
out vec3 viewDirTS;
|
|
|
|
out vec3 sunLightDirTS;
|
|
|
|
out vec3 reflectorLightDirTS;
|
2024-01-11 00:53:24 +01:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
gl_Position = transformation * vec4(vertexPosition, 1.0);
|
2024-01-12 14:49:53 +01:00
|
|
|
vec3 normal = (modelMat * vec4(vertexNormal, 0.0)).xyz;
|
|
|
|
vec3 tangent = (modelMat * vec4(vertexTangent, 0.0)).xyz;
|
|
|
|
vec3 bitangent = (modelMat * vec4(vertexBitangent, 0.0)).xyz;
|
|
|
|
vertexPosWld = (modelMat * vec4(vertexPosition, 1.0)).xyz;
|
2024-01-11 00:53:24 +01:00
|
|
|
vertexTexCoordOut = vertexTexCoord;
|
|
|
|
vertexTexCoordOut.y = 1 - vertexTexCoord.y;// corrects inversion (bottom at top) of the earth
|
2024-01-12 14:49:53 +01:00
|
|
|
|
|
|
|
mat3 TBN = transpose(mat3(tangent, bitangent, normal));
|
|
|
|
|
|
|
|
//`lightPos - vertexPos` from tutorial is wrong?
|
|
|
|
//TODO why should we normalize here if we would normalize Tangent Space vectors later?
|
|
|
|
// and why do it here, mb fragment shader?
|
|
|
|
vec3 sunLightDir = normalize(vertexPosWld - sunPos);
|
|
|
|
vec3 reflectorLightDir = normalize(vertexPosWld - reflectorPos);
|
|
|
|
vec3 viewDir = normalize(cameraPos - vertexPosWld);
|
|
|
|
|
|
|
|
// tangent space
|
|
|
|
viewDirTS = TBN * viewDir;
|
|
|
|
sunLightDirTS = TBN * sunLightDir;
|
|
|
|
reflectorLightDirTS = TBN * reflectorLightDir;
|
|
|
|
|
|
|
|
//TODO should normilize here or in the fragment shader?
|
|
|
|
viewDirTS = normalize(viewDirTS);
|
|
|
|
sunLightDirTS = normalize(sunLightDirTS);
|
|
|
|
reflectorLightDirTS = normalize(reflectorLightDirTS);
|
|
|
|
}
|
|
|
|
|