我想使用以下代码模糊图像
{
const GLchar fShaderText[] = FRAGMENT_SHADER_SOURCE
(
uniform sampler2D imageTexture;
uniform highp float w0;
uniform highp float w1;
uniform highp float w2;
uniform highp float w3;
uniform highp float w4;
uniform highp float w5;
uniform highp float w6;
varying highp vec2 uv0;
void main()
{
highp float u_dx = 1./imageWH.x;
highp float sum = 0.;
highp vec4 col = texture2D(imageTexture, uv0);
sum += texture2D(imageTexture, vec2(uv0.x - 6. * u_dx, uv0.y)).x * w6;
sum += texture2D(imageTexture, vec2(uv0.x - 5. * u_dx, uv0.y)).x * w5;
sum += texture2D(imageTexture, vec2(uv0.x - 4. * u_dx, uv0.y)).x * w4;
sum += texture2D(imageTexture, vec2(uv0.x - 3. * u_dx, uv0.y)).x * w3;
sum += texture2D(imageTexture, vec2(uv0.x - 2. * u_dx, uv0.y)).x * w2;
sum += texture2D(imageTexture, vec2(uv0.x - u_dx, uv0.y)).x * w1;
sum += col.x * w0;
sum += texture2D(imageTexture, vec2(uv0.x + u_dx, uv0.y)).x * w1;
sum += texture2D(imageTexture, vec2(uv0.x + 2. * u_dx, uv0.y)).x * w2;
sum += texture2D(imageTexture, vec2(uv0.x + 3. * u_dx, uv0.y)).x * w3;
sum += texture2D(imageTexture, vec2(uv0.x + 4. * u_dx, uv0.y)).x * w4;
sum += texture2D(imageTexture, vec2(uv0.x + 5. * u_dx, uv0.y)).x * w5;
sum += texture2D(imageTexture, vec2(uv0.x + 6. * u_dx, uv0.y)).x * w6;
gl_FragColor = vec4(sum, 0., 0., 1.);
}
);
// Store the progrm, compute uniform locations
ProgramUniforms &pu = (_programs["HorizontalBlur"] = ProgramUniforms());
pu.program = compileShaders(gVertexShaderText, fShaderText);
pu.uniformMap["mvpMatrix"] = glGetUniformLocation(pu.program, "mvpMatrix");
pu.uniformMap["imageTexture"] = glGetUniformLocation(pu.program, "imageTexture");
pu.uniformMap["imageWH"] = glGetUniformLocation(pu.program, "imageWH");
pu.uniformMap["w0"] = glGetUniformLocation(pu.program, "w0");
pu.uniformMap["w1"] = glGetUniformLocation(pu.program, "w1");
pu.uniformMap["w2"] = glGetUniformLocation(pu.program, "w2");
pu.uniformMap["w3"] = glGetUniformLocation(pu.program, "w3");
pu.uniformMap["w4"] = glGetUniformLocation(pu.program, "w4");
pu.uniformMap["w5"] = glGetUniformLocation(pu.program, "w5");
pu.uniformMap["w6"] = glGetUniformLocation(pu.program, "w6");
}
我想你已经注意到我必须为计算提取相邻的纹素。
我担心的是,当当前纹素位于边界时,它的一些邻居肯定会在输入图像之外。
那么,texture2d()
还可以返回有效值吗?
答案 0 :(得分:0)