[SOLVED] BlendState question


I want to achieve a lighting/shadowing effect for a 2D game I’m doing, a kind of lightmap.

I have the following texture:

My idea is that blitting the left part of the texture over a patch of grass, it’d render the tree shadow making the currently rendered background darker. But the right part, the “window light” could be rendered in the interior of a building to simulate light lighting up the floor.

When the RGB components of the texture is 128 there should be no shadow nor light, so the current background should be kept intact.

My question is: Is there a BlendState configuration capable of performing those operations? (darkening when close to 0, lighting when close to 255, leaving background intact in 128). I’ve been trying several configurations but I’m unable to get one working.

note: I know I can do this in two steps, but I’m curious to know if this can be done with a single BlendState, as I could render all shadows and lights with one batch instead of two.


On phone rn.

Check out the blendstate properties on msdn.
I think it could work if you draw am the assets before with a 1,1,1,0.5 color and then blend based on alpha difference, but I don’t know if you can make the effect pronounced enough then.

Hi Kosmonautgames,

thanks for your answer. I just found https://blogs.msdn.microsoft.com/shawnhar/2007/01/02/spritebatch-and-custom-blend-modes/ explaining just what I’m trying to achieve :slight_smile: