Page 1 of 1
FBO help
Posted: Sun Oct 23, 2011 7:38 am
by pond
hello, would anyone be willing to walk me through how to setup global effects, for example blur or pixelation
i cant seem to get my head around it from reading and the examples
it may not be possible, but this is one i was trying to use:
uniform sampler2D tex;
void main()
{
float dx = 15.*(1./512.);
float dy = 10.*(1./512.);
vec2 coord = vec2(dx*floor(gl_TexCoord[0].x/dx),
dy*floor(gl_TexCoord[0].y/dy));
gl_FragColor = texture2D(tex, coord);
}
i found it here:
http://coding-experiments.blogspot.com/ ... ation.html
or this guassian blur:
http://callumhay.blogspot.com/2010/09/g ... -glsl.html
any advice is welcome, thanks
Posted: Sun Oct 23, 2011 11:13 am
by Kjell
Hi pond,
Textures variables for shaders are automatically named "tex1", "tex2" etc, so change "tex" into "tex1" and it should work fine
In case you're still having difficulties, watch
this tutorial.
K
Posted: Tue Oct 25, 2011 3:30 pm
by VilleK
Kjell wrote:In case you're still having difficulties, watch
this tutorial
Good tutorial Kjell, thanks for making it.
Posted: Mon Nov 07, 2011 2:56 am
by pond
hi kjell, thanks for your help!
ive tried to implement the pixelation shader, but im not sure that ive got it working properly...i attached it
could i ask you a question? is there a way i could set up a gaussian blur effect that is applied on a per model basis? so that i could relate it to a defined "identity" variable in spawnmodel instances
then i could, in a way, simulate focusing on objects
Posted: Mon Nov 07, 2011 12:25 pm
by Kjell
Hi pond,
There's no right and wrong when it comes to shaders .. but when I think of "pixelation" I would go for something like this.
Code: Select all
uniform sampler2D tex1;
uniform float screen_cx; // screen resolution x
uniform float screen_cy; // screen resolution y
const float pixel = 32.0;
void main()
{
float dx = screen_cx / pixel;
float dy = screen_cy / pixel;
float ox = pixel / screen_cx * 0.5;
float oy = pixel / screen_cy * 0.5;
vec2 coord = vec2(floor(gl_TexCoord[0].x * dx) / dx + ox,
floor(gl_TexCoord[0].y * dy) / dy + oy);
gl_FragColor = texture2D(tex1, coord);
}
And, you mean this kind of focus?
The standard way of doing that is using a depth-map, but I guess you could calculate the depth on a per-object base ( instead of per-pixel ) as well if you want. In any case, you need to render the depth data you want to use to a texture, so you can sample that data to control the gaussian amount in your shader.
K
Posted: Mon Nov 07, 2011 1:05 pm
by pond
wow!!!exactly like that. it looks so good
would you show me how to do this? or do you have a zgeproj i could look at? any help is great hehe
edit: i just tried your pixelation shader code and the result is similar to the other one, as in there are lines that trace outward in a grid. im very much a newbie still, so iwasnt sure if it was correct to see this.
thanks i will still make use of this.
Posted: Mon Nov 07, 2011 3:06 pm
by Kjell
Hi pond,
pond wrote:i just tried your pixelation shader code and the result is similar to the other one
Are you sure it compiled correctly ( and added + set the required variables ), otherwise it won't actually update the shader. Attached are what both shaders look like for me.
K
Posted: Tue Nov 08, 2011 12:47 am
by pond
hey kjell, you are right - i had set values for screen_cx and screen_cy, but i was only looking at it in the design window. once i build the exe it looks fine
thanks.