52 lines
1.6 KiB
GLSL
52 lines
1.6 KiB
GLSL
#version 330 core
|
|
|
|
// Matrices
|
|
uniform mat4 modelViewMatrix;
|
|
uniform mat4 MVP;
|
|
uniform mat4 normalMatrix;
|
|
uniform mat4 viewMatrix;
|
|
|
|
uniform int nbDirLights;
|
|
uniform vec3 dirLights[16];
|
|
uniform int nbPointLights;
|
|
uniform vec3 pointLights[16];
|
|
|
|
layout(location = 0)in vec3 inPosition;
|
|
layout(location = 1)in vec3 inNormal;
|
|
layout(location = 2)in vec4 inTexCoord;
|
|
|
|
out vec3 lightDirInView[8];
|
|
out vec3 halfVecInView[8];
|
|
|
|
out vec3 varNormal;
|
|
out vec2 varTexCoord;
|
|
|
|
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;
|
|
for(i=0; i<nbDirLights && i<8; ++i)
|
|
computeDirectionnalLightingVectorsInView(vec3(modelViewMatrix*vec4(inPosition, 1.0)), dirLights[i*2], lightDirInView[i], halfVecInView[i]);
|
|
for(i=0; i<nbPointLights && i+nbDirLights<8; ++i)
|
|
computePointLightingVectorsInView(vec3(modelViewMatrix*vec4(inPosition, 1.0)), pointLights[i*2], lightDirInView[nbDirLights+i], halfVecInView[nbDirLights+i]);
|
|
|
|
// normales corrigees (en fonction de la vue)
|
|
varNormal = normalize(vec3(normalMatrix*vec4(inNormal,0)));
|
|
|
|
// coordonnees de texture
|
|
varTexCoord = inTexCoord.xy;
|
|
|
|
// position du vertex
|
|
gl_Position = MVP * vec4(inPosition, 1.0);
|
|
}
|