I am trying to implement bloom from the learnopengl guest article on physically based bloom. However I wanted to try do this with a compute shader and using the mip levels instead of producing several different textures for each mip.
My bloom:
As you can see its producing weird lines accross the image and the bright textures aren’t really bleeding the pixels out as normal bloom would.
I am not sure what I am doing wrong as I am using the same down/up sampling technique and the same kernel.
In the bloom shader:
void main()
{
ivec2 coordinate = ivec2(gl_GlobalInvocationID);
vec3 destinationColor = vec3(0.0, 1.0, 1.0);
vec2 texCoord = (vec2(coordinate) + vec2(0.5)) / imageSize(u_Destination);
if(u_SampleOption == BLOOM_DOWN_SAMPLE)
destinationColor = DownSample(texCoord);
else if (u_SampleOption == BLOOM_UP_SAMPLE)
{
destinationColor = UpSample(texCoord);
destinationColor += textureLod(u_Source, texCoord, float(u_SourceMip)).rgb;
}
imageStore(u_Destination, coordinate, vec4(destinationColor, 1.0));
}
In the host code:
m_Data.BloomPass.Use();
uint32_t width = m_Settings.ViewportWidth;
uint32_t height = m_Settings.ViewportHeight;
constexpr int DownSample = 0;
constexpr int UpSample = 1;
//
// ---- down sampling ----
for (uint32_t i = 1; i < RenderData::BloomMipLevelCount; i++)
{
uint32_t source = i - 1;
uint32_t destination = i;
uint32_t sourceWidth = width >> source;
uint32_t sourceHeight = height >> source;
uint32_t destinationWidth = width >> destination;
uint32_t destinationHeight = height >> destination;
float groupX = std::ceil((float)destinationWidth / 8.0f);
float groupY = std::ceil((float)destinationHeight / 8.0f);
m_Data.BloomPass.SetUniform("u_SampleOption", DownSample);
m_Data.BloomPass.SetUniform("u_SourceMip", (int)source);
m_Data.BloomPass.SetUniform("u_Source", 0);
m_Data.BloomPass.SetUniform("u_Destination", 1);
m_Data.FinalImageTexture->Bind(0);
m_Data.FinalImageTexture->BindImage(1, destination, 0, false);
glDispatchCompute((GLuint)groupX, (GLuint)groupY, 1);
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
}
//
// ---- up sampling ----
m_Data.BloomPass.Use();
for (uint32_t i = RenderData::BloomMipLevelCount - 1; i > 0; i--)
{
uint32_t source = i;
uint32_t destination = i - 1;
uint32_t sourceWidth = width >> source;
uint32_t sourceHeight = height >> source;
uint32_t destinationWidth = width >> destination;
uint32_t destinationHeight = height >> destination;
float groupX = std::ceil((float)destinationWidth / 8.0f);
float groupY = std::ceil((float)destinationHeight / 8.0f);
m_Data.BloomPass.SetUniform("u_SampleOption", UpSample);
m_Data.BloomPass.SetUniform("u_SourceMip", (int)source);
m_Data.BloomPass.SetUniform("u_Source", 0);
m_Data.BloomPass.SetUniform("u_Destination", 1);
m_Data.FinalImageTexture->Bind(0);
m_Data.FinalImageTexture->BindImage(1, destination, 0, false);
glDispatchCompute((GLuint)groupX, (GLuint)groupY, 1);
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
}
if anyone could guide me to any other sources of error that would be greatly apprecited. If need i can provide more code.