I have a weird issue when trying to render the lightmaps in my game.

Please see the following screenshots.

Note how the scene looks up close with the lightmaps enabled. Close-up with lightmap enabled

Note how that same part of the scene is now completely blacked out (as well as its surroundings) - this happens gradually as you zoom out.

Same scene from a distance with the lightmap

When I completely disable the lightmap, nothing is blacked out, making me believe its related to the way I apply it with HLSL.

Same scene from a distance without the lightmap

Here's how I my Pixel Shader code looks like:

float4 PS1(VSO input) : COLOR
    float4 albedo = (HasAlbedo) ? tex2D(AlbedoSampler, input.UV) * input.Color : input.Color;
    float4 lightmap = (HasLightMap) ? tex2D(LightMapSampler, input.LightMapUV) : float4(1, 1, 1, 1);

    float4 finalColor = float4(albedo.xyz * lightmap.xyz, 1.0f);

    return (HasFog) ? input.FogFactor * finalColor + (1.0 - input.FogFactor) * FogColor : finalColor;

Am I doing something wrong in my HLSL? Or is it most likely something else?

For some additional information:

  • I use SharpDX in combination with C#.

  • The assets in the screenshots come from the game "Medal of Honor Allied Assault", so my sincere apologies for the Swastika signs if it offends anyone. This scene just happened to show the issue perfectly.


I fixed the issue myself!

After some more testing I found out that even if the lightmap would make the full scene overbright (just like it would when it was forcefully disabled in the HLSL), it still generated black shadows.

Because of this discovery I went back to my texture declaration:

LightMaps[i] = new Texture(GameHelper.Device, BSPFile.LIGHTMAP_SIZE, BSPFile.LIGHTMAP_SIZE, 0, Usage.None, Format.A8R8G8B8, Pool.Managed);

I started fiddling what made most sense to me, which was the LevelCount. After setting it to 1, rather than 0, the issue resolved itself!

After Googling I found out what the LevelCount actually does and by setting it to 1, I disable a hardware feature where downscaled versions of same texture get generated and shown based on the distance between the surface of that texture and the camera. It now totally makes sense why this messes things up.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.