SFML community forums
Help => Graphics => Topic started by: heishe on June 26, 2011, 09:37:57 pm
-
Hey, I have this shader in my program:
uniform sampler2D texture;
uniform vec2 target_size;
uniform float scale;
vec4 bloom(vec4 original)
{
return original*scale;
}
void main()
{
vec4 color = texture2D(texture,gl_TexCoord[0].xy);
vec2 step = scale/target_size;
//right and left
color *= texture2D(texture,gl_TexCoord[0].xy + vec2(step.x,0.0));
color *= texture2D(texture,gl_TexCoord[0].xy + vec2(-step.x,0.0));
//up and down
color *= texture2D(texture,gl_TexCoord[0].xy + vec2(0.0,step.y));
color *= texture2D(texture,gl_TexCoord[0].xy + vec2(0.0,-step.y));
gl_FragColor = bloom(color);
}
It's a simple blur+bloom shader (I think it's gaussian blur, although I'm not sure about the terminology), which blurs the image according to a factor (bigger factor = bigger blur) and blooms it, also depending on the factor.
This shader runs on my really crappy old laptop, with Intel Integrated Graphics set (which uses software 2D rendering), but not on the PCs of two other people who tested the application. Both have ATI graphics cards (one of them has got a HD 5770, the other one a pretty new mobile graphics card).
A more simple shader, like this:
void main()
{
gl_FragColor = vec4(0.0,1.0,0.0,1.0);
}
however, works perfectly fine with them and simply draws a green rectangle to every sprite that it is applied to.
What could this be? Could it be that "newer" graphics cards( HD 5770 isn't exactly new though, afaik OpenGL 3.0 ? ) don't support gl_TexCoord etc. anymore?
-
I'm no expert, but I think you need to define the version you are using.
Put this "#version 120" above the shader code.
I got it from here: http://en.wikipedia.org/wiki/GLSL
-
If I put that at the top of the shader it fails to compile the shader, telling me that this version is not supported by GL2.
Putting "#version 110" compiles, but it doesn't fix the problem on the other machines (shader still doesn't show anything).
-
The code don't work.
Do you send the variable to the GLSL code ?
Because some aren't initialized if you use this code like this
-
of course I do. Otherwise it wouldn't work no my laptop, either. Target size is simply the size of the sprite (width/height), scale is just a factor that I send to the shader every frame, and the texture is the image of the sprite itself.
-
This shader runs on my really crappy old laptop, with Intel Integrated Graphics set (which uses software 2D rendering), but not on the PCs of two other people who tested the application. Both have ATI graphics cards (one of them has got a HD 5770, the other one a pretty new mobile graphics card).
This is just a hunch, but what version of SFML are you using?
-
The 2.0 version as of about a week ago. I already thought about the ATI bug, but that (to my knowledge) has been fixed a long time ago.
-
The 2.0 version as of about a week ago. I already thought about the ATI bug, but that (to my knowledge) has been fixed a long time ago.
It was fixed, so hrm. Maybe have them make sure their drivers are updated?
-
They certainly are. I also doubt that this is a driver problem.
Has anyone here tried the shader? It's not that hard to test. Just draw a sprite using this shader, and set the values of the variable to whatever you want them to be.
-
They certainly are. I also doubt that this is a driver problem.
Has anyone here tried the shader? It's not that hard to test. Just draw a sprite using this shader, and set the values of the variable to whatever you want them to be.
give us the C++ code, the GLSL code can't work like this.
-
Alright, here's a basic example of how to use the shader code:
#include <sfml/graphics.hpp>
#include <sfml/window.hpp>
int main()
{
sf::RenderWindow window;
window.Create(sf::VideoMode(800,600,32),"test");
sf::Image i; i.LoadFromFile("load your favourite bitmap here");
sf::Sprite spr(i,sf::Vector2f(300,300));
sf::Shader bloomblur;
bloomblur.LoadFromFile("put the shader in a text file and put it here");
bloomblur.SetTexture("texture", *spr.GetImage());
bloomblur.SetParameter("target_size",spr.GetSize());
bloomblur.SetParameter("scale", 3.0f);
bool running = true;
while(running)
{
sf::Event e;
while(sf::PollEvent(e)
{
if(e.Type == sf::Event::KeyPressed)
running =false;
}
window.Clear(sf::Color::Green);
window.Draw(spr,bloomblur);
window.Display();
}
return 0;
}
I've hacked this into the browser, so it may not work initially, however, since all of you know how to set up a basic application you should be able to fix it quickly.
It should work though.