2 #extension GL_ARB_texture_rectangle : require
3 #extension GL_ARB_texture_rectangle : enable
5 #extension GL_EXT_gpu_shader4 : require
6 #extension GL_EXT_gpu_shader4 : enable
9 vec4 OSG_SSME_FP_calcShadow(in vec4 ecFragPos);
11 uniform sampler2DRect texBufPos;
12 uniform sampler2DRect texBufNorm;
13 uniform sampler2DRect texBufDiff;
15 // compute point light INDEX for fragment at POS with normal NORM
16 // and diffuse material color MDIFF
17 vec4 computePointLight(int index, vec3 pos, vec3 norm, vec4 mDiff)
19 vec4 color = vec4(0., 0., 0., 0.);
21 vec3 lightDirUN = gl_LightSource[index].position.xyz - pos;
22 vec3 lightDir = normalize(lightDirUN);
23 float NdotL = max(dot(norm, lightDir), 0.);
27 vec4 shadow = OSG_SSME_FP_calcShadow(vec4(pos, 1.));
29 float lightDist = length (lightDirUN);
30 float distAtt = dot(vec3(gl_LightSource[index].constantAttenuation,
31 gl_LightSource[index].linearAttenuation,
32 gl_LightSource[index].quadraticAttenuation),
33 vec3(1., lightDist, lightDist * lightDist));
34 distAtt = 1. / distAtt;
36 color = shadow * distAtt * NdotL * mDiff * gl_LightSource[index].diffuse;
37 // color = shadow * 0.5;
43 // compute directional light INDEX for fragment at POS with normal NORM
44 // and diffuse material color MDIFF
45 vec4 computeDirLight(int index, vec3 pos, vec3 norm, vec4 mDiff)
47 vec4 color = vec4(0., 0., 0., 0.);
49 vec3 lightDir = gl_LightSource[index].position.xyz;
50 float NdotL = max(dot(norm, lightDir), 0.);
54 vec4 shadow = OSG_SSME_FP_calcShadow(vec4(pos, 1.));
56 color = shadow * NdotL * mDiff * gl_LightSource[index].diffuse;
62 // compute spot light INDEX for fragment at POS with normal NORM
63 // and diffuse material color MDIFF
64 vec4 computeSpotLight(int index, vec3 pos, vec3 norm, vec4 mDiff)
66 vec4 color = vec4(0., 0., 0., 0.);
68 vec3 lightDirUN = gl_LightSource[index].position.xyz - pos;
69 vec3 lightDir = normalize(lightDirUN);
70 float spotEffect = dot(-lightDir, gl_LightSource[index].spotDirection);
72 if(spotEffect > gl_LightSource[index].spotCosCutoff)
74 float NdotL = max(dot(lightDir, norm), 0.);
78 vec4 shadow = OSG_SSME_FP_calcShadow(vec4(pos, 1.));
80 float lightDist = length(lightDirUN);
81 float distAtt = dot(vec3(gl_LightSource[index].constantAttenuation,
82 gl_LightSource[index].linearAttenuation,
83 gl_LightSource[index].quadraticAttenuation),
84 vec3(1., lightDist, lightDist * lightDist) );
85 spotEffect = pow(spotEffect, gl_LightSource[index].spotExponent);
86 distAtt = spotEffect / distAtt;
88 color = shadow * distAtt * NdotL * mDiff * gl_LightSource[index].diffuse;
98 vec3 norm = texture2DRect(texBufNorm, gl_FragCoord.xy).xyz;
100 if(dot(norm, norm) < 0.95)
106 vec4 posAmb = texture2DRect(texBufPos, gl_FragCoord.xy);
107 vec3 pos = posAmb.xyz;
108 float amb = posAmb.w;
109 vec4 mDiff = texture2DRect(texBufDiff, gl_FragCoord.xy);
111 gl_FragColor = computePointLight(0, pos, norm, mDiff);