• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
rApp

[XnA] 2D Lighting - How is it done?

9 posts in this topic

[font="Arial"][size="6"]Hello![/size][/font]
I've been curious lately on how you make your own "2D Lighting"-engine? (Is it called engine?)
I've tried to find a XnA-tutorial on how to achieve this but my search havent been successful, most finds have been in a 3D enviroment.. :/

What i want to achieve is something like in this game[url="http://www.youtube.com/watch?v=UGo7iMUcxLc"] [/url]
[url="http://www.youtube.com/watch?v=UGo7iMUcxLc"]http://www.youtube.c...h?v=UGo7iMUcxLc[/url]

Im completety noob when it comes to this so please be patience! :(
Are there any tutorials for XnA 2D Lighting? (No 3D! :()
0

Share this post


Link to post
Share on other sites
I'm an old Direct3D user rather than XnA, but hopefully a lot of this translates to what you're doing. I wrote a 2D engine using textured quads (triangle strips) and added the sort of 2D lighting shown in your video. I did it by altering the vertex colors and intensities to simulate lighting.

First I added a "light" (or several) to a scene, which was really just a 2D x,y coordinate, an RGB color, an intensity, and a range. I made a class called "light" to store that data.

Since 2D textured quads are rendered using the texture colors modulated by the vertex colors, your vertex colors are normally all white (red is 255, green is 255, blue is 255) if you want to see the original texture. If you want to darken the texture, you can darken the vertex colors (something like 127, 127, 127) and your texture will appear darker.

I used this texture modulation feature to do my 2D lighting. Each scene refresh I would set all my scene vertices to an unlit "ambient" level. This could be a little below 255, 255, 255, if I want very subtle lighting or 0, 0, 0, if I want the player to only see what is being lit (like the cavern levels in your video). Then I checked the distance of each light in the scene against each vertex in the scene and, if the light affected the vertex (by that I mean that it was close enough), I would add that light's color and intensity to the vertex's "ambient" color.

Once I'm done accumulating the light effects on each vertex, I use the accumulated color to render the quad, and it appears to be lit. This method does have its limitations, but it will get you simple 2D colored per-vertex lighting. Again, I'm an old-school D3D guy (DX8.1), so maybe they've come up with an easier way to do 2D lighting since then with XnA.
0

Share this post


Link to post
Share on other sites
Okey, I think I get what you are saying.
But how would i make everything dark and then get the bright thing to "overrun" that? (Sorry for being novice, but I really wanna know these things! :))
0

Share this post


Link to post
Share on other sites
For my 2D games, I wrote a light pre-pass renderer as described by Wolfgang Engel [url="http://diaryofagraphicsprogrammer.blogspot.com/2008/03/light-pre-pass-renderer.html"]here[/url]. I wrote it as if I were writing a 3D renderer, but was able to take some geometric shortcuts because I knew the game was a 2D platformer. The image below shows the results (light pre-pass + tone mapping + bloom). The material on the tiles use normal and specular maps in addition to their diffuse color. The characters are rendered without light.

[img]http://dev.willrmiller.com/BurgerQuest/BurgerQuest10.png[/img]

Using this approach, my engine supports hundreds of dynamic lights at very high framerates. Most 2D engines that have lighting aren't this complex though. You can get acceptable results by simply rendering your lights with additive blending after you've rendered the rest of your scene. You should check out a game called [url="http://forums.tigsource.com/index.php?topic=18578.0"]The Archer[/url] which is being developed over at TIGSource for an example of this.
0

Share this post


Link to post
Share on other sites
Geolycosa, how are you making the rest of the map black?
Are you placing some kind of texture over the whole scene or are you drawing that with a black color if the "light" can't reach?

And how are you making, sorry for sounding absolutely stupid but, the light go in all directions?
I mean what's making it act like a "ray"?
0

Share this post


Link to post
Share on other sites
[quote name='rApp' timestamp='1304348102' post='4805465']
Geolycosa, how are you making the rest of the map black?
Are you placing some kind of texture over the whole scene or are you drawing that with a black color if the "light" can't reach?
[/quote]

I use three maps to compute light at each pixel: a normal map, a specular / diffuse intensity map, and a color map. The specular / diffuse intensity map modulates the specular and diffuse light contribution to each pixel.


I don't compute a "ray" so to speak. The lighting process is detailed on Engel's blog, but essentially it works by rendering in these passes:

Geometry Pass (out: gbuffer) - Encode position and normal vectors into a gbuffer

Light Pass (out: light buffer) - For each light, sampling the gbuffer, render light color * N.L * attenuation in R, G, and B channels, then the specular contribution in the A channel. Render with additive blending.

Material Pass (in: light buffer) - Forward render each object and compute light by sampling the light buffer.

Again, if you're really interested in the nuts and bolts of this, I would encourage you to study Engel's work on the subject.
0

Share this post


Link to post
Share on other sites
[quote name='geolycosa' timestamp='1304349197' post='4805476']
[quote name='rApp' timestamp='1304348102' post='4805465']
Geolycosa, how are you making the rest of the map black?
Are you placing some kind of texture over the whole scene or are you drawing that with a black color if the "light" can't reach?
[/quote]

I use three maps to compute light at each pixel: a normal map, a specular / diffuse intensity map, and a color map. The specular / diffuse intensity map modulates the specular and diffuse light contribution to each pixel.
[/quote]
Okey, how are these maps made?
I mean like, are there three different textures? (Have they been made by you using a program like photoshop or are they made "on the run"?)
If they are made "on the run", do you have any good tutorials for this?

As far as i've reached now im only printing a 1x1px texture stretching the whole screens resolution, and then just fades this using COLOR in the Draw-method.. This doesnt feel like im doing it right! :P
0

Share this post


Link to post
Share on other sites
[quote name='rApp' timestamp='1304349528' post='4805480']
[quote name='geolycosa' timestamp='1304349197' post='4805476']
[quote name='rApp' timestamp='1304348102' post='4805465']
Geolycosa, how are you making the rest of the map black?
Are you placing some kind of texture over the whole scene or are you drawing that with a black color if the "light" can't reach?
[/quote]

I use three maps to compute light at each pixel: a normal map, a specular / diffuse intensity map, and a color map. The specular / diffuse intensity map modulates the specular and diffuse light contribution to each pixel.
[/quote]
Okey, how are these maps made?
I mean like, are there three different textures? (Have they been made by you using a program like photoshop or are they made "on the run"?)
If they are made "on the run", do you have any good tutorials for this?

As far as i've reached now im only printing a 1x1px texture stretching the whole screens resolution, and then just fades this using COLOR in the Draw-method.. This doesnt feel like im doing it right! :P
[/quote]

There are three different textures used per material. I used Photoshop to create the color and light intensity maps. For the intensity maps, I have diffuse intensity in RGB and specular intensity in A. The normal maps were generated in a program called [url="http://www.crazybump.com/"]Crazy Bump[/url]. Crazy bump is pretty good at generating normal maps from organic looking images (rocks and stuff), but not so good at making maps for non-organic surfaces. For that, I would suggest actually modeling the shapes in a 3D modeling application (Google's [url="http://sketchup.google.com/"]SketchUp[/url] will suffice) and generating the normal maps that way.


0

Share this post


Link to post
Share on other sites
I've read some of the different links you have provided me but i still don't really get where I should start... :/

If I wanna start simple, a square that gives you light to a scene.
-Is this "easy" to make?
If yes, where do i start?
I've tried to find tutorials that is 2D and with XnA but i havent found a single one that works.. All the others seems to be working with 3D which i dont wanna get into right now.

Sorry for being a pain :(
0

Share this post


Link to post
Share on other sites
[quote name='rApp' timestamp='1304351855' post='4805502']
I've read some of the different links you have provided me but i still don't really get where I should start... :/

If I wanna start simple, a square that gives you light to a scene.
-Is this "easy" to make?
If yes, where do i start?
I've tried to find tutorials that is 2D and with XnA but i havent found a single one that works.. All the others seems to be working with 3D which i dont wanna get into right now.

Sorry for being a pain :(
[/quote]


You're not going to find a tutorial on exactly how to do this in 2D (it's not something that's commonly done), but the 3D implementations you're probably looking at are very close to the 2D ones (the math and setup are exactly the same). If you want an XNA implementation of light pre-pass, check out J. Coluna's excellent [url="http://jcoluna.wordpress.com/2011/01/18/xna-4-0-light-pre-pass/"]post[/url] on the subject. If these links don't make sense to you, this lighting implementation might be out of your reach at this point. I would recommend finding some basic XNA tutorials on shader-based per-pixel lighting (even though they are 3D) and figure out how they work. It's simple to take those techniques and use them for 2D.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0