I found Unity3D's 2D Light Renderer, and then put it copied over

. A few months ago, I happened to see someone in the group discussion Unity3D light , so I sprouted a new target ---- copied it over!

As we all know, 3D rendering of the entire pipeline closely related to lighting, the number of related technology is not quite count, and 2D game lighting is often overlooked because most games are 2D overlay maps, to what effect, art direct drawn on the bin, so most of the 2D game engine, but it is a texture engine, doing the work has not rendered a little technical content rendering.

Even 2D game, make good use of the light source can also enhance the quality of a grade, but, as mentioned earlier, 2D engines do not provide this functionality, with 2D engines do not know the technology, so most dynamic light effects 2D games are foreign goods.


. Entered, recording what I spent editing 2D light source to achieve two weekends.

Renderings

End product

General idea

Mr. Cheng illumination area, at a later stage can be output by sampling the full screen area, which lies in the difficulty to generate the illumination area.

Since the beginning of the area and the illumination area and an outer area, the inner area is, the light emitting portion, light does not attenuate, the area is outside the range of radiation, light will gradually decay, in this context, also partial area of ​​the light area of ​​a circle and a polygon area.

Generating area of ​​a circle:

And generated by a radius of the circular area, the outer area then generated by a given level of radiation, the shape looks like a ring, then after the filling area, and a triangular loop, the way is finally generated such.

Circular segment _

Generating polygon area:

Given by generating the vertex area then generated by a given outer area of ​​radiation, the idea is the same as with a circular, polygonal but two slightly difficult problem. One is polygonal in shape is not controllable, if a concave polygon, the area of ​​the superimposed light, which can cause multiple superimposed portions are light. The other is not as round as a uniform polygonal shape, Imagine a light that comes out of the same degree of light attenuation at the same distance should be the same, take a circular light source, the light emitted from the inner edge of the area, finally reached the outer edge of the area, when the light emitted immediately (when the internal edge area) attenuation value of 1 (maximum value), when the light reaches the end (when the outer edge area) attenuation value of 0 (minimum), and it is a uniform circular shape, so that any angle satisfying this condition, the polygons are required to do this through a little computational cost.

The first point to address: the largest convex hull can be obtained.

Solving the second time point, computing an outer area of ​​a polygon with rounded corners instead of sharp angles.

The final generation look like this.

Polygon line _

_ _ Filled polygon segment

_ Filled polygons


final effect

There are line drawing

Presentation charts _ There are segments

Wireless segment Draw

Wireless segment presentation charts _

Github Portal

Guess you like

Origin www.cnblogs.com/mmc1206x/p/11784206.html