[930] | 1 | uniform sampler2D texture;
|
---|
| 2 | uniform vec3 LightPos;
|
---|
| 3 | uniform vec3 Kd;
|
---|
| 4 | uniform sampler2D shadowMap;
|
---|
| 5 | uniform sampler2D spotlight;
|
---|
| 6 | uniform float modeDirect;
|
---|
| 7 | uniform float modeLight;
|
---|
| 8 | uniform float modeIndirect;
|
---|
| 9 | uniform float modeAmbient;
|
---|
| 10 | uniform vec3 intensity;
|
---|
| 11 | uniform vec3 lpower;
|
---|
| 12 | uniform vec3 factor;
|
---|
| 13 |
|
---|
| 14 | varying vec4 position;
|
---|
| 15 | varying vec3 color;
|
---|
| 16 | varying vec2 texCoord;
|
---|
| 17 | varying vec3 normal;
|
---|
| 18 | varying vec3 lightVect;
|
---|
| 19 | varying vec4 shadowCoord;
|
---|
| 20 | varying vec3 position1;
|
---|
| 21 |
|
---|
| 22 |
|
---|
| 23 | void main()
|
---|
| 24 | {
|
---|
| 25 | vec4 aux = tex2D(texture,texCoord);
|
---|
| 26 |
|
---|
| 27 | normal = normalize(normal);
|
---|
| 28 |
|
---|
| 29 | float depth = length(lightVect);
|
---|
| 30 |
|
---|
| 31 | lightVect /= depth;
|
---|
| 32 |
|
---|
| 33 | vec3 L;
|
---|
| 34 | float diffuseLight;
|
---|
| 35 | vec3 diffuse = vec3(0.0, 0.0, 0.0);
|
---|
| 36 | float sum = 0;
|
---|
| 37 | float sum2 = 0;
|
---|
| 38 | float x, y;
|
---|
| 39 | float s;
|
---|
| 40 | float ac;
|
---|
| 41 | float shadow = 0.0;
|
---|
| 42 | float sLight;
|
---|
| 43 |
|
---|
| 44 | if (modeDirect == 1.0)
|
---|
| 45 | {
|
---|
| 46 | L = normalize(LightPos - position1.xyz);
|
---|
| 47 | diffuseLight = lpower * max(dot(normalize(normal), L), 0);
|
---|
| 48 | diffuse = Kd * diffuseLight;
|
---|
| 49 |
|
---|
| 50 | vec3 b = shadowCoord.xyz / shadowCoord.w;
|
---|
| 51 | vec4 a = texture2DProj(shadowMap,shadowCoord);
|
---|
| 52 | shadow = (depth < a.r + 0.01);
|
---|
| 53 |
|
---|
| 54 | shadow *= float(shadowCoord.w > 0.01);
|
---|
| 55 | float variance = a.g - (a.r * a.r);
|
---|
| 56 | float m_d = a.r - depth;
|
---|
| 57 | float p_max = variance / (variance + m_d * m_d);
|
---|
| 58 | shadow = max(p_max, shadow);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | if (modeIndirect == 0.0)
|
---|
| 62 | {
|
---|
| 63 | if (modeAmbient == 0.0)
|
---|
| 64 | {
|
---|
| 65 | if (modeDirect == 0.0) gl_FragColor = vec4(0.0,0.0,0.0,1.0);
|
---|
| 66 | else gl_FragColor = vec4(color.xyz, 1.0)* shadow * vec4(diffuse,0.0);
|
---|
| 67 | }
|
---|
| 68 | else
|
---|
| 69 | {
|
---|
| 70 | if (modeDirect == 0.0) gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
|
---|
| 71 | else gl_FragColor = vec4(color.xyz, 1.0) * (vec4(intensity,1.0)* vec4(factor,1.0) + shadow * vec4(diffuse,0.0));
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 | else
|
---|
| 75 | {
|
---|
| 76 | if (modeDirect == 0.0) gl_FragColor = vec4(color.xyz, 1.0)* vec4(intensity,1.0) * vec4(aux.rgb, 1.0);
|
---|
| 77 | else gl_FragColor = vec4(color.xyz, 1.0) * (vec4(intensity,1.0) * vec4(aux.rgb, 1.0) + shadow * vec4(diffuse,0.0));
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | if (modeLight == 1.0) gl_FragColor = vec4(aux.rgb,1.0);
|
---|
| 81 | } |
---|