I have pretty much zero experience working with shaders as my first couple phone games were just 2d games that didn't use any sort of shaders. Now I'm working on a PC game that has a day and night cycle so I found a tutorial and implemented a shader effect with only a basic understand of how it's working. Enough so that I've been able to accomplish what I've desired with darkness and lighting. This is a 2d game as well. Anyway here's my shader effect that I'm using:

texture lightMask;
sampler mainSampler : register(s0);
sampler lightSampler = sampler_state{Texture = lightMask;};

struct PixelShaderInput
    float4 TextureCoords: TEXCOORD0;

float4 PixelShaderFunction(PixelShaderInput input) : COLOR0
    float2 texCoord = input.TextureCoords;

    float4 mainColor = tex2D(mainSampler, texCoord);
    float4 lightColor = tex2D(lightSampler, texCoord);

    return mainColor * lightColor;

technique Technique1
    pass Pass1
        PixelShader = compile ps_2_0 PixelShaderFunction();

And Implement like so:


ScreenManager.SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
ScreenManager.SpriteBatch.Draw(mainScene, Vector2.Zero, Color.White);

I didn't notice any problem at first on my 27" S-IPS 2560x1440 monitor. When I change primary monitors to my 1920x1080 LCD monitor the shaders don't appear to work the same. It doesn't have the soft gradient lighting from my lightmask. It's kind of difficult to describe. The outside edge of the lightmask isn't a fade into darkness. It's more of an abrupt change from being lighter to darker. I've tested on another computer and it's not working right on that other computer either. It has a 22" or so LCD monitor. Anyway I'm just confused as to why it's displaying different based on the monitor. I do scale but I start at 0.6f * hudScale so the lightmask is fairly large and starts even scaled down.

I really don't understand much about shaders so perhaps someone out there can help me understand why there is this difference of how the shader is displaying between monitors. My primary monitor is displaying it exactly how I like it, but more people have 1920x1080 LCD monitors than one like my 25560x1440 S-IPS LED so I want to to display the for all setups.


  • \$\begingroup\$ Can you post some screenshots of the output of your shader on these different setups? Or is it that the pixel values are the same (you've verified this with screenshots), and the monitors display them differently? In that case, can you try to take some photos that show the difference? \$\endgroup\$ Mar 24, 2013 at 16:12
  • \$\begingroup\$ Edited with a screenshot. It's odd, even the screenshot displays that way so it seems it's not necessarily anything programming side that's doing it. The picture isn't perfect but you can sort of see what I mean anyway. It's nothing that terrible. It just comes across a bit differently. \$\endgroup\$
    – Ted
    Mar 24, 2013 at 20:55
  • \$\begingroup\$ So to clarify, on the right half of the image, the sharp circular edge visible in the bottom right is the artifact you're trying to get rid of? \$\endgroup\$ Mar 24, 2013 at 21:21
  • \$\begingroup\$ Yessir, I'm wondering what the reason is for that sharp circular edge to my lightmask that should be soft. This picture here was just a screenshot that was dragged in-between monitors so it appears it may not be a programming problem as I originally thought. I'm just confused to why it's displaying differently, but it's not something I couldn't live with. \$\endgroup\$
    – Ted
    Mar 24, 2013 at 22:07

1 Answer 1


I suspect you're running into an issue with gamma conversion settings. If you're not familiar with this, check out the Gamma FAQ - although you don't need to understand all the details. It's enough to know that the relationship between a pixel value and the intensity produced by the monitor is non-linear, and varies from monitor to monitor (and also depends on OS/driver settings, etc).

Since your light mask is a texture that you've presumably created in some paint program, I suspect what's going on is that the texture contains a subtle sharp edge - perhaps going from RGB = 0 to RGB = some small number, like 10 (let's say) - and this edge is invisible on your primary monitor because the way it displays intensities makes 10 almost as dark as 0. Therefore you wouldn't have noticed it when you painted the texture. However, when you take it to another monitor, RGB 10 (or whatever) is a good deal brighter than 0, so the edge becomes visible.

If that's the case, a simple solution is of course to fix the texture. :) If you turn up the brightness of it in your paint program (using an adjustment layer in Photoshop for instance) you should be able to see the edge.

Alternatively, you might consider using a mathematical function in the shader to generate the falloff, rather than using a texture. If you choose a function that goes smoothly to zero within the boundaries of the sprite, that should avoid any overly-sharp edge being visible on any monitor.

  • \$\begingroup\$ Thank you for that explanation and link. That makes a lot of sense and I'll now see if I can fix it :) \$\endgroup\$
    – Ted
    Mar 24, 2013 at 22:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .