• Advertisement

Archived

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

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

This topic is 5030 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
Rendering to texture is not that slow. I had no problem doing it twice per frame with 512x512 texture, and with quite expensive shaders. The point it that you keep texture on GPU (don''t read it back to CPU) and then draw it like fullscreen quad. Effects as grayscale or colorization are trivial to implement on even GF1. If you are targeting higher (GF-FX/R9xxx) then possibilitys are endless. In any case no need to use CPU for anything.

You should never let your fears become the boundaries of your dreams.

Share this post


Link to post
Share on other sites
I may be completely wrong here, but wouldn't it be possible to use grey scale/sepia toned textures and vertex colors and avoid using colored lights? No shaders, no render to textures. KISS.
If you have to turn the effect on/off then it might get too expensive though (multiple textures and VBs)

EDIT: doh.. Didn't catch the part about "render my scene and then add a filter"..

[edited by - frostburn on May 11, 2004 2:20:27 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by _DarkWIng_
Rendering to texture is not that slow. I had no problem doing it twice per frame with 512x512 texture, and with quite expensive shaders. The point it that you keep texture on GPU (don''t read it back to CPU) and then draw it like fullscreen quad. Effects as grayscale or colorization are trivial to implement on even GF1. If you are targeting higher (GF-FX/R9xxx) then possibilitys are endless. In any case no need to use CPU for anything.

You should never let your fears become the boundaries of your dreams.


This would require (to me at least) higher class hardware (GF3/4 and up) and is therefore not an option. But yes, readin the texture into RAM for editing won''t cut it. Real men do it in GDI anyway...


Matrix: what you suggested is hardly considered real-time.

Share this post


Link to post
Share on other sites
quote:
Original post by Crispy
This would require (to me at least) higher class hardware (GF3/4 and up) and is therefore not an option.

What would require GF3? Turning color into grayscale is just one dot product. Colorization is a dot product and multiplication (this sometimes looks fake) or 3 dot products (can be much better). If you want to go for something really fancy you need FP (to convert to HSV/HSL color space and back)


You should never let your fears become the boundaries of your dreams.

[edited by - _DarkWIng_ on May 11, 2004 11:26:46 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by _DarkWIng_
What would require GF3? Turning color into grayscale is just one dot product. Colorization is a dot product and multiplication (this sometimes looks fake) or 3 dot products (can be much better). If you want to go for something really fancy you need FP (to convert to HSV/HSL color space and back)



I''m sorry I''m a bit ignorant in this area - how exactly would you do this without pixel shaders or something equivalent (either in VRAM or on the frame buffer)? AFAIK GF3 is the first card to have pixel shaders, am I not right?

PS - true greyscale has got nothing to do with dot products.

Share this post


Link to post
Share on other sites
True greyscale can't be done even on GF3/4 (I think). But you can fake it on GF1 with abuse of dot product (grey = R*Rf+G*Gf+B*Bf).

You should never let your fears become the boundaries of your dreams.

[edited by - _DarkWIng_ on May 12, 2004 4:10:51 AM]

Share this post


Link to post
Share on other sites

  • Advertisement