Skip to content

Commit

Permalink
renderer: disable normal/specular compute whith lightmap color but mi…
Browse files Browse the repository at this point in the history
…ssing deluxe map direction, ref DaemonEngine#324

Workaround DaemonEngine#324, restore the unavailability of this feature.
  • Loading branch information
illwieckz committed Apr 23, 2020
1 parent 32f8038 commit 9130b08
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions src/engine/renderer/glsl_source/lightMapping_fp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ IN(smooth) vec3 var_Tangent;
IN(smooth) vec3 var_Binormal;
IN(smooth) vec3 var_Normal;

#if defined(USE_BSP_SURFACE) && defined(USE_LIGHT_MAPPING) && !defined(USE_DELUXE_MAPPING)
/* HACK: restore legacy behavior for bsp surface with lightmap
but no deluxemap, do not use the lightgrid to compute the light
direction, do not do normal mapping neither specular mapping
with static lights.
https://github.com/DaemonEngine/Daemon/issues/324
Comment out this line to enable lightgrid light direction with
lightmap light color when there is no deluxe map.
*/
#define HACK_NO_BSP_GRID_LIGHTDIR
#endif

#if defined(USE_LIGHT_MAPPING)
uniform sampler2D u_LightMap;
#else
Expand Down Expand Up @@ -100,25 +113,33 @@ void main()
color.a = diffuse.a;

#if !defined(USE_LIGHT_MAPPING) || !defined(USE_DELUXE_MAPPING)
// Compute light grid position.
vec3 lightGridPos = (var_Position - u_LightGridOrigin) * u_LightGridScale;
#if !defined(HACK_NO_BSP_GRID_LIGHTDIR)
// Compute light grid position.
vec3 lightGridPos = (var_Position - u_LightGridOrigin) * u_LightGridScale;
#endif
#endif

#if defined(USE_DELUXE_MAPPING)
// Compute light direction in world space from deluxe map.
vec4 deluxe = texture2D(u_DeluxeMap, var_TexLight);
vec3 lightDir = normalize(2.0 * deluxe.xyz - 1.0);
#else
// Compute light direction in world space from light grid.
vec4 texel = texture3D(u_LightGrid2, lightGridPos);
vec3 lightDir = normalize(texel.xyz - (128.0 / 255.0));
#if !defined(HACK_NO_BSP_GRID_LIGHTDIR)
// Compute light direction in world space from light grid.
vec4 texel = texture3D(u_LightGrid2, lightGridPos);
vec3 lightDir = normalize(texel.xyz - (128.0 / 255.0));
#endif
#endif

#if defined(USE_LIGHT_MAPPING)
// Compute light color from world space lightmap.
vec3 lightColor = texture2D(u_LightMap, var_TexLight).rgb;

color.rgb = vec3(0.0);
#if !defined(HACK_NO_BSP_GRID_LIGHTDIR)
color.rgb = vec3(0.0);
#else
color.rgb = lightColor.rgb * diffuse.rgb;
#endif
#else
// Compute light color from lightgrid.
vec3 ambientColor, lightColor;
Expand Down Expand Up @@ -149,12 +170,16 @@ void main()
https://github.com/DaemonEngine/Daemon/issues/299#issuecomment-606186347
*/

// Divide by cosine term to restore original light color.
lightColor /= clamp(dot(normalize(var_Normal), lightDir), 0.3, 1.0);
#if !defined(HACK_NO_BSP_GRID_LIGHTDIR)
// Divide by cosine term to restore original light color.
lightColor /= clamp(dot(normalize(var_Normal), lightDir), 0.3, 1.0);
#endif
#endif

// Blend static light.
computeLight(lightDir, normal, viewDir, lightColor, diffuse, material, color);
#if !defined(HACK_NO_BSP_GRID_LIGHTDIR)
// Blend static light.
computeLight(lightDir, normal, viewDir, lightColor, diffuse, material, color);
#endif

// Blend dynamic lights.
computeDLights(var_Position, normal, viewDir, diffuse, material, color);
Expand Down

0 comments on commit 9130b08

Please sign in to comment.