1 / 19
文档名称:

cocos2dx文献翻译.doc

格式:doc   大小:2,060KB   页数:19页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

cocos2dx文献翻译.doc

上传人:文艺人生 2022/4/18 文件大小:2.01 MB

下载得到文件列表

cocos2dx文献翻译.doc

文档介绍

文档介绍:cocos2dx文献翻译
[ Tutorial] RenderTexture + Blur
This tutorial will help you to understand how you came a little bit transparent). This can be guaranteed by calculating the central coefficient as 1 - sum of all the others.
So, to the codes. The idea is to pre-calculate gaussian coefficients on start, pass them to the shader and do no math other than multiplication inside.
Besides the standard v_fragmentColor and v_texCoord we have four additional parameters:
1. pixelSize - in GLSL there are no pixels, only decimals, for instance 0 denotes the left or the l
ower border of the texture and 1 - the right or the upper border. This means we have to know the decimal step to make to the next pixel.
2. radius - our blur radius
3. weights - array of precalculated gaussian weights
4. direction - 2d vector denoting horizontal or vertical blur
The word "uniform" in front of these values mean that they are not going to change during the run. The rest of the shader body is pretty straightforward: take a pixel, accumulate surrounding pixels with some coefficients and voila. I had to hardcode maximum array size to be 64 as I found no way to use a dynamic array as a uniform in shader.
Everything is pretty much self-explanatory here. We create a new GLProgram using the standard vertex shader and our blur shader, pass additional parameters using GLProgramState class and everything is ready to go. One may encounter another way of assigning the shader body to GLchar* variable, something like this:
I prefer using String::createWithContentsOfFile because it frees you from necessity to write \n\ at the end of every line which is quite annoying.
The only thing left to do is actually blurring a texture. Our strategy here will be as follows:
1. Create a sprite from the texture passed as a parameter
2. Draw it to a RenderTexture with horizontal blur shader
3. Create a sprite from resulting texture
4. Draw this sprite to a Render texture with verti