# Light Simulation 2D

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

## 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 on other sites
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.

1. 1
2. 2
Rutin
20
3. 3
A4L
15
4. 4
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633738
• Total Posts
3013617
×