@@ -36,29 +36,16 @@ IN(smooth) vec3 var_Tangent;
3636IN(smooth ) vec3 var_Binormal;
3737IN(smooth ) vec3 var_Normal;
3838
39- #if defined(USE_BSP_SURFACE) && defined(USE_LIGHT_MAPPING) && ! defined(USE_DELUXE_MAPPING)
40- /* HACK: restore legacy behavior for bsp surface with lightmap
41- but no deluxemap, do not use the lightgrid to compute the light
42- direction, do not do normal mapping neither specular mapping
43- with static lights.
44- https://github.com/DaemonEngine/Daemon/issues/324
45-
46- Comment out this line to enable lightgrid light direction with
47- lightmap light color when there is no deluxe map.
48- */
49- #define HACK_NO_BSP_GRID_LIGHTDIR
50- #endif
51-
5239#if defined(USE_LIGHT_MAPPING)
5340 uniform sampler2D u_LightMap;
54- #else
41+ #elif defined(USE_GRID_LIGHTING)
5542 uniform sampler3D u_LightMap;
5643 #define u_LightGrid1 u_LightMap
5744#endif
5845
5946#if defined(USE_DELUXE_MAPPING)
6047 uniform sampler2D u_DeluxeMap;
61- #else
48+ #elif defined(USE_GRID_DELUXE_MAPPING)
6249 uniform sampler3D u_DeluxeMap;
6350 #define u_LightGrid2 u_DeluxeMap
6451#endif
@@ -67,7 +54,7 @@ lightmap light color when there is no deluxe map.
6754 IN(smooth ) vec2 var_TexLight;
6855#endif
6956
70- #if ! defined(USE_LIGHT_MAPPING ) || ! defined(USE_DELUXE_MAPPING )
57+ #if defined(USE_GRID_LIGHTING ) || defined(USE_GRID_DELUXE_MAPPING )
7158 uniform vec3 u_LightGridOrigin;
7259 uniform vec3 u_LightGridScale;
7360#endif
@@ -112,30 +99,26 @@ void main()
11299 vec4 color;
113100 color.a = diffuse.a;
114101
115- #if ! defined(USE_LIGHT_MAPPING) || ! defined(USE_DELUXE_MAPPING)
116- #if ! defined(HACK_NO_BSP_GRID_LIGHTDIR)
117- // Compute light grid position.
118- vec3 lightGridPos = (var_Position - u_LightGridOrigin) * u_LightGridScale;
119- #endif
102+ #if defined(USE_GRID_LIGHTING) || defined(USE_GRID_DELUXE_MAPPING)
103+ // Compute light grid position.
104+ vec3 lightGridPos = (var_Position - u_LightGridOrigin) * u_LightGridScale;
120105 #endif
121106
122107 #if defined(USE_DELUXE_MAPPING)
123108 // Compute light direction in world space from deluxe map.
124109 vec4 deluxe = texture2D (u_DeluxeMap, var_TexLight);
125110 vec3 lightDir = normalize (2.0 * deluxe.xyz - 1.0 );
126- #else
127- #if ! defined(HACK_NO_BSP_GRID_LIGHTDIR)
128- // Compute light direction in world space from light grid.
129- vec4 texel = texture3D (u_LightGrid2, lightGridPos);
130- vec3 lightDir = normalize (texel.xyz - (128.0 / 255.0 ));
131- #endif
111+ #elif defined(USE_GRID_DELUXE_MAPPING)
112+ // Compute light direction in world space from light grid.
113+ vec4 texel = texture3D (u_LightGrid2, lightGridPos);
114+ vec3 lightDir = normalize (texel.xyz - (128.0 / 255.0 ));
132115 #endif
133116
134117 #if defined(USE_LIGHT_MAPPING)
135118 // Compute light color from world space lightmap.
136119 vec3 lightColor = texture2D (u_LightMap, var_TexLight).rgb;
137120
138- #if ! defined(HACK_NO_BSP_GRID_LIGHTDIR )
121+ #if defined(USE_DELUXE_MAPPING) || defined(USE_GRID_DELUXE_MAPPING )
139122 color.rgb = vec3 (0.0 );
140123 #else
141124 color.rgb = lightColor.rgb * diffuse.rgb;
@@ -146,9 +129,13 @@ void main()
146129 ReadLightGrid(texture3D (u_LightGrid1, lightGridPos), ambientColor, lightColor);
147130
148131 color.rgb = ambientColor * r_AmbientScale * diffuse.rgb;
132+
133+ #if ! defined(USE_DELUXE_MAPPING) && ! defined(USE_GRID_DELUXE_MAPPING)
134+ color.rgb += lightColor.rgb * diffuse.rgb;
135+ #endif
149136 #endif
150137
151- #if defined(USE_LIGHT_MAPPING)
138+ #if defined(USE_LIGHT_MAPPING) && defined(USE_DELUXE_MAPPING)
152139 /* Lightmaps generated by q3map2 don't store the raw light value, but
153140 they store light premultiplied with the dot product of the light
154141 direction and surface normal. The line is just an attempt to reverse
@@ -170,13 +157,11 @@ void main()
170157 https://github.com/DaemonEngine/Daemon/issues/299#issuecomment-606186347
171158 */
172159
173- #if ! defined(HACK_NO_BSP_GRID_LIGHTDIR)
174- // Divide by cosine term to restore original light color.
175- lightColor /= clamp (dot (normalize (var_Normal), lightDir), 0.3 , 1.0 );
176- #endif
160+ // Divide by cosine term to restore original light color.
161+ lightColor /= clamp (dot (normalize (var_Normal), lightDir), 0.3 , 1.0 );
177162 #endif
178163
179- #if ! defined(HACK_NO_BSP_GRID_LIGHTDIR )
164+ #if defined(USE_DELUXE_MAPPING) || defined(USE_GRID_DELUXE_MAPPING )
180165 // Blend static light.
181166 computeLight(lightDir, normal, viewDir, lightColor, diffuse, material, color);
182167 #endif
@@ -187,7 +172,7 @@ void main()
187172 #endif
188173
189174 // Add Rim Lighting to highlight the edges on model entities.
190- #if defined(r_rimLighting) && ! defined(USE_BSP_SURFACE ) && ! defined(USE_LIGHT_MAPPING )
175+ #if defined(r_rimLighting) && defined(USE_MODEL_SURFACE ) && defined(USE_GRID_LIGHTING )
191176 float rim = pow (1.0 - clamp (dot (normal, viewDir), 0.0 , 1.0 ), r_RimExponent);
192177 vec3 emission = ambientColor * rim * rim * 0.2 ;
193178 color.rgb += 0.7 * emission;
0 commit comments