FBO help

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
pond
Posts: 25
Joined: Mon Jul 11, 2011 5:54 am

FBO help

Post 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 :oops:

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
User avatar
Kjell
Posts: 1924
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
User avatar
VilleK
Site Admin
Posts: 2371
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

Kjell wrote:In case you're still having difficulties, watch this tutorial
Good tutorial Kjell, thanks for making it.
pond
Posts: 25
Joined: Mon Jul 11, 2011 5:54 am

Post 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
Attachments
fbo test.zgeproj
(1.45 KiB) Downloaded 581 times
User avatar
Kjell
Posts: 1924
Joined: Sat Feb 23, 2008 11:15 pm

Post 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?

Image

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
Last edited by Kjell on Mon Nov 07, 2011 1:05 pm, edited 1 time in total.
pond
Posts: 25
Joined: Mon Jul 11, 2011 5:54 am

Post 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.
User avatar
Kjell
Posts: 1924
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
Attachments
pond.png
pond.png (11.79 KiB) Viewed 10923 times
Kjell.png
Kjell.png (7.39 KiB) Viewed 10923 times
pond
Posts: 25
Joined: Mon Jul 11, 2011 5:54 am

Post 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.
Post Reply