3 #extension GL_ARB_texture_rectangle : require
4 #extension GL_ARB_texture_rectangle : enable
6 // compute point light INDEX for fragment at POS with normal NORM
7 // and diffuse material color MDIFF
8 vec4 computePointLight(int index, vec3 pos, vec3 norm, vec4 mDiff)
10 vec4 color = vec4(0., 0., 0., 0.);
12 vec3 lightDirUN = gl_LightSource[index].position.xyz - pos;
13 vec3 lightDir = normalize(lightDirUN);
14 float NdotL = max(dot(norm, lightDir), 0.);
18 float lightDist = length (lightDirUN);
19 float distAtt = dot(vec3(gl_LightSource[index].constantAttenuation,
20 gl_LightSource[index].linearAttenuation,
21 gl_LightSource[index].quadraticAttenuation),
22 vec3(1., lightDist, lightDist * lightDist));
23 distAtt = 1. / distAtt;
25 color = distAtt * NdotL * mDiff * gl_LightSource[index].diffuse;
32 uniform sampler2DRect texBufPos;
33 uniform sampler2DRect texBufNorm;
34 uniform sampler2DRect texBufDiff;
35 uniform vec2 vpOffset;
40 vec2 lookup = gl_FragCoord.xy - vpOffset;
41 vec3 norm = texture2DRect(texBufNorm, lookup).xyz;
43 if(dot(norm, norm) < 0.95)
49 vec4 posAmb = texture2DRect(texBufPos, lookup);
50 vec3 pos = posAmb.xyz;
52 vec4 mDiff = texture2DRect(texBufDiff, lookup);
54 gl_FragColor = computePointLight(0, pos, norm, mDiff);