SFML community forums
Help => Graphics => Topic started by: ptrxyz on June 23, 2009, 11:37:36 am
-
I tried to make a new blur effect. Well, first, here is my code:
texture framebuffer
effect
{
float x = _in.x;
float y = _in.y;
float zx = 1.0 / 640.0;
float zy = 1.0 / 480.0;
vec4 p1 = framebuffer(vec2(_in.x, _in.y));
vec4 p2 = framebuffer(vec2(_in.x + zx, _in.y + zy));
vec4 p3 = framebuffer(vec2(_in.x - zx, _in.y + zy));
vec4 p4 = framebuffer(vec2(_in.x + zx, _in.y - zy));
vec4 p5 = framebuffer(vec2(_in.x - zx, _in.y - zy));
_out = (p1 + p2 + p3 + p4 + p5) * 0.2;
}
What I do is basically just get the vec4s of the colors that are a bit right, left, above or below the current pixel and just sum them up and multiply them by a factor to keep the brightness.
But the problem is: This example only works for me as long as I replace the last line ( _out = (p1 + p2 + p3 + p4 + p5) * f;) by this line:
_out = (p1 + p2 + p3) * f;
As you can see I can not sum up all 5 vectors...It keeps crashing. As soon as I add more then 3 (no matter which ones I add, it just have to be less then 4) the effect simply doesn't show and the App.Window doesnt update anymore (oh and CPU usage goes up to 100%). If i just ad 3 vectors: everything works fine... Does anyone know what I am doing wrong?
EDIT: Strange enough, but this works too:
_out = p1 + p1 + p1 + p1 + p2 + p2 + p2;
So, the error occures as soon as I want to sum up more then 3 different vectors. A work around like
vec4 dummy = p1 + p2 + p3;
_out = dummy + p4 + p5;
doesnt work, too...
Another EDIT:
I thoguht it might be a memory problem with the GLSL compiler or something so i tried this code:
texture framebuffer
effect
{
float x = _in.x;
float y = _in.y;
float zx = 1.0 / 640.0;
float zy = 1.0 / 480.0;
vec4 val;
vec4 p1 = framebuffer(vec2(_in.x, _in.y));
val = framebuffer(vec2(_in.x + zx, _in.y + zy));
p1 = p1 + val;
val = framebuffer(vec2(_in.x - zx, _in.y + zy));
p1 = p1 + val;
val = framebuffer(vec2(_in.x + zx, _in.y - zy));
p1 = p1 + val;
val = framebuffer(vec2(_in.x - zx, _in.y - zy));
p1 = p1 + val;
float f = 0.2;
_out = p1 * f;
}
Problem remains: As soon as i sum up more then 3 different pixels i get a crash. If i just add 3 or less all is fine....
-
Shaders have a limit in the number of instructions. Maybe you can find a tool that gives you more informations for this.
-
Hm....what kind of tool do you mean? Could you give me a hint about what to google for? I have to admit that i am not that deep into shaders, so i really dont have a clue about what hitword could match my needs.
-
You can try "GLSL" and "instruction count". I can't help more, sorry, I've never done this for GLSL.
-
Ah thanks! I found out that my notebook's GFX chip only supports 22 instructions. I guess that might be the problem.
For those who ever might have the same problem:
I worked around the problem by applying 2 effects then. One blurring horizontally, another one blurring vertically. Halfes the performance, but it's still ok for my purposes.
Topic can be closed.