Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

InRicomWeTrust

Image COlor Effects : B&W, Sepia...

This topic is 5270 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

Hello I''m trying to add cool visual effects to a demo I have to code for my student project; But i am not able to find any information on how I can render my scene and then add a filter (like photoshop but in real time of course ) to render a frame in Sepia (old movie) or Black & White. For the moment I only need ot deal with the coloring part of the code, then i would try to add noize and some extra features for more realism. Can you guys help me with his matter. Any link, source code or information would be greatly appreciated. Thanks in Advance.

Share this post


Link to post
Share on other sites
Advertisement
I will give a look to Nehe tutorial ASAP but fow now I thought it was just a color_matrix change question. Maybe I''m wrong.

In deed I can render the scene to a texture and then change it to sepia (i don''t know how ?!) and redisplay it on a quad correctly centered on screen?

Share this post


Link to post
Share on other sites
I could be wrong but I dont think that there even is such a thing as the color matrix...
However, what I would do if the effects HAD to be dynamic per frame would be to render the scene, call glReadPixels to get the pixels from the framebuffer, then apply your filter (google the algorithms, most like b+w are really simple), then call glTexSubImage2D() to set the new pixel data as a texture, then render a quad that fills up the view frustrum with the texture that you have.

However, that is unnecissarily complicated...(not to mention very slow) What would probably be easier would be for every texture you load to make a version of it that has already had the filter applied to it in the loader code. Then just switch between sets of textures to make it look like you are applying a new effect.

-hope that helps!

--------------------------------------

It took me long enough, but now I am finally 16. Yay! Sorta funny, but I am probably the only person on earth who wrote a 3D driving game prior to actually driving .

Share this post


Link to post
Share on other sites
Ok thanks for your answer. In deed it would be easier to switch the textures but I need to add noize and some white lines (like any old movie no?)

So I will try the first method : rendering to a texture and then apply it on a quad.

Hope I will find how to retrieve the framebuffer data and way to modify the color of the pixel read

Regards,
Yan

Share this post


Link to post
Share on other sites
Those methods will work, but I don't think it would be real-time. If it was it would be too slow because you still have to manipulate every pixel. You can do it using a pixel shader that way it's done in hardware. There's an example here("Image Processing with Pixel Shaders in Direct3D") that does sepia, sobel, etc.

-UltimaX-
|Designing A Screen Shot System|

"You wished for a white christmas... Now go shovel your wishes!"

[edited by - UltimaX on May 9, 2004 5:16:10 PM]

Share this post


Link to post
Share on other sites
UltimaX is right - you won''t be able to pull of render to texture like that and get a framerate greater than perhaps 3-7. You''ll need to write pixel shaders, which, depending on the efect you''re after (such as color->grayscale conversion), shouldn''t be too much of a hassle.




TCP - Transmission by Carrier Pigeons

Share this post


Link to post
Share on other sites
Perhaps the easiest way to manipulate the textures without creating multiple instances of them is to add the effect to the bits when you load the texture:


// Convert From BGR To RGB Format And Add An Alpha Value Of 255

for(long i = 0; i < lWidthPixels * lHeightPixels; i++) // Loop Through All Of The Pixels

{
BYTE* pPixel = (BYTE*)(&pBits[i]); // Grab The Current Pixel

BYTE temp = pPixel[0]; // Store 1st Color In Temp Variable (Blue)

pPixel[0] = pPixel[2]; // Move Red Value To Correct Position (1st)

pPixel[2] = temp; // Move Temp Value To Correct Blue Position (3rd)


// This Will Make Any Black Pixels, Completely Transparent (You Can Hardcode The Value If You Wish)

if ((pPixel[0]==0) && (pPixel[1]==0) && (pPixel[2]==0)) // Is Pixel Completely Black

pPixel[3] = 0; // Set The Alpha Value To 0

else // Otherwise

pPixel[3] = 255; // Set The Alpha Value To 255

}


Then to add the aftereffects just draw them after the scene; make sure you disable the depth buffer.

Good luck,
- llvllatrix

Share this post


Link to post
Share on other sites
I dont think that was an explicit requirement. You can achieve the sepia effect without resorting to post render manipulation.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!