Sign in to follow this  

Post processing effects?

This topic is 3478 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all! So I would like to be able to manipulate pixels after rendering. I'm not sure if this is called post-processing or what. Basically I would like to able to do things like swap the R and G values of all pixels, convert the screen to gray scale, lighten all pixels by a certain amount, etc. I did find this thread: http://www.gamedev.net/community/forums/topic.asp?topic_id=440479&whichpage=1 Where it is suggested to use frame buffer objects. I found the tutorials on here: http://flashbang.se/postbreak.php?id=18 On how to set up a framebuffer object, now if I could only figure out how to use them to do what I want....(say, adding 10 to all red pixel values capping at 255 of course) If anyone could help, that would be awesome! :) Thanks!

Share this post


Link to post
Share on other sites
Quote:
Original post by kerryhall
Hey all!

So I would like to be able to manipulate pixels after rendering. I'm not sure if this is called post-processing or what. Basically I would like to able to do things like swap the R and G values of all pixels, convert the screen to gray scale, lighten all pixels by a certain amount, etc.

I did find this thread:
http://www.gamedev.net/community/forums/topic.asp?topic_id=440479&whichpage=1
Where it is suggested to use frame buffer objects. I found the tutorials on here:
http://flashbang.se/postbreak.php?id=18
On how to set up a framebuffer object, now if I could only figure out how to use them to do what I want....(say, adding 10 to all red pixel values capping at 255 of course)

If anyone could help, that would be awesome! :)

Thanks!


That's very easy using shaders.
I recommend you to use GLEW to be able accesing shader extensions on OpenGL.
After that, write a trivial vertex shader (you are not going to change vertex)
void main(void)
{
gl_FrontColor = gl_Color;
gl_Position = ftransform();
}

For instance, this is a fragment shader to swap the R and G values (maybe there are syntax mistakes)

void main()
{
vec3 color=gl_Color;
gl_FragColor = vec3(color.g,color.r,color.b);
}

Share this post


Link to post
Share on other sites
Hmmmm, let's say that I would like to do something like only render even numbered pixel rows, while odd numbered pixel rows are black.

Or let's say I want to render just within a triangle or pentagon area on the screen, the rest of the screen black.

Or lets say I want to render my scene, but then draw a 10 pixel wide green border around the screen.

Would I use a fragment program?

Thanks to everyone!

Share this post


Link to post
Share on other sites
Thank you! I'm not sure how to use the stencil buffer in this way though.

Could someone show me some quick code to use the stencil buffer to draw to a non-rectangular region of the screen? Thank you!



Share this post


Link to post
Share on other sites
Also, does anyone know how to initialize the stencil buffer with SDL? All the examples I have found use glut.

Thanks!


Edit:
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,1);
was the initialization code I was looking for. I have also found this code example from the red book to render to a non-rectangular region:
http://www.opengl.org/resources/code/samples/redbook/stencil.c

However, if I could find a fast way to modify pixel values directly, that would be great!



[Edited by - kerryhall on May 19, 2008 5:53:53 PM]

Share this post


Link to post
Share on other sites
Hey all! Thanks for all your help so far. I have successfully figured out how to render to non rectangular regions of the screen.

However, I still have one question:

How can I render to a certain region of the screen, but render in red pixels only? Or render at half brightness only? (all pixel values are halved)

Would I use a pixel shader for this? Anyone have an idea? Thanks!

Kerry

Share this post


Link to post
Share on other sites
Not sure if shaders will bypass this (most likely not):
http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/colormask.html






Since you cant manually touch the color buffer, you need a copy of it:

1.)Draw your scene into a texture (FBO, PBO, etc).
or
2.)Use glCopyTexImage2D() and copy the color buffer to a texture. Then just draw a fullscreen quad with a shader:

gl_FragColor = pixel.rbga;
or
float average = (pixel.r + pixel.g + pixel.b)/3;
gl_FragColor = average; //grayscale

Share this post


Link to post
Share on other sites
Thanks dpadam450!

I will give that a try. I was going to ask how to draw a full screen quad, but I found this:
http://www.opengl.org/resources/faq/technical/transformations.htm#tran0090

Share this post


Link to post
Share on other sites

This topic is 3478 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this