Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Mixed use, algorithm and calculation of OpenGL
Mixed use, algorithm and calculation of OpenGL
Blending is essential in OpenGL multi-layer overlay and buffer color calculation. Developers can mix through OpenGL's own mixing interface, or they can customize related mixing algorithms in the shader. This paper will explain in detail the calculation method of the blending algorithm that comes with OpenGL, and help developers who need color blending operations to quickly understand the meaning and calculation method of the blending algorithm, and briefly explain the realization of the two blending methods.

OpengGL provides mixing functions in 15 for developers to use quickly, including (mixing coefficient, mixing factor, enumerated values of comments):

Turn on the mixed mode in the actual application scenario. Draw a color W(0.3, 0.4, 0.7, 0.5) on the layer first, and then draw a color X(0.8, 0.2, 0.3, 0. 1). If the mixing function is glblendfunc (GL _ src _ alpha, GL _ one _ minus _ src _ color) and the operator is glblendequeation (GL _ func _ addfunc _ add), the mixing result is calculated as follows:

The condition is the same as that of 1, except that the mixing function adopts glblendfuncspective(GL _ one, GL _ one _ minus _ src _ alpha, GL _ one, GL _ one _ minus _ dst _ alpha), which can be known through decomposition.

Due to the limitation of OpenGL's own mixed algorithm interface, it is impossible to customize the extension except the above contents, so developers can also complete the mixing in the shader. However, this method not only needs the color buffer data of the current frame as the shader input, but also needs the color buffer data of the previous frame, so that the custom algorithm can complete the blending. Therefore, it has some shortcomings in time and space, but it is a hybrid algorithm with high degree of freedom and customization. The use of blending in shaders will be introduced as an example in a future article.