Sign in to follow this  

Grayscale Transitions (not what you think)

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

Hi, I saw mentioned in some posts that people use grayscale images to create transition-effects. They just use this grayscale images and load them into the same code all the time. In dependency on the loaded picture the transition effect between two images differs. Can anybody point me to some more detailed information on the matter or explain this to me? Thanks in advance.

Share this post


Link to post
Share on other sites
If you're talking about the sort of effect where you fade from one image to another, but each pixel at slightly different times, then yeah.

Basically, you have four buffers, SRC1, SRC2, BLEND, and DEST. For a normal blend, fading from SRC1 to SRC2, you do something like this:
for (i=0 to 255)
{
for (pix=0 to NUMPIXELS)
{
DEST[pix] = SRC1[pix] * (256-i) / 256 + SRC2[pix] * i / 256;
}
}


For a transition such as you describe, you go more like:
for (i=-255 to 255)
{
for (pix=0 to NUMPIXELS)
{
blend = Clamp(BLEND[pix]+i, 0, 255);
DEST[pix] = SRC1[pix] * blend / 256 + SRC2[pix] * blend / 256;
}
}


For additional coolness points, have your BLEND picture animate... it looks way cool. :)

Share this post


Link to post
Share on other sites
Quote:
Original post by MannyCalavera
Hi,

I saw mentioned in some posts that people use grayscale images to create transition-effects. They just use this grayscale images and load them into the same code all the time. In dependency on the loaded picture the transition effect between two images differs.

Can anybody point me to some more detailed information on the matter or explain this to me?

Thanks in advance.


Could you be more specific please?!

- Direct3D?, DirectDraw?, DirectX Transform?

- What types of transition: fades?, wipes?, ??

If you're talking about DirectDraw and effects such as cross-fading, then Lock() the relevent surfaces and use methods such as the one fractoid mentions.

If you're talking about Direct3D and effects such as cross-fading, then take a look at alpha blending.

If you're talking about Direct3D and effects such as wipes, look in the DirectX SDK docs under:
DirectX Graphics ->
Programming Guide ->
Advanced Topics ->
Pixel Pipeline ->
Stencil Buffer Techniques ->
Dissolves, Fades, and Swipes


If you give us more details of what you want to achieve and which API you're using, then we'll be able to go into more detail and perhaps post some links to tutorials etc.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hi, thanks for the answers so far.

I'm talking about Direct3D and want to use fades and wipes depending on a grayscale-image (so then fractoids method isn't for me, thanks anyway buddy :) ). The brightness of parts in the image shall define the speed in which the transition is executed. (So I could make an image which is darker at the top and in the program the transition would be already over on the top when the bottom is still painting.)

So depending on the used image the transition can be very complex.

The stencil buffer sounded as if it would be the thing to use but do I understand it right that it can't use alphablending at the same time?

Any links to further reading or tips will be very appreciated.

Thanks in advance

Share this post


Link to post
Share on other sites
I think Fractoid's method could be what you'd want. What he describes would have the effect you mentioned, operated on a texture or surface.
You could either blend together two render targets onto the back buffer, or draw a full-screen pair of triangles and either lock a texture and twiddle its bits, or use a Pixelshader. The pixelshader method would obviously be faster, but limits the cards the effect will run on. (Off hand I think you'd only be able to do it with Shaders > v2.0?)
The best solution would be to code both and fall back on one of the locking effects on older cards. There are two catches. One being that redrawing the back buffer or a hi-res texture in software can be sluggish (around 10 fps in my experience) and the other being that you may want to use a low-res texture for the effect, obviously reducing the resolution of your scene. Even Doom 3 looks like it uses low-res textures for some of its full-screen effects (Berserk?), though, so that should be considered reasonable.

Share this post


Link to post
Share on other sites
Hi, thanks for the reply.

I want to realize the way it would work on all cards first, so that would be the locking of rendertargets to change their pixels. But I want to do this with pictures the user chooses (e.g. photos with high resolution and so) so this would be terribly slow I presume.

But what about the other way you proposed?

Quote:

[..]blend together two render targets onto the back buffer[..]


What exactly do you mean by this? With Renderstates (Blending them...) I can't be exact enough I always thought since I want to make the transition between 2 pictures depending on the grayscale picture.

Thanks in advance.

Share this post


Link to post
Share on other sites
You can do it yourself without pixel shaders using texture multiplication. Basically you have the transition, start, and end images in video memory, and then render (start*(transition + offset)) and then add (end * (1.0 - (transition + offset))) over the top. I'm fairly sure you can munge the fixed function lighting system to do that.

Share this post


Link to post
Share on other sites
Well, thanks for the tip. But I must admit I'm not entirely sure how to achieve this. I don't use lighting so far, is it mandatory to achive such a result?

And you talk about blendstates here don't you? Just to be sure I steer in the right direction when I try some of this. ;)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Manny Calavera... doh i remember now, it's Grim Fandango ! Man, that game rocked !

Share this post


Link to post
Share on other sites

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