Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Is it possible to set an alpha value globally in Direct3D 9, which modulates the pixel alpha values of every subsequent draw?

I would like to let a whole scene fade in/out. I know that for example ID3DXSprite::Draw() lets you set this in the Color parameter, but I'm using pixel shaders to draw 2D circles and rectangles as well, so I would have to pass the alpha value to each of them.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

With shaders and ordinary alpha blending I don't think this is possible. If you wanted to replace all the alpha values in the scene by a global constant, you could use D3DBLEND_BLENDFACTOR and D3DBLEND_INVBLENDFACTOR. But it sounds to me like you want to multiply each pixel's alpha value by a global constant. This is best done in the pixel shader.

That being said, fading out the alpha of every scene element may not be what you actually want to do. It will produce a strange effect as opaque objects will become transparent during the fade. For instance, an object hidden behind a wall will be briefly visible during the fade, as the wall and the object are both partly transparent.

If you want to fade to a constant color (black, white, etc.), a better approach may be to just render a full-screen pass of that color over the entire scene, rather than altering the alpha values of anything in the scene. If you want to fade to a different scene (like a dissolve) then the second scene should be drawn into an offscreen render target, then drawn on a full-screen pass over the first scene.

share|improve this answer
    
Yes, I want to multiply each pixel's alpha value to retain the "relative" transparency of objects (because some objects might already be transparent in the beginning, so they should be even more transparent when fading off. Nevertheless, I do see now that this is only suitable for some kind of on-screen GUI for example. Fading between two scenes should be done as you described, good point! –  ph4nt0m Jul 26 '13 at 18:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.