VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Direct3D> 2D Part 2, Faking Light

by Mark van Renswoude (6 Submissions)
Category: DirectX
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (20 Votes)

After figuring out how to rotate 2D sprites using Direct3D (check my other submissions), I wanted to do lighting. After reading some tutorials I gave up, they all used 3D, while I wanted to do 2D. There are other ways of faking light; making tiles in multiple shades at either design time or run time, but they're limited...


So here it is: faked light using Direct3D to simulate 2D! It looks great, runs fast (if you've got a 3D card, my P133 with Voodoo 3 could easily run it, although not on software rendering mode), and allows dynamic setting of light brightness and color.

So how does it work? Easy: it sets the color of a vertex (corner) to the brightness of the light at that specific place, after which Direct3D automatically adjusts the texture!



Some limitations though:



  • Light might seem choppy when moved (like in the example), but static lights will do much better... the smaller the tiles, the less you'll notice it, but I didn't want to fill the screen with 8x8 sized tiles...

  • This won't work with multiple lights or multiple colors of lights, you'll need to adjust some algorithms for that to work. I'm working on this problem, if I finish it, I'll post it here offcourse.



Enjoy, and don't forget to leave comments and vote!



(You're free to use this code in your own programs/games, but I would appreciate it if you gave me some credit, thanks!)

Rate Direct3D> 2D Part 2, Faking Light

Download Direct3D> 2D Part 2, Faking Light

Download Direct3D> 2D Part 2, Faking Light (8 KB)

Direct3D> 2D Part 2, Faking Light Comments

No comments have been posted about Direct3D> 2D Part 2, Faking Light. Why not be the first to post a comment about Direct3D> 2D Part 2, Faking Light.

Post your comment

Subject:
Message:
0/1000 characters