Don't be afraid of the dark II

Two and a half years ago, the darkness mode was improved to support multiple players as the original only works with one player.

This effect has worked well since then but recently it was reported that some Ubuntu machines produce corrupted RenderTarget textures.

Up until today, it worked by:

  • Creating a RenderTarget
  • Drawing the spot mask for each player to create a new, larger mask
  • Use a Pixel Shader to blend this texture with the scene

Now, this is all done in the Pixel Shader without the need for the RenderTarget!

  • Pass in a blank 640x480 texture
  • Pass in the spot mask texture
  • Pass in the 4 (or less) spot positions for each player
  • If the current pixel being processed falls within any of the spot regions and it's transparent, simply return transparent and break from the loop

Usage is simple, just pass a couple of parameters to the shader and draw.

  
pixelShader.CurrentTechnique = pixelShader.Techniques["DARK"];
pixelShader.Parameters["maskTexture"].SetValue(darkMask);
pixelShader.Parameters["players"].SetValue(spots);
pixelShader.Parameters["playerCount"].SetValue(playerCount);
 
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, pixelShader);
spriteBatch.Draw(darkness, new Vector2(PuzzleBounds.X, PuzzleBounds.Y), PuzzleBounds, Color.White);
spriteBatch.End();

This approach makes the code cleaner (by simply not have an additional RT) and fixes the effect on Ubuntu machines.

Night time!
Darkness mode!

Previous: MMR update #35

Next: MMR update #36

Get the latest posts delivered right to your inbox!

or subscribe via RSS with Feedly!

Author

Gareth

Also a Lode Runner fan. A fan that gets to write the most important parts!

comments powered by Disqus