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 spot light INDEX for fragment at POS with normal NORM
10 // and diffuse material color MDIFF
11 vec4 computeSpotLight(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 spotEffect = dot(-lightDir, gl_LightSource[index].spotDirection);
19 if(spotEffect > gl_LightSource[index].spotCosCutoff)
21 float NdotL = max(dot(lightDir, norm), 0.);
25 vec4 shadow = OSG_SSME_FP_calcShadow(vec4(pos, 1.));
27 float lightDist = length(lightDirUN);
28 float att = dot(vec3(gl_LightSource[index].constantAttenuation,
29 gl_LightSource[index].linearAttenuation,
30 gl_LightSource[index].quadraticAttenuation),
31 vec3(1., lightDist, lightDist * lightDist) );
32 spotEffect = pow(spotEffect, gl_LightSource[index].spotExponent);
33 att = spotEffect / att;
35 color = shadow * att * NdotL * mDiff * gl_LightSource[index].diffuse;
43 uniform sampler2DRect texBufPos;
44 uniform sampler2DRect texBufNorm;
45 uniform sampler2DRect texBufDiff;
47 uniform vec2 vpOffset;
52 vec2 lookup = gl_FragCoord.xy - vpOffset;
53 vec3 norm = texture2DRect(texBufNorm, lookup).xyz;
55 if(dot(norm, norm) < 0.95)
61 vec4 posAmb = texture2DRect(texBufPos, lookup);
62 vec3 pos = posAmb.xyz;
64 vec4 mDiff = texture2DRect(texBufDiff, lookup);
66 gl_FragColor = computeSpotLight(0, pos, norm, mDiff);