Sign in to follow this  
HellzGod

Fade out - fixed function pipeline

Recommended Posts

HellzGod    122
Hi, I'm trying to create fade in fade out effects. Fade in ( blank screen -> picture ) works. But fade out (picture->blank screen ) doesn't. This is what I have done for fade out:
//initialize fTime = 255;
....

Render()
{
....
fTime -= 0.01f;
p_dx_Device->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
p_dx_Device->SetRenderState( D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA );
p_dx_Device->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );


//SET TEXTURE ALPHA ARGS
p_dx_Device->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
p_dx_Device->SetTextureStageState( 0, D3DTSS_ALPHAARG0, D3DTA_CURRENT );
p_dx_Device->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
p_dx_Device->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );

//SET TEXTURE COLOR ARGS
p_dx_Device->SetTextureStageState( 0,D3DTSS_COLORARG0, D3DTA_CURRENT );
p_dx_Device->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
p_dx_Device->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
p_dx_Device->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );


if ( fTime < 0.0f)
   fTime = 0;
float alpha = fTime;
material.Diffuse.a = alpha;
....
}

I don't get any transparency effect. But when I modify the code for fade in, it works. Is there anything I should change? Thanks, M

Share this post


Link to post
Share on other sites
ET3D    810
Since fade-in works, and it should have the exact same states, just time going in the other direction, I'm not going to look into this.

One thing which doesn't look right is that you don't disable stage 1. You should always disable the stage after the last you use, otherwise a previous setting of states might interfere with the new one.

Okay, I did look at the code, and the alpha stage looks wrong. You're using modulate and supplying three args, which makes me suspect that's not the operation you wanted.

Share this post


Link to post
Share on other sites
Evil Steve    2017
I do this in my engine by rendering a alpha'd quad over the scene. From just before EndScene() in my scene graph:

// If we have an alpha fade, render the fullscreen quad
if(m_dwOverlayColour != 0x00000000)
{
TLVertex v[4];
float w = (float)m_thePresentParams.BackBufferWidth;
float h = (float)m_thePresentParams.BackBufferHeight;
v[0].vPos = D3DXVECTOR4(0.0f, h, 0.0f, 0.5f);
v[0].dwColour = m_dwOverlayColour;
v[1].vPos = D3DXVECTOR4(0.0f, 0.0f, 0.0f, 0.5f);
v[1].dwColour = m_dwOverlayColour;
v[2].vPos = D3DXVECTOR4(w, h, 0.0f, 0.5f);
v[2].dwColour = m_dwOverlayColour;
v[3].vPos = D3DXVECTOR4(w, 0.0f, 0.0f, 0.5f);
v[3].dwColour = m_dwOverlayColour;

// Set states, render, then reset
SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
SetRenderState(D3DRS_LIGHTING, FALSE);
SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
SetStreamSource(NULL, 0);
m_pDevice->SetFVF(FVF_TLVERTEX);
m_pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(TLVertex));
}

(SetRenderState() and SetStreamSource() are member functions of my graphics class that just wrap the device functions)

Share this post


Link to post
Share on other sites
HellzGod    122
Hi,
Thanks for your replies!! I have taken both of your points.
@ ETD3D
I changed that part to:

p_dx_Device->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
p_dx_Device->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
p_dx_Device->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
p_dx_Device->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );


p_dx_Device->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
p_dx_Device->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
p_dx_Device->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
p_dx_Device->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );



STILL fade out doesn't work!! :(

Thanks,
M

Share this post


Link to post
Share on other sites

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