Jump to content
  • Advertisement
Sign in to follow this  
Snowprog

Light Simulation 2D

This topic is 3319 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 I'm working with 2D in Direct3D. I have a scene where I want to simulate night. In this night simulation I can use a pocket light. I have solved this problem in this way: I have created a vertexbuffer where the vertices are located in a way that they start at the screen borders and form a hole in the center (this is my pocket light). The color component of the vertices are set to black and alpha 0.5. The result is a scene that is darker and in the middle you see a light circle which looks like a pocket light. Now here comes the drawback: I can only use one pocket light. Obviously when I use two vertexbuffers the triangles will interfere each other. Does anybody have an idea how I can solve this Problem, so that I can use arbitrary number of pocket lights? I thought about manipulating a texture, to display the pocket lights, but I think the pixel per pixel operation will maybe to much work for the system. The pocket light position has to be updated frequently. Oh by the way. I have turned off the ligth in 3D (had some trouble with this). Thank in advance

Share this post


Link to post
Share on other sites
Advertisement
Good approach, though you'd get slightly better quality if you used a simple textured quad.

The issue here is that you are treating the light as a negative quantity: your vertex buffer *subtracts* light from the edges, which obviously won't work when two lights interact.

Are pixel shaders an option? In that case, the solution is trivial: the final pixel color becomes something like "ambient_factor * base_color + attenuation * base_color * light_color", where attenuation is a function of the distance between the light and the current pixel.

I *think* it might be possible to set up a blending mode to achieve similar results, but no idea what blending mode to use.

Finally, you could use plain old fixed-function vertex lighting. I'm an OpenGL guy, so I can't help you here, but google to the rescue.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!