Trying to do the classic gradient circle lights seen commonly back in the XNA days:
Pass 1: Render lights into a light map
Pass 2: Render Scene
Pass 3: Multiply in shader
Set up the shader as this:
#if OPENGL
#define SV_POSITION POSITION
#define VS_SHADERMODEL vs_3_0
#define PS_SHADERMODEL ps_3_0
#else
#define VS_SHADERMODEL vs_4_0_level_9_1
#define PS_SHADERMODEL ps_4_0_level_9_1
#endif
Texture2D Texture : register(t0);
sampler TextureSampler : register(s0)
{
Texture = (Texture);
};
Texture2D LightMap;
sampler LightMapSampler
{
Texture = <LightMap>;
};
float4 Main(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
float4 mainColor = tex2D(TextureSampler, texCoord);
float4 lightColor = tex2D(LightMapSampler, texCoord);
return mainColor * lightColor;
}
technique BasicColorDrawing
{
pass P0
{
PixelShader = compile PS_SHADERMODEL Main();
}
};
This results in just a black texture with no out put, the code for drawing is as below:
// Create a Light Mask to pass to the pixel shader
GraphicsDevice.SetRenderTarget(m_LightMap);
GraphicsDevice.Clear(Color.Black);
m_SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);
m_SpriteBatch.Draw(m_Light.LightCookie, new Vector2(0, 0), Color.White);
m_SpriteBatch.Draw(m_Light.LightCookie, new Vector2(500, 0), Color.White);
m_SpriteBatch.Draw(m_Light.LightCookie, new Vector2(500, 200), Color.White);
m_SpriteBatch.Draw(m_Light.LightCookie, new Vector2(100, 400), Color.White);
m_SpriteBatch.End();
// Draw the main scene to the Render Target
GraphicsDevice.SetRenderTarget(m_Camera.RenderTexture);
GraphicsDevice.Clear(Color.CornflowerBlue);
m_SpriteBatch.Begin();
m_SpriteBatch.Draw(m_Texture, new Rectangle(0,0, m_GraphicsDevice.Viewport.Width, m_GraphicsDevice.Viewport.Height), Color.White);
m_SpriteBatch.End();
// Blend together
m_LightEffect.CurrentTechnique = m_LightEffect.Techniques[0];
m_LightEffect.Parameters["LightMap"].SetValue(m_LightMap);
GraphicsDevice.SetRenderTarget(null);
GraphicsDevice.Clear(Color.Black);
m_SpriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, null, m_LightEffect, null);
m_SpriteBatch.Draw(m_Camera.RenderTexture, Vector2.Zero, Color.White);
m_SpriteBatch.End();
This is the LightMap Target:
And the scene target is just filled with a free brick texture for test purposes instead of my tile map:
Thanks.