@@ -36,6 +36,19 @@ 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+
3952#if defined(USE_LIGHT_MAPPING)
4053 uniform sampler2D u_LightMap;
4154#else
@@ -100,25 +113,33 @@ void main()
100113 color.a = diffuse.a;
101114
102115 #if ! defined(USE_LIGHT_MAPPING) || ! defined(USE_DELUXE_MAPPING)
103- // Compute light grid position.
104- vec3 lightGridPos = (var_Position - u_LightGridOrigin) * u_LightGridScale;
116+ #if ! defined(HACK_NO_BSP_GRID_LIGHTDIR)
117+ // Compute light grid position.
118+ vec3 lightGridPos = (var_Position - u_LightGridOrigin) * u_LightGridScale;
119+ #endif
105120 #endif
106121
107122 #if defined(USE_DELUXE_MAPPING)
108123 // Compute light direction in world space from deluxe map.
109124 vec4 deluxe = texture2D (u_DeluxeMap, var_TexLight);
110125 vec3 lightDir = normalize (2.0 * deluxe.xyz - 1.0 );
111126 #else
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 ));
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
115132 #endif
116133
117134 #if defined(USE_LIGHT_MAPPING)
118135 // Compute light color from world space lightmap.
119136 vec3 lightColor = texture2D (u_LightMap, var_TexLight).rgb;
120137
121- color.rgb = vec3 (0.0 );
138+ #if ! defined(HACK_NO_BSP_GRID_LIGHTDIR)
139+ color.rgb = vec3 (0.0 );
140+ #else
141+ color.rgb = lightColor.rgb * diffuse.rgb;
142+ #endif
122143 #else
123144 // Compute light color from lightgrid.
124145 vec3 ambientColor, lightColor;
@@ -149,12 +170,16 @@ void main()
149170 https://github.com/DaemonEngine/Daemon/issues/299#issuecomment-606186347
150171 */
151172
152- // Divide by cosine term to restore original light color.
153- lightColor /= clamp (dot (normalize (var_Normal), lightDir), 0.3 , 1.0 );
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
154177 #endif
155178
156- // Blend static light.
157- computeLight(lightDir, normal, viewDir, lightColor, diffuse, material, color);
179+ #if ! defined(HACK_NO_BSP_GRID_LIGHTDIR)
180+ // Blend static light.
181+ computeLight(lightDir, normal, viewDir, lightColor, diffuse, material, color);
182+ #endif
158183
159184 // Blend dynamic lights.
160185 computeDLights(var_Position, normal, viewDir, diffuse, material, color);
0 commit comments