dimitris93
dimitris93

Reputation: 4273

Monogame "lighting" specific objects

I have done something similar to this in Monogame:

2

3

My question is, what would I have to do to draw that lighting effect only on the pillar and not the background ? Is there something like ignoring certain sprites when using BlendState.Additive ? How would that work ? Here is how i'm drawing it now.

//draw background
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque);
spriteBatch.Draw(Background, Vector2.Zero, Color.White);
spriteBatch.End();

//draw pillar
spriteBatch.Begin(SpriteSortMode.Deferred);
spriteBatch.Draw(Texture, new Rectangle(PillarX, PillarY, Width, Height), Color.White);
spriteBatch.End();

//draw lighting sprite in additive mode
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive);
spriteBatch.Draw(LightTexture, pos, null, Color.OrangeRed, 0f, Vector2.Zero, 
    scale, SpriteEffects.None, 0f);
spriteBatch.End();    

Upvotes: 1

Views: 1080

Answers (1)

thegentlecat
thegentlecat

Reputation: 498

Basically, you have 2 options:

  • Use a pixel shader to render the lighting sprite only on the desired area or
  • Use the stencil buffer and render the pillar into it before you aplly the lighting sprite.

I won't explain this in detail because both ways are explained extensively at this question of the gamedev stackexchange.

Upvotes: 1

Related Questions