Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 330 core
- uniform vec3 lightPos;
- in vec3 modelPos;
- in vec3 faceNormal;
- // Code adpated from opengl-tutorial.org
- void main() {
- vec3 n = normalize(faceNormal);
- vec3 l = normalize(lightPos);
- // Cosine of the angle between the normal and the light direction,
- // clamped above 0
- // - light is at the vertical of the triangle -> 1
- // - light is perpendicular to the triangle -> 0
- // - light is behind the triangle -> 0
- float cosTheta = clamp(dot(n, l), 0, 1);
- float distance = abs(modelPos - lightPos);
- vec3 diffuseColor = vec3(137/255, 183/255, 255/255);
- vec3 lightColor = vec3(1,1,1);
- float lightPower = 60;
- vec3 color = diffuseColor * lightColor * lightPower * cosTheta / (distance*distance);
- gl_FragColor = color;
- //float lv = dot(normal, lightPos);
- //float corrected = pow(lv, 1.0 / 2.2);
- //gl_FragColor = vec4(137.0 / 255.0, 183.0 / 255.0, 1.0, 1.0);
- //gl_FragColor = vec4(corrected, corrected, corrected, 1.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement