58 lines
1.7 KiB
GLSL
58 lines
1.7 KiB
GLSL
#version 330 core
|
|
|
|
// Matrices
|
|
uniform mat4 modelViewMatrix;
|
|
uniform mat4 MVP;
|
|
uniform mat4 normalMatrix;
|
|
uniform mat4 viewMatrix;
|
|
|
|
uniform vec3 dirLight[2];
|
|
uniform int nbPointLights;
|
|
uniform vec3 pointLights[8];
|
|
|
|
layout(location = 0)in vec3 inPosition;
|
|
layout(location = 1)in vec3 inNormal;
|
|
layout(location = 2)in vec2 inTexCoord;
|
|
layout(location = 2)in vec3 inTangent[2];
|
|
|
|
out vec3 lightDirInView[5];
|
|
out vec3 halfVecInView[5];
|
|
|
|
out vec3 varNormal;
|
|
out vec2 varTexCoord;
|
|
out vec3 varTangent;
|
|
out vec3 varBinormal;
|
|
|
|
void computeDirectionnalLightingVectorsInView(in vec3 posInView, in vec3 lightDirInWorld, out vec3 lightDir, out vec3 halfVec){
|
|
lightDir = mat3(viewMatrix)*lightDirInWorld;
|
|
halfVec = normalize(normalize(lightDir) - normalize(posInView));
|
|
lightDir = normalize(lightDir);
|
|
}
|
|
|
|
void computePointLightingVectorsInView(in vec3 posInView, in vec3 lightPosition, out vec3 lightDir, out vec3 halfVec){
|
|
lightDir = vec3(viewMatrix*vec4(lightPosition, 1.0)) - posInView;
|
|
halfVec = normalize(lightDir - posInView);
|
|
lightDir = normalize(lightDir);
|
|
}
|
|
|
|
void main(void) {
|
|
int i;
|
|
computeDirectionnalLightingVectorsInView(vec3(modelViewMatrix*vec4(inPosition, 1.0)), dirLight[0], lightDirInView[0], halfVecInView[0]);
|
|
for(i=1; i<nbPointLights+1; ++i)
|
|
computePointLightingVectorsInView(vec3(modelViewMatrix*vec4(inPosition, 1.0)),
|
|
pointLights[i*2 - 2],
|
|
lightDirInView[i],
|
|
halfVecInView[i]);
|
|
|
|
// normales corrigees (en fonction de la vue)
|
|
varNormal = normalize(vec3(normalMatrix*vec4(inNormal,0)));
|
|
|
|
// coordonnees de texture
|
|
varTexCoord = inTexCoord.xy;
|
|
varTangent = inTangent[0];
|
|
varBinormal = inTangent[1];
|
|
|
|
// position du vertex
|
|
gl_Position = MVP * vec4(inPosition, 1.0);
|
|
}
|