I would like to know, how to make that effect, I have seen in the game named Yomawari. The little girl has a lamp and its cone revals the dark spirits around her. But only if they are in the light. I think it's like the additive blending, but I dont get it to work. I use monogame and c#.
Here is a sample: https://youtu.be/kPLRXP7ovB0?t=1241
All ideas are wellcome (sourcecode preferred ;))
Greetings Kai
My current test code: (DL: https://github.com/EnemyArea/yomawari-lights)
protected override void Draw(GameTime gameTime)
{
var blend = new BlendState
{
ColorBlendFunction = BlendFunction.Add,
ColorSourceBlend = Blend.DestinationColor,
ColorDestinationBlend = Blend.Zero
};
var lightBlendState = new BlendState
{
ColorSourceBlend = Blend.Zero,
ColorDestinationBlend = Blend.SourceColor
};
var mousePosition = Mouse.GetState().Position;
// Draw lights
this.GraphicsDevice.SetRenderTarget(this.blackpixel);
this.GraphicsDevice.Clear(Color.DarkGray);
this.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive);
this.spriteBatch.Draw(this.lichtRund, new Vector2(mousePosition.X, mousePosition.Y), null, Color.White, 0f, new Vector2(this.lichtRund.Width * 0.5f, this.lichtRund.Height * 0.5f), 1f, SpriteEffects.None, 0);
this.spriteBatch.End();
this.GraphicsDevice.SetRenderTarget(null);
// Draw hidden
this.GraphicsDevice.SetRenderTarget(this.renderTarget);
this.GraphicsDevice.Clear(Color.White);
this.spriteBatch.Begin(SpriteSortMode.Deferred, blend);
this.spriteBatch.Draw(this.testeye, new Vector2(this.GraphicsDevice.Viewport.Width / 2f, this.GraphicsDevice.Viewport.Height / 2f), null, Color.White, 0f, new Vector2(this.testeye.Width * 0.5f, this.testeye.Height * 0.5f), 1f, SpriteEffects.None, 0);
this.spriteBatch.Draw(this.blackpixel, Vector2.Zero, Color.White);
this.spriteBatch.End();
this.GraphicsDevice.SetRenderTarget(null);
// Combine all
this.GraphicsDevice.Clear(Color.Black);
this.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
this.spriteBatch.Draw(this.background, Vector2.Zero, Color.White);
this.spriteBatch.End();
this.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
this.spriteBatch.Draw(this.renderTarget, Vector2.Zero, Color.White);
this.spriteBatch.End();
this.spriteBatch.Begin(SpriteSortMode.Deferred, lightBlendState);
this.spriteBatch.Draw(this.blackpixel, Vector2.Zero, Color.White);
this.spriteBatch.End();
base.Draw(gameTime);
}