3 #extension GL_ARB_texture_rectangle : require
4 #extension GL_ARB_texture_rectangle : enable
7 vec4 OSG_SSME_FP_calcShadow(in vec4 ecFragPos);
9 // compute point light INDEX for fragment at POS with normal NORM
10 // and diffuse material color MDIFF
11 vec4 computePointLight(int index, vec3 pos, vec3 norm, vec4 mDiff)
13 vec4 color = vec4(0., 0., 0., 0.);
15 vec3 lightDirUN = gl_LightSource[index].position.xyz - pos;
16 vec3 lightDir = normalize(lightDirUN);
17 float NdotL = max(dot(norm, lightDir), 0.);
21 vec4 shadow = OSG_SSME_FP_calcShadow(vec4(pos, 1.));
23 float lightDist = length (lightDirUN);
24 float distAtt = dot(vec3(gl_LightSource[index].constantAttenuation,
25 gl_LightSource[index].linearAttenuation,
26 gl_LightSource[index].quadraticAttenuation),
27 vec3(1., lightDist, lightDist * lightDist));
28 distAtt = 1. / distAtt;
30 color = shadow * distAtt * NdotL * mDiff * gl_LightSource[index].diffuse;
37 uniform sampler2DRect texBufPos;
38 uniform sampler2DRect texBufNorm;
39 uniform sampler2DRect texBufDiff;
40 uniform vec2 vpOffset;
45 vec2 lookup = gl_FragCoord.xy - vpOffset;
46 vec3 norm = texture2DRect(texBufNorm, lookup).xyz;
48 if(dot(norm, norm) < 0.95)
54 vec4 posAmb = texture2DRect(texBufPos, lookup);
55 vec3 pos = posAmb.xyz;
57 vec4 mDiff = texture2DRect(texBufDiff, lookup);
59 gl_FragColor = computePointLight(0, pos, norm, mDiff);