Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 167 vs 168 for /trunk/assets/shaders/GLSL/fragmentAtoms/phong_light_loop.frag

Diff revisions: vs.
  @@ -1,5 +1,5 @@
1 1 in vec3 _lightDirection[MAX_LIGHT_COUNT];
2 - in float _attenuation[MAX_LIGHT_COUNT];
2 + smooth in float _attenuation[MAX_LIGHT_COUNT];
3 3 in vec3 _viewDirection;
4 4
5 5 #define LIGHT_DIRECTIONAL 0
  @@ -22,10 +22,10 @@
22 22 //Specular and opacity maps are available even for non-textured geometry
23 23 #if defined(USE_OPACITY_MAP)
24 24 //Opacity and specular maps
25 - uniform sampler2D opacityMap;
25 + uniform sampler2D texOpacityMap;
26 26 #endif
27 27 #if defined(USE_SPECULAR_MAP)
28 - uniform sampler2D specularMap;
28 + uniform sampler2D texSpecularMap;
29 29 #endif
30 30
31 31 #include "phong_point_light.frag"
  @@ -33,26 +33,26 @@
33 33 #include "phong_directional_light.frag"
34 34 #include "shadowMapping.frag"
35 35
36 - void applyLight(in int light,
37 - in int lightType,
38 - in bool lightCastsShadows,
39 - in vec2 texCoord,
40 - in vec3 normal,
41 - in vec3 viewDirection,
36 + void applyLight(const in int light,
37 + const in int lightType,
38 + const in bool lightCastsShadows,
39 + const in vec2 texCoord,
40 + const in vec3 normal,
41 + const in vec3 viewDirection,
42 42 inout MaterialProperties materialProp)
43 43 {
44 - //Normalized Light/Normal/Eye vectors in TBN space
45 - vec3 L = normalize(_lightDirection[light]);
46 - vec3 R = normalize(-reflect(L,normal));
47 - //Specular intensity based on material shininess
48 - float iSpecular = clamp(pow(max(dot(R, viewDirection), 0.0), material[3].x ), 0.0, 1.0);
49 - float NdotL = max(dot(normal, L), 0.0);
50 44
51 45 #if defined(USE_SPECULAR_MAP)
52 - vec4 specularValue = texture(specularMap, texCoord)
46 + vec4 specularValue = texture(texSpecularMap, texCoord)
53 47 #else
54 48 vec4 specularValue = material[2];
55 49 #endif
50 +
51 + vec3 L = normalize(_lightDirection[light]);
52 + vec3 R = normalize(-reflect(L,normal));
53 + //Specular intensity based on material shininess
54 + float iSpecular = clamp(pow(max(dot(R, viewDirection), 0.0), material[3].x ), 0.0, 1.0);
55 + float NdotL = max(dot(normal, L), 0.0);
56 56
57 57 if(lightType == LIGHT_DIRECTIONAL){
58 58 phong_directionalLight(light, iSpecular, NdotL, specularValue, materialProp);
  @@ -76,40 +76,49 @@
76 76
77 77 void phong_loop(in vec2 texCoord, in vec3 normal, inout MaterialProperties materialProp){
78 78 vec3 viewDirection = normalize(_viewDirection);
79 - if(dvd_lightCount == 0) return;
79 + if(dvd_lightCount == 0)
80 + return;
80 81 if(dvd_lightEnabled[0]) applyLight(0, dvd_lightType[0], dvd_lightCastsShadows[0], texCoord, normal, viewDirection, materialProp);
81 82 #if MAX_LIGHT_COUNT >= 2
82 - if(dvd_lightCount == 1) return;
83 + if(dvd_lightCount == 1)
84 + return;
83 85 if(dvd_lightEnabled[1]) applyLight(1, dvd_lightType[1], dvd_lightCastsShadows[1], texCoord, normal, viewDirection, materialProp);
84 86 #endif
85 87 #if MAX_LIGHT_COUNT >= 3
86 - if(dvd_lightCount == 2) return;
88 + if(dvd_lightCount == 2)
89 + return;
87 90 if(dvd_lightEnabled[2]) applyLight(2, dvd_lightType[2], dvd_lightCastsShadows[2], texCoord, normal, viewDirection, materialProp);
88 91 #endif
89 92 #if MAX_LIGHT_COUNT >= 4
90 - if(dvd_lightCount == 3) return;
93 + if(dvd_lightCount == 3)
94 + return;
91 95 if(dvd_lightEnabled[3]) applyLight(3, dvd_lightType[3], dvd_lightCastsShadows[3], texCoord, normal, viewDirection, materialProp);
92 96 #endif
93 97 #if MAX_LIGHT_COUNT >= 5
94 - if(dvd_lightCount == 4) return;
98 + if(dvd_lightCount == 4)
99 + return;
95 100 if(dvd_lightEnabled[4]) applyLight(4, dvd_lightType[4], dvd_lightCastsShadows[4], texCoord, normal, viewDirection, materialProp);
96 101 #endif
97 102 #if MAX_LIGHT_COUNT >= 6
98 - if(dvd_lightCount == 5) return;
103 + if(dvd_lightCount == 5)
104 + return;
99 105 if(dvd_lightEnabled[5]) applyLight(5, dvd_lightType[5], dvd_lightCastsShadows[5], texCoord, normal, viewDirection, materialProp);
100 106 #endif
101 107 #if MAX_LIGHT_COUNT >= 7
102 - if(dvd_lightCount == 6) return;
108 + if(dvd_lightCount == 6)
109 + return;
103 110 if(dvd_lightEnabled[6]) applyLight(6, dvd_lightType[6], dvd_lightCastsShadows[6], texCoord, normal, viewDirection, materialProp);
104 111 #endif
105 112 #if MAX_LIGHT_COUNT == 8
106 - if(dvd_lightCount == 7) return;
113 + if(dvd_lightCount == 7)
114 + return;
107 115 if(dvd_lightEnabled[7]) applyLight(7, dvd_lightType[7], dvd_lightCastsShadows[7], texCoord, normal, viewDirection, materialProp);
108 116 #endif
109 117 #if MAX_LIGHT_COUNT > 8
110 118 ///Apply the rest of the lights
111 - for(int i = 8; i < MAX_LIGHT_COUNT; i++){
112 - if(dvd_lightCount == i) return;
119 + for(int i = 8; i =< MAX_LIGHT_COUNT; i++){
120 + if(dvd_lightCount == i)
121 + return;
113 122 if(dvd_lightEnabled[i]) applyLight(i, dvd_lightType[i], dvd_lightCastsShadows[i], texCoord, normal, viewDirection, materialProp);
114 123 }
115 124 #endif