Skip to main content
gamedev.net
🔒 Locked

Lighting Question

Started by Moxiousness 2 replies 700+ views
Original Post
Moxiousness
Moxiousness
I am trying to implement a simple, yet fast, lighting in a 2d game. My original method was using a library I wrote in MMX and C, via DLL (this is a visual basic game) and storing an alpha/brightness value per pixel, and shading the map to black based on the mapped value. It was reasonably fast, but this was using directdraw. I converted my game to directx8, and now I am not sure how to do it. I don't want to use this DLL any more, so I was wondering if there was some way I could do something such as .. create a texture the size of the viewport, and "clear" it to the ambient light, and then draw light sources on it, by setting this texture as the render target? I'm not sure how I can do this, as I want to only add the alpha values to the texture, so that the "light" is merely "less dark" but never brighter than the original color. Any help would be appreciated.
MJP
MJP
Unfortunately I'm not too familiar with how Direct3D8 works...I'm really only familiar with D3D9 and D3D10 myself.

However you should be do it like this:

-Render all your sprites to a render target
-Render all your lighting to another render target, using additive blending. As long as you don't use a floating-point format, the output will always be clamped to [0,1]
-Render a full-screen pass using a pixel-shader that multiplies the values of the two render targets, and output to the backbuffer.
Moxiousness
Moxiousness
hmm that sounds about what I want ... but what about compatibility? It's a pretty simple game, but I am willing to make sacrifices.
Moxiousness
Moxiousness
Thanks for the help, I got it working. I used additive blending like you said, but instead of a pixel shader, I was able to use the fixed function pipeline to perform the same thing ... basically like this:

SetRenderState D3DRS_SRCBLEND, D3DBLEND_DESTCOLOR
SetRenderState D3DRS_DESTBLEND, D3DBLEND_ZERO

Works like a champ.

Topic Locked

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

Sign in to reply to this topic.