Created
May 26, 2015 01:26
-
-
Save TomMinor/a316b06532993d56c160 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; | |
in vec3 fragmentPosition; | |
// 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); | |
float distance = length( fragmentPosition - light.position ); | |
float attenuation = 1 / (distance * distance); | |
// The final colour is the diffuse(clamped to 0-1 range) multiplied by the light colour and the material colour | |
fragColour = attenuation * 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