Created
May 26, 2015 01:06
-
-
Save TomMinor/8f44958ec70bee8d0205 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
layout(location = 0) in vec3 inVert; | |
layout(location = 1) in vec3 inNormal; | |
layout(location = 2) in vec3 inUV; | |
// Model View Projection matrix | |
uniform mat4 MVP; | |
// Model View matrix | |
uniform mat4 MV; | |
// Normal matrix | |
uniform mat3 NormalMatrix; | |
struct Lights | |
{ | |
// Position in eye coordinates | |
vec4 position; | |
// Diffuse reflectivity | |
vec4 Kd; | |
// Light source intensity | |
vec4 Ld; | |
}; | |
// Light data passed in from the client | |
uniform Lights light; | |
// Output to the fragment shader (interpolated) | |
out vec3 LightIntensity; | |
void main() | |
{ | |
// Convert normal to eye space | |
vec3 nrmN = normalize(NormalMatrix * inNormal); | |
// Convert vertex to eye space (we convert it to vec4 so the multiply by matrix works) | |
vec4 eye = MV * vec4(inVert, 1); | |
// Get direction to the light | |
vec3 lightNrm = normalize( eye - light.position ); | |
// Calculate diffuse (lambert reflectance) | |
vec3 lambert = dot(nrmN, lightNrm); | |
// Intensity is the diffuse value multiplied by the light colour and intensity | |
LightIntensity = light.Ld * light.Kd * max(lambert, 0.0); | |
// Position is the input vertex transformed by the model view projection matrix | |
gl_Position = MVP * vec4(inVert,1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment