由于某种原因,bloom显示为黄色,我不能完全确定为什么bloom是黄色,这不是一个混合问题,并且代码似乎正确。
我已经研究了这个问题,知道一个人似乎也遇到了同样的问题,我想这可能与fbo纹理过滤有关,但我不确定。我需要一些帮助。
这是代码。
最终收集代码
#version 330 core
out vec4 FragColor;
in vec2 _texcoord;
in float color;
uniform sampler2D scene;
uniform sampler2D bloom;
uniform float bloom_intensity;
void main()
{
const float gamma = 1.3;
float exposure = 1.0;
vec3 hdrColor = texture(scene, _texcoord).rgb;
vec3 bloomColor = texture(bloom, _texcoord).rgb;
hdrColor += bloomColor; /// bloom_intensity;
// tone mapping
vec3 result = vec3(1.0) - exp(-hdrColor * exposure);
// also gamma correct while we're at it
result = pow(result, vec3(1.0 / gamma));
FragColor = vec4(result, 1.0);
}
光片段着色器中的花朵
// final lighting calculations
vec3 result = calc_directional_light(Diffuse, Specular, Metalness, AO);
for (int i = 0; i < 5; i++)
{
result += calc_point_light(pointLights[i], Diffuse, Specular);
result += calc_spot_light(spotLights[i], Diffuse, Specular);
}
float brightness = dot(result, vec3(0.2126, 0.7152, 0.0722));
if(brightness > 0.7)
BrightColor = vec4(result, 1.0);
else
BrightColor = vec4(0.0, 0.0, 0.0, 1.0);
FragColor = vec4(result, 1.0);
开花设置
inline void Create(std::vector<GLuint> shader_programs, size_t width, size_t height, float intensity)
{
_shader_programs = shader_programs;
_intensity = intensity;
_fbo = new Fbo(width, height, { new FboAttachment(width, height, GL_RGB16F, GL_RGB, GL_FLOAT, GL_COLOR_ATTACHMENT0),
new FboAttachment(width, height, GL_RGB16F, GL_RGB, GL_FLOAT, GL_COLOR_ATTACHMENT1) }, true);
_h_blur = new Fbo(width, height, { new FboAttachment(width, height, GL_RGB16F, GL_RGB, GL_FLOAT, GL_COLOR_ATTACHMENT0) }, false);
_v_blur = new Fbo(width, height, { new FboAttachment(width, height, GL_RGB16F, GL_RGB, GL_FLOAT, GL_COLOR_ATTACHMENT0) }, false);
_u_texturemap[0] = glGetUniformLocation(_shader_programs[0], "textureMap");
_u_texturemap[1] = glGetUniformLocation(_shader_programs[1], "textureMap");
_u_blurres[0] = glGetUniformLocation(_shader_programs[0], "blur_resolution");
_u_blurres[1] = glGetUniformLocation(_shader_programs[0], "blur_resolution");
}
花朵渲染
inline virtual void Render()
{
_h_blur->Bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(_shader_programs[0]);
glUniform1i(_u_texturemap[0], 0);
glUniform1f(_u_blurres[0], 128.0f);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _fbo->GetAttachments()[1]->_texture);
_screen_rect->Render(1);
_h_blur->Unbind();
_v_blur->Bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(_shader_programs[1]);
glUniform1i(_u_texturemap[1], 0);
glUniform1f(_u_blurres[1], 128.0f);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _h_blur->GetAttachments()[0]->_texture);
_screen_rect->Render(1);
_v_blur->Unbind();
}