1// $Id$ 2// 3// Fragment shader for infinite lights 4// 5// Author: Dan Gudmundsson 6// 7 8#version 120 9 10#include "lib_base.glsl" 11#include "lib_normal.glsl" 12#include "lib_material.glsl" 13 14varying vec3 ws_position; 15uniform vec3 ws_eyepoint; 16uniform vec4 ws_lightpos; 17uniform vec4 light_diffuse; 18uniform vec4 light_specular; 19uniform vec3 light_att; 20uniform float Exposure; 21 22void main(void) 23{ 24 vec3 n = get_normal(); 25 vec3 v = normalize(ws_eyepoint-ws_position); // point to camera 26 vec3 l = normalize(ws_lightpos.xyz); 27 l = normalize(l); 28 PBRInfo pbr = calc_views(n, v, l); 29 pbr = calc_material(pbr); 30 31 // Calculate the shading terms for the microfacet specular shading model 32 vec3 F = specularReflection(pbr); 33 float G = geometricOcclusion(pbr); 34 float D = microfacetDistribution(pbr); 35 36 // Calculation of analytical lighting contribution 37 vec3 diffuseContrib = (1.0 - max(max(F.r, F.g), F.b)) * diffuse(pbr); 38 diffuseContrib *= light_diffuse.xyz; 39 vec3 specContrib = F * G * D / (4.0 * pbr.NdotL * pbr.NdotV); 40 specContrib *= light_specular.xyz; 41 // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law) 42 vec3 frag_color = pbr.NdotL * (diffuseContrib + specContrib); 43 frag_color *= Exposure; 44 gl_FragColor = vec4(pow(frag_color,vec3(1.0/2.2)), pbr.opaque); 45} 46