uniform sampler2D sampler0;
uniform vec2 tc_offset[9];
void blur()
{
vec4 sample[9];
for(int i = 0; i < 9; ++i)
sample[i] = texture2D(sampler0, gl_TexCoord[0].st + tc_offset[i]);
gl_FragColor = (sample[0] + (2.0 * sample[1]) + sample[2] +
(2.0 * sample[3]) + sample[4] + 2.0 * sample[5] +
sample[6] + 2.0 * sample[7] + sample[8] ) / 13.0;
}
Run Code Online (Sandbox Code Playgroud)
样本[i] = texture2D(sample0,...)行如何工作?
似乎模糊图像,我必须首先生成图像,但在这里,我在某种程度上试图查询我正在生成的iamge.这是如何运作的?
它将模糊内核应用于图像.tc_offset需要由应用程序正确初始化,以在实际纹理坐标周围形成3x3的采样点区域:
0 0 0
0 x 0
0 0 0
Run Code Online (Sandbox Code Playgroud)
(假设x是原始坐标).左上角采样点的偏移量为-1/width,-1/height.中心点的偏移需要仔细对齐纹理中心(0.5度问题).此外,硬件双线性滤波器可用于廉价地增加模糊量(通过在纹素之间采样).
着色器的其余部分按照距离缩放样本.通常,这也是预先计算的:
for(int i = 0; i < NUM_SAMPLES; ++i) {
result += texture2D(sampler,texcoord+offsetscaling[i].xy)*offsetscaling[i].z;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3080 次 |
| 最近记录: |