While researching this technique I ran across many people asking for help with this and most of the help was pointing to broken links or deprecated information. While I make no claims about the quality of the code I do imagine that this will be useful to someone searching for this technique.
If you're just looking to get your feet wet you can download a working demo here.
The following images were used to render the scene:




Background courtesy of Open Game Art
This scene without any effects applied.

The lighting mask dynamically created with additive blending.

The final rendered scene.

Video Example:
Thats what i'm looking for ... thanks a lot.
ReplyDeleteThats what i was looking for too.... but when i tryed to run the sample... i'm getting this error message:
ReplyDeleteXNA Framework Reach profile requires TextureAddressMode to be Clamp when using texture sizes that are not powers of two.
at line 140 in LightingDemo.cs
spriteBatch.Draw(mainScene, new Vector2(0, 0), Color.White);
Can you help me? what i'm doing wrong?
my e-mail is gustavo@ushijima.com.br
thanks a lot!!!
@Anonymous, To get rid of the Clamp error:
ReplyDeletePaste this line of code inside the initialize method:
---
GraphicsDevice.SamplerStates[1] = SamplerState.LinearClamp;
---
Very nice example, I was able to adapt it in one of the games I'm working on. My question is, how would I go about drawing something on top of the darkness? I want to draw a HUD but it is being affected by the dark.
ReplyDeleteI believe you have to call two different Begin chunks. One for the lighting and the background, and then another for the HUD that isnt affected by the lighting
DeleteGood work :)
ReplyDeleteBut i have a question.
How can i run this in XNA 3.1?
This example is exactly that i want but all my project runs in 3.1, i search a lot and couldn't found this in 3.1 :/