1
Graphics / Re: Basic bloom effect help
« on: May 12, 2012, 08:51:52 pm »
Sorry for the huge delay in replying. I'm definitely using SFML2. I just accidentally removed the ampersand when I was retyping the code .
Anyhow, I managed to get bloom working after spending some time writing one up from scratch and using render textures in the process. Still unsure of what went wrong before but it's working now so I don't really care lol. Thanks for the help nonetheless. If anyone's curious, here are the shaders.
Horizontal shader:
Vertical shader:
And here is what it looks like.
Anyhow, I managed to get bloom working after spending some time writing one up from scratch and using render textures in the process. Still unsure of what went wrong before but it's working now so I don't really care lol. Thanks for the help nonetheless. If anyone's curious, here are the shaders.
Horizontal shader:
Code: [Select]
uniform sampler2D sourceTexture;
uniform float sigma;
uniform float glowMultiplier;
uniform float width;
const int KERNEL_SIZE = 5;
float glow = glowMultiplier / (sigma * sqrt(2.0 * 3.14159));
float blurWeight(float x)
{
return (glow * exp(-(x*x) / (2.0 * sigma * sigma)));
}
void main()
{
vec4 color = vec4(0.0);
vec2 texCoord = gl_TexCoord[0].xy;
for (int i = -KERNEL_SIZE; i <= KERNEL_SIZE; i++)
{
texCoord.x = gl_TexCoord[0].x + (i / width);
color += texture2D(sourceTexture, texCoord) * blurWeight(i);
}
gl_FragColor = color;
}
Vertical shader:
Code: [Select]
uniform sampler2D sourceTexture;
uniform float sigma;
uniform float glowMultiplier;
uniform float height;
const int KERNEL_SIZE = 5;
float glow = glowMultiplier / (sigma * sqrt(2.0 * 3.14159));
float blurWeight(float x)
{
return (glow * exp(-(x*x) / (2.0 * sigma * sigma)));
}
void main()
{
vec4 color = vec4(0.0);
vec2 texCoord = gl_TexCoord[0].xy;
for (int i = -KERNEL_SIZE; i <= KERNEL_SIZE; i++)
{
texCoord.y = gl_TexCoord[0].y + (i / height);
color += texture2D(sourceTexture, texCoord) * blurWeight(i);
}
gl_FragColor = color;
}
And here is what it looks like.