Skip to main content
gamedev.net
🔒 Locked

Direct3D Texture Rendering

Started by ADM Dec 9, 2005 at 5:35 PM 11 replies 2.4k views
Original Post
ADM
ADM
I'm making a 2D engine tile based game using DirectX 9 in VB.net. I'm using a texture (loaded bmp) to simulate light when blended with the game sprites. The problem is that I only want the tiles to blend with the lightmap texture, but the tiles blend with the lightmap texture and ALSO blend with every other sprite (some tiles are overlapped). I tried using lighting with Direct3D but I couldn't get it working right. I'm using Direct3D.Sprite.Draw to render each texture. How would I get lighting effect working correctly? What if I were to somehow 'combine' all the tile textures into 1 texture and then apply the blending effects? Thanks alot. [Edited by - ADM on December 10, 2005 7:45:09 AM]
lack o comments
lack o comments
It sounds like you aren't changing render states to a non-blending operation when you go to render the sprites. Is that right?
ADM
ADM
I need them to blend otherwise the tiles don't have the light effected added to them. I just don't want them to blend with other tiles. :P
lack o comments
lack o comments
I really am not getting the gist of what you are trying to do.

Quote:

I'm using a texture (loaded bmp) to simulate light when blended with the game sprites

How exactly are the sprites and the lightmap interrelated here? From this I almost get the impression of some kind of dynamically created lightmap. Is that right? I don't really understand the effect you are trying to obtain just from this sentence. Be a little more descriptive of the process and the output you want.

If you are simply trying to render a tile-map, some sprites and a lightmap ontop of all of that, just say so. Otherwise, give a little more detail.

Sorry I'm not getting this [grin]
ADM
ADM
Here is a picture to show you my problem. The grayscale image I use makes it look like my player is using a lantern light. The only problem is that using this effect makes tiles blend with one another.

http://www.project52.net/mir/example4.JPG
ADM
ADM
Is there a way I could draw about 400 textures to one big (screen size) texture instead of rendering directly to a sprite?
sirob
sirob
How are you currently blending the lightmap with the tiles? Are you using Alpha-Blending or using Texture Stage States. You want be using the latter, and if you are, could you post that peice of code for it? If you're using Alpha-Blending, look into Texture Stage States :).

Hope this helps.
Sirob Yes.» - status: Work-O-Rama.
ADM
ADM
I first draw the lightmap texture wit these properties:

D3D.RenderState.SourceBlend = Blend.One
D3D.RenderState.DestinationBlend = Blend.One

Then I draw the tiles, players, buildings ontop of one another using:

D3D.RenderState.SourceBlend = Blend.Zero
D3D.RenderState.DestinationBlend = Blend.SourceColor

Here is my lightmap texture:

http://www.project52.net/mir/0.JPG
sirob
sirob
Right, so you are currently drawing in 2 passes. One for the lightmap, and then another for the tiles.

What happens is that alphablending blends with what's in the backbuffer when you draw, so you can't modulate with only the lightmap where the tiles overlap.

What I'd recommend is using Texture Stage States to perform the operation in one pass, instead of two. Using TSS allows you to select how each pixel is textured, when it is drawn. What you need to be looking into is how to modulate your texture with the lightmap in one pass.

Hope this helps.
Sirob Yes.» - status: Work-O-Rama.
ADM
ADM
How would I use texture stages with Direct3D.Sprite?
sirob
sirob
hrm, you actually can't use TSS with Sprites, sorry, I didn't notice you were using them. :(

What you can do, however, is switch your rendering order. First, draw all the tiles with alpha-blending disabled completely. Then, when you're done with the drawing, draw the lightmap onto the tiles, with alphablending enabled. While this isn't the best solution, it should work out okay.

Hope this helps.
Sirob Yes.» - status: Work-O-Rama.
ADM
ADM
I did that earlier and it works great. Yet the problem comes when the lightmaps overlap. This is an example of what happens: http://www.project52.net/mir/Lighting.JPG

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.