LOG750-LAB2/src/shaders/basicShader.vert
2016-11-10 13:28:46 -05:00

56 lines
1.3 KiB
GLSL

#version 400 core
uniform mat4 mvMatrix;
uniform mat4 projMatrix;
uniform mat3 normalMatrix;
uniform vec3 lDirection;
uniform bool isLightSource;
uniform vec4 color;
uniform bool isSky;
uniform bool isPhong;
in vec4 vPosition;
in vec3 vNormal;
in vec2 vUv;
out vec2 texCoords;
out vec4 ifColor;
out vec3 fPosition;
out vec3 fNormal;
void
main()
{
vec4 vEyeCoord = mvMatrix * vPosition;
gl_Position = projMatrix * vEyeCoord;
fPosition = -vEyeCoord.xyz;
fNormal = normalMatrix * vNormal;
texCoords = vUv;
ifColor = color;
if(!isPhong && !isSky && !isLightSource) {
// Get lighting vectors
vec3 LightDirection = normalize(lDirection);
vec3 nfNormal = normalize(fNormal);
vec3 nviewDirection = normalize(fPosition);
// Compute diffuse component
float diffuse = max(0.0, dot(nfNormal, LightDirection));
// Compute specular component
vec3 Rl = normalize(-LightDirection+2.0*nfNormal*dot(nfNormal,LightDirection));
float specular = 0.0;//0.1*pow(max(0.0, dot(Rl, nviewDirection)), 16);
// Vertex color (currently static, to be replaced with texture)
vec3 color = ifColor.xyz;
// Compute final color
ifColor = vec4(color * (0.1 + diffuse + specular), 1);
//ifColor = vec4(fNormal, 1);
}
}