Drawing on a RenderTarget2D with values over 1

Hello.

I was trying to make a lightning system. I have a RenderTarget2D that starts at black where the lights are drawn with additive BlendState. It then multiplies the normal render colors., and for the moment works. The problem is that im not able to get the values to pass over 1 (for light to have a greater intensity).

When I draw the lights map over the game render with the following blend state (to multiply the rgb and keep the alpha that is always 1 on the light map)

public readonly static BlendState LightBufferDrawBlendState = new(){
    ColorDestinationBlend = Blend.SourceColor,
    ColorSourceBlend = Blend.Zero,
    ColorBlendFunction = BlendFunction.Add,

    AlphaDestinationBlend = Blend.SourceAlpha,
    AlphaSourceBlend = Blend.Zero,
    AlphaBlendFunction = BlendFunction.Add
};

The image result is not the one I expected.
For drawing the lights in the LightBuffer, I apply a brighten effect as the effect parameter I use for beggining the SpriteBatch, where the Bright is the Light color / intensity.:

float4 MainPS(VertexShaderOutput input) : COLOR
{
	float4 baseColor = tex2D(SpriteTextureSampler,input.TextureCoordinates) * input.Color;
	return float4(baseColor.x*Bright.x, baseColor.y*Bright.y, baseColor.z*Bright.z, baseColor.w);
}

Note that the RenderTarget is instantiated with SurfaceFormat of HalfVector4 so that it can allow numbers over 1.

I don’t really have a lot of experience with MonoGame shading/effects/advanced drawing so im a bit lost.

Thank you.

I ended up figuring it out. In case someone needs it:
I just draw the light buffer over the base render
spriteBatch.Draw(LightsBuffer,new Rectangle(0,0,ViewportSize.X, ViewportSize.Y), Color.White);

With the spriteBatch begun with a shader whose pixel function is:

float4 MainPS(VertexShaderOutput input) : COLOR
{
	return tex2D(BaseRenderSampler,input.TextureCoordinates)*tex2D(SpriteTextureSampler,input.TextureCoordinates) * input.Color;
}

Using the light buffer as a texture in the final shader makes the multiply step much clearer and is a useful approach for others working with RenderTarget2D.

1 Like