Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Light {
- vec3 position;
- vec3 Iambient;
- vec3 Idiffuse;
- vec3 Ispecular;
- };
- uniform Light lights[LIGHTS_AMOUNT];
- uniform vec3 cameraPosition;
- float constant = 1.0;
- float linear = 0.007;
- float quadratic = 0.002;
- vec3 lightning(vec3 color) {
- vec3 finalDiffuse = vec3(1.0);
- for (int i=0; i <= LIGHTS_AMOUNT; i++) {
- Light light = lights[i];
- vec3 Normal = normalize(normal);
- // Ambient
- vec3 ambient = light.Iambient;
- // Diffuse
- vec3 lightDirection = normalize(light.position - fragmentPosition);
- float diff = max(0,dot(lightDirection,Normal));
- vec3 diffuse = diff * light.Idiffuse;
- // Specular
- vec3 viewDirection = normalize(cameraPosition - fragmentPosition);
- vec3 reflectDirection = reflect(-lightDirection,Normal);
- float spec = pow(max(dot(viewDirection,reflectDirection),0),32);
- vec3 specular = spec * light.Ispecular;
- float distance = length(light.position - fragmentPosition);
- float attenuation = 1.0 / (constant + linear * distance + quadratic * (distance * distance));
- ambient *= attenuation;
- diffuse *= attenuation;
- specular *= attenuation;
- finalDiffuse += (ambient + diffuse + specular);
- }
- return color * finalDiffuse;
- }
- void main() {
- vec3 color = texture(textureData,uv_0).rgb;
- vec3 lightningColor = lightning(color);
- fragColor = vec4(lightningColor,1.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement