出于某种原因,每次我做模糊时结果都是这样,我真的很困惑为什么会这样。同样对于绽放,模糊都是像素化的,并且每次我做模糊时都会发生这种情况。我真的不知道问题是什么。
这是您需要的方差阴影贴图模糊的所有代码。
GaussianBlur垂直片段着色器..
#version 330 core
out vec4 FragColor; //fragment shader output
in vec2 _texcoord; //input interpolated texture coordinate
uniform sampler2D textureMap; //the input image to blur
//constant kernel values for Gaussian smoothing
const float kernel[]=float[21] (0.000272337, 0.00089296, 0.002583865, 0.00659813, 0.014869116,
0.029570767, 0.051898313, 0.080381679, 0.109868729, 0.132526984,
0.14107424, 0.132526984, 0.109868729, 0.080381679, 0.051898313,
0.029570767, 0.014869116, 0.00659813, 0.002583865, 0.00089296, 0.000272337);
void main()
{
//get the inverse of texture size
vec2 delta = 1.0 / textureSize(textureMap,0);
vec4 color = vec4(0);
int index = 20;
//go through all neighbors and multiply the kernel value with the obtained
//colour from the input image
for(int i =- 10; i <= 10; i++) {
color += kernel[index--] * texture(textureMap, _texcoord + (vec2(0, i * delta.y)));
}
//return the filtered colour as fragment output
FragColor = vec4(color.xy,0,0);
}
GuassianBlur水平片段着色器..
#version 330 core
out vec4 FragColor; //fragment shader output
in vec2 _texcoord; //input interpolated texture coordinate
//uniform
uniform sampler2D textureMap; //the input image to blur
//constant kernel values for Gaussian smoothing
const float kernel[]=float[21] (0.000272337, 0.00089296, 0.002583865, 0.00659813, 0.014869116,
0.029570767, 0.051898313, 0.080381679, 0.109868729, 0.132526984,
0.14107424, 0.132526984, 0.109868729, 0.080381679, 0.051898313,
0.029570767, 0.014869116, 0.00659813, 0.002583865, 0.00089296, 0.000272337);
void main()
{
//get the inverse of texture size
vec2 delta = 1.0 / textureSize(textureMap, 0);
vec4 color = vec4(0);
int index = 20;
//go through all neighbors and multiply the kernel value with the obtained
//colour from the input image
for(int i =- 10; i <= 10; i++) {
color += kernel[index--] * texture(textureMap, _texcoord + (vec2(i * delta.x, 0)));
}
//return the filtered colour as fragment output
FragColor = vec4(color.xy, 0, 0);
}
模糊阶段..
glBindFramebuffer(GL_FRAMEBUFFER, _filteredshadowmap_fbo);
glUseProgram(_program_blurH);
glUniform1i(_u_texture_map_h, 0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _shadowmap);
renderQuad();
glUseProgram(_program_blurV);
glUniform1i(_u_texture_map_v, 0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _shadowmap);
renderQuad();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
初始化模糊 fbo..
// shadowmap blurring
glGenFramebuffers(1, &_filteredshadowmap_fbo);
glBindFramebuffer(GL_FRAMEBUFFER, _filteredshadowmap_fbo);
glGenTextures(1, &_filtered_shadowmap);
glBindTexture(GL_TEXTURE_2D, _filtered_shadowmap);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, SHADOW_QUALITY, SHADOW_QUALITY, 0, GL_RGBA, GL_FLOAT, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _filtered_shadowmap, 0);
GLenum status2 = glCheckFramebufferStatus(GL_FRAMEBUFFER);
status2 != GL_FRAMEBUFFER_COMPLETE ? std::cerr << "Unable to create FBO" << std::endl : std::cout << "FBOs Were successful" << std::endl;
glBindFramebuffer(GL_FRAMEBUFFER, 0);