OpenGL-ES 2.0 (for Android) How to create 2D dynamic lighting effect?

I've been looking for this for some time now and I haven't found a suitable answer. I want to create a 2D dynamic lighting effect on android using OpenGL-ES 2.0 like in this video:

But I don't know where to start.

If anyone could help me a little to get me started, I would really appreciate it.

Thank you in advance


source to share

1 answer

I'm not sure how the author of the video implements this effect. But just by watching the video and reading the comments below, I think one can achieve this effect like this:

First, consider the case with only one light source. You can paint a radial gradient texture in advance. (brightest in the center, darkest on the border and gray in between. You can paint this with Photoshop.) Draw this texture in the center of the light. Then you need to create triangles to make the shadow. Suppose the light is at point A. For each BC line segment on any polygons, you need to extend the AB line to point D far enough away (at least on screen). Also add AC to point E. Then you have quad BCED (or two triangles BCD and CDE). Take this square with black. Do the same for all line segments of all polygons. This is a shadow. And you get the effect for one light source.

For multiple lights, you can affect each light on a framebuffer object (FBO). And the end result is just TSF averaging. (Actually you can only use one FBO to accumulate the color value for each light source. And in the last pass, you just need to divide it by the number of lights).

I think there is an easy way to achieve 2D light effect.



All Articles