Last active
August 29, 2015 14:21
-
-
Save TomMinor/e7b988d1c482b777279e 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
// The normal attribute passed in from the vertex shader | |
in vec3 fragmentNormal; | |
// The output attribute that will be written to the framebuffer | |
layout(location = 0) out vec4 fragColour; | |
// Defines all the light info | |
struct Lights | |
{ | |
vec4 position; | |
vec4 diffuse; | |
}; | |
// Probably meant to be the material colour | |
uniform vec4 diffuse; | |
// Pass in the light information from the client | |
uniform Lights light; | |
void main() | |
{ | |
// Find light normal | |
vec3 nrmL = normalize(light.position); | |
// Calculate diffuse (lambert reflectance) | |
float nDotL = dot(fragmentNormal, nrmL); | |
// The final colour is the diffuse(clamped to 0-1 range) multiplied by the light colour and the material colour | |
fragColour = diffuse * light.diffuse * max(nDotL, 0.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment