Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - verilax

Pages: [1]
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  :P.

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.

2
Graphics / Basic bloom effect help
« on: May 06, 2012, 09:06:35 pm »
Hi, I'm trying to implement a bloom effect using shaders on sfml2 but unfortunately, I'm a complete newbie to GLSL and I'm having a lot of trouble figuring out why it's not working at all. I tried to use the shaders posted here by another user and passed in the variables the horizontal and vertical blur shaders required but all that resulted is my sprite becoming invisible. I tried just applying only the horizontal blur and passed in this with the same result (sprite disappears).
    blurH.SetParameter("fadedelta", 0.5f);
    blurH.SetParameter("img", sf::Shader::CurrentTexture);
    blurH.SetParameter("width", 1600.0f);
    blurH.SetParameter("g", 1.5f);
    renderWindow.Draw(outline, blurH);
 

I don't see any GLSL errors in the console so I have no clue what I'm doing wrong. I've been stuck for several days now and it's just so frustrating because I feel like I can't move on to other parts of my game until I can get this working. Would someone be able to share a bit of insight on implementing this or perhaps some working example code?

Pages: [1]
anything