uniform sampler2D texture; uniform vec3 LightPos; uniform vec3 Kd; uniform sampler2D shadowMap; uniform sampler2D spotlight; uniform float modeDirect; uniform float modeLight; uniform float modeIndirect; uniform float modeAmbient; uniform vec3 intensity; uniform vec3 lpower; uniform vec3 factor; varying vec4 position; varying vec3 color; varying vec2 texCoord; varying vec3 normal; varying vec3 lightVect; varying vec4 shadowCoord; varying vec3 position1; void main() { vec4 aux = tex2D(texture,texCoord); normal = normalize(normal); float depth = length(lightVect); lightVect /= depth; vec3 L; float diffuseLight; vec3 diffuse = vec3(0.0, 0.0, 0.0); float sum = 0; float sum2 = 0; float x, y; float s; float ac; float shadow = 0.0; float sLight; if (modeDirect == 1.0) { L = normalize(LightPos - position1.xyz); diffuseLight = lpower * max(dot(normalize(normal), L), 0); diffuse = Kd * diffuseLight; vec3 b = shadowCoord.xyz / shadowCoord.w; vec4 a = texture2DProj(shadowMap,shadowCoord); shadow = (depth < a.r + 0.01); shadow *= float(shadowCoord.w > 0.01); float variance = a.g - (a.r * a.r); float m_d = a.r - depth; float p_max = variance / (variance + m_d * m_d); shadow = max(p_max, shadow); } if (modeIndirect == 0.0) { if (modeAmbient == 0.0) { if (modeDirect == 0.0) gl_FragColor = vec4(0.0,0.0,0.0,1.0); else gl_FragColor = vec4(color.xyz, 1.0)* shadow * vec4(diffuse,0.0); } else { if (modeDirect == 0.0) gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); else gl_FragColor = vec4(color.xyz, 1.0) * (vec4(intensity,1.0)* vec4(factor,1.0) + shadow * vec4(diffuse,0.0)); } } else { if (modeDirect == 0.0) gl_FragColor = vec4(color.xyz, 1.0)* vec4(intensity,1.0) * vec4(aux.rgb, 1.0); else gl_FragColor = vec4(color.xyz, 1.0) * (vec4(intensity,1.0) * vec4(aux.rgb, 1.0) + shadow * vec4(diffuse,0.0)); } if (modeLight == 1.0) gl_FragColor = vec4(aux.rgb,1.0); }