2
\$\begingroup\$

Using the example for some basic light maps found here : http://blog.josack.com/2011/07/xna-2d-dynamic-lighting.html, I've managed to create a lightmap texture using individual lightmaps and display it over a 2D tiled world as in the Platformer example.

I'm using the very basic 2D camera example as found here : http://www.david-amador.com/2009/10/xna-camera-2d-with-zoom-and-rotation/, and the problem is that the lightmap texture scrolls with the player sprite. This looks pretty good and would be excellent for lighting the player sprite as it moves. But, I also want to be able to place static lights (or some initial position for the lights) that do not move with the player or camera.

When I turn off the camera or give it a static position, it works as a series of static lights so I believe it's probably caused by the camera transformation matrix following the player around. I'm using RenderTarget2Ds, one for the main game screen after all the backgrounds and tiles are rendered, and one for the "lightmap" which consists of a black background and a bunch of lighting textures which are merged with it using additive blending.

For now, I'm doing all of this in PlatformerGame.cs where the camera transformation and position is set and the level.Draw() call is made. I can't figure out how to separate the drawing of the lightmap and the camera following the player. I was thinking it would be better to render the shadows and lighting directly in the drawing of the level itself, but I'm not sure how to do that either because this technique requires RenderTarget2Ds and calling SpriteBatch.Begin()/End().

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Most likely you are trying to draw the light map as a full screen quad. Try changing your lightmap to having a world position, like a normal sprite, and rendering it using SpriteBatch.Draw();

You may also find that you don't need the second render target. Create your lightmaps as if their just other objects in the scene. Then give them some transparency and turn alpha blending on. If you make sure to render them at the end, they blend with the scene you have already drawn and either make it lighter or darker.

If you play around with different blending modes you should find one that multiplies you're world pixel colours by the lightmap to give you the lighting effect you want.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .