Client Update

Mycal

Staff member
OK, it was actually extremely simple to port the DX8 code to SlimDX 9. I plan after fully finishing the SlimDX 9 code to also port to SlimDX 10 for those cards that can support it. However, I will not personally be porting to SlimDX11 simply because I do not have a DX11 capable card.

So right now, instead of going through with the first step of drawing a complex map. I decided to work my way up. Right now my goal is to get lighting to work. I am still a little lost on lighting since there are so few tutorials for any version of DX detailing it.

So right now, I've drawn a basic multicolored tilemap for a floor and have set the camera above this. I finally tweaked the camera to be positioned properly. Now when I turn on the lights I run into an issue. I do not know if it's my laptop or if I have set something up wrong, but no matter what I do, the drawn floor appears black. So I've set this code aside and used a simple triangle and tried the same thing. No go, still black.

To ensure that it's not my laptop, I'll have to just stop here and wait until I get to my desktop which I know supports lighting and test.

Anyway, this post is to say that, no matter what, I will get lighting to work before I move on. We don't need anything too complex since we are just 2D. All we really need is point lights, so once this just works, I'll move on. I'll work on tweaking later on when I have a full map drawn.

Also, while there is a camera, it is a fixed camera. I may make use of it for scrolling purposes (I'd like to see how this works in comparison to my old scrolling code), but otherwise it is totally stationary.
 

Mycal

Staff member
AGH, I really hate DX lighting. I kind of get lighting to work, but the ambient lighting was screwing with the diffuse color of the rectangles we're drawing. Obviously this isn't good. Second, my laptop fully supports Direct3D and lighting but refuses to work at all with my code, but works great with some tested compiled programs.

So, all this considered, since I am having such a hard time with lighting, I'm going to try a simpler solution. Who knows, maybe in the future I can figure the lighting out and replace the following method.

Lightmaps are a very common lighting technique used in many games. Basically for those that don't know, a lightmap is a black image with white placed on the portions of the image where you want the map to show through. Right now, I'm going to assume lights are static on maps and not dynamically created (meaning, they are placed on the map and not scripted on the map). Using this assumption (I can change this later, but this is just for testing purposes), a lightmap will be generated once at runtime for the given map. For a 2D world, we don't need to go very complex, so we'll just use radial cutouts on the lightmap.

So first, I'm going to try to see if I can even get lightmaps to display properly, though I have a very good idea how to do this. If this works, then I need to create a way to generate these lightmaps on the fly. So that's what I'm working on today.
 

Mycal

Staff member
Sigh, I just can't get it to look like it did in photoshop :(. But I think it turned out...ok at least. Anyway, here's a screen of 3 point lights using a pre-rendered lightmap.



Now to see if I can generate these lightmaps on the fly. This is the difficult part, so it'll probably be awhile before I post another screenshot :p
 

Attachments

  • lightmap-sample0.png
    lightmap-sample0.png
    123.6 KB · Views: 9

Mycal

Staff member
Hooray!! I did it with the kind help of the community at GameDev.net. I could have sworn I had tried this combination of alphablend states, but it worked this time..Anyway, here is the lightmap working perfectly as I wanted. Maybe need to add a little transparency to it, but otherwise, it looks great.

Now to really get to generating these dynamically :D.
 

Attachments

  • lightmap-sample1.png
    lightmap-sample1.png
    242.2 KB · Views: 7

Mycal

Staff member
Actually this was quicker than I expected. I used a rather simple method of generating the lights, but it works great. No screens yet since I haven't yet done generating multiple lights, but that's a pretty simple matter. Now I need to add some new flags to the map class and lighting is done :D.

Screens with actual map drawings is next. For testing purposes, it will be a rather random map. It will be a multi-tiled floor with random placed objects (to test multiple tilesets), along with per tile instructions (tints [including alpha channels], opacity, xy shifts, rotations), and finally randomly placed lights of varying radius. Hopefully this is done realtively soon, since the lighting didn't take nearly as long as expected.
 

Mycal

Staff member
Ooops, forgot to post the pic, soon as I find where I put my backpack, I'll get my laptop and post a screen :p
 
Top