Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Lightmapping in 2D Environment (DX8)

This topic is 5227 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, I am trying to figure if this is possible or not. Say I have D3DDevice setup in 640x480 32bit. I draw a bunch of 2D sprites using quads. Now I have another quad, about 100x100 pixels, in the middle of the screen, with a texture on it. The texture is a lightmap, which gradients from black (edges) to white (center), making a smooth ball-looking circle. I know how to blend this on top of everything else and have the darkest part of the lightmap darken everything in the background and the lightest pasrt doesn''t change what''s in the back. The thing is, if this lightmap is 100x100 pixels, everything outside it doesn''t change. I could stretch out the map to fullscreen, and that works fine, for a static, in the center lightmap. But what if I want to have a bunch of them, and resize by sizing the quad, is it possible using blending? For example, could I have 10 small quads, representing lightmaps, all over the screen, and whatever is outside of these quads should be black, or the color of the light, everything inside should get blended and darken up the dark areas of the texture. Is this possible? I hope I''m being clear on my problem! Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
if i'm understanding correct.. could you render the light maps first then use a color modulation blend to render the sprites? that way the sprites only are drawn where there is color drawn on the screen from the lightmaps and they'll blend with that.

[edited by - shmalbus on April 19, 2002 10:30:30 AM]

Share this post


Link to post
Share on other sites
Hmmm... That''s an interesting idea. For some reason I could only picture the lightmaps being drawn ontop of everything, but this makes sence. I''ll try it out, and hopefully get it to work.

Thanks for the suggestion.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Can''t you just do an AND copy with your sprite onto the image. This would blend the sprite over it how you wanted (white parts are fully visible, black is black, and grey is partially visible). I don''t know exactly how, but I know in GDI you can set it to do this, so I''m assuming ddraw has something similar.

Billy

Share this post


Link to post
Share on other sites
OK, I tried rendering the lightmaps first and got it partially to work, but. Say I have a lightmap, then I draw the sprites ontop of it using special blends so the darker the destination pixel is, the darker that part of the sprite copies. Works fine if I blend the sprites on top of a lightmap, but if a sprite goes where another sprite already is, id blends again, making sprites that overlap look semitransparent.

This is how I draw lightmaps:
D3DDevice.SetRenderState D3DRS_SRCBLEND, D3DBLEND_SRCALPHA
D3DDevice.SetRenderState D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA

And this is for the sprites ontop:
D3DDevice.SetRenderState D3DRS_SRCBLEND, D3DBLEND_DESTCOLOR
D3DDevice.SetRenderState D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA

Basically, this would be perfect for 3D polygons, 1 lightmap per face, but for 2D environment, where sprites overlap, and the lightmaps go freely all over the screen, I''m guessing the best way would be to draw the lightmaps ontop of everything.

But if I draw the lightmaps on top, how can I achieve multiple lights from the same texture at different positions and sizes, so when 2 of them meet, they blend together as 1 light? One way I thought of would be to draw a quad all over the screen with 1 texture on it, then depending on the light positioning I could draw over the texture real time and display the whole thing, but this method appears very slow, due to me using Visual Basic. I really need this thing to work using one circle lightmap at any size position, multiple times. The must be some way.

Thanks in advance for any suggestiones

Share this post


Link to post
Share on other sites
C''mon guys, there must be something I''m missing, how did Diablo 2 do their lights? Do they render the lightmaps in realtime using pixel plotting?

Share this post


Link to post
Share on other sites
Hello,

I know it's quite awhile this topic received its last reply, but it is one of the first which describes the same problem I have

I am one out of two programmers who are working on a kind of RPGish Zelda-like game (Cataclysm...it's been awhile since our site was updated, but the project is still alive!!). The programming-process went smoothless, until we ran into the lightmap-problem.

Cataclysm is a 2d-game using a directx9 lib (Powerdraw3pre3). At first we draw a big background bitmap (1024*768*16bit). On top of that some sprites and tiles. On top of that we wanted to draw our real-time lightmap (multiple lightsources), but we've encountered the exact problem described above in the original post/replies.

Since this is a old topic, I was hoping someone knows a solution to this problem. Obviously, pixel plotting is out of the question since this will kill our framerate, isn't it??

Greetings,
Sander


[edited by - Sannepan on January 27, 2004 5:02:45 PM]

[edited by - Sannepan on January 27, 2004 5:03:50 PM]

Share this post


Link to post
Share on other sites
What I did was to use an extra texture and every frame render all visible lights to it, adding the lights togheter. Then I rendered that one lightmap over everything else. Looked fine and was fast enough.

Share this post


Link to post
Share on other sites
Hi Huga,

Wow, I never expected such a quick reply

Well, you have the right solution. The problem is, how do you do that?? I''m not that of a crack (yet) with the directX stuff.

If you have an example, you will make this boy very happy.

Thanks in advance,
Sander

Share this post


Link to post
Share on other sites
Well, it''s been almost a year since I wrote that game so I don''t really remember... But I can dig up some really horrible code for you if you''d like. You can email me at marda978___APA___AT___APA___student.liu.se (without the ___APA___''s of course)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!