• Advertisement
Sign in to follow this  

problem with dx8 offscreen rendering

This topic is 3309 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 work wich DirextX 8.1. I need render into texture ( render target ). If i render to RT two sprites wich alpha channel then i have very badly picture after render RT to screen: screen1 If i disable alpha blend: g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE ); before render RT to screen, then all showed correct. But i need render this sprite with textrure from RT with transparent from 0 to 255. thus and so i can`t disable alphablend :-(. The transparent for sprites i make through color in vertex. The vertex format is:
struct Vertex
{
    float x, y, z;
	DWORD col;
    float tu, tv;

	enum FVF
	{
		FVF_Flags = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1
	};
};




the render order is: 1.1 render 'wood' texture intro RT 1.2 render white-transparent texture intro RT 2. render scene 2.1 render white-black quad textrure 2.2 render RT textrure 2.3 goto 2 [Edited by - progman_rus on December 26, 2008 4:27:28 AM]

Share this post


Link to post
Share on other sites
Advertisement
When you change render targets, all the device state is still in effect. You're probably assuming that by switching render targets you get the default state, but you don't. So when you switch render targets, make sure you set all the state as you need for that render target.

Share this post


Link to post
Share on other sites
Quote:
Original post by legalize
When you change render targets, all the device state is still in effect. You're probably assuming that by switching render targets you get the default state, but you don't. So when you switch render targets, make sure you set all the state as you need for that render target.


I set render states each time before BeginScene/EndScene. And I render into render only one time and only with starting application.

Share this post


Link to post
Share on other sites
this is my defaults states:
g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_ALPHAREF, 0x01 );
g_pd3dDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL );

g_pd3dDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD );
g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );

Share this post


Link to post
Share on other sites
and this states I made before render each sprites:

g_pd3dDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD );
g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );

Share this post


Link to post
Share on other sites
the problem is not decided :-(
I found new error:
picture1:
I render the sprite to rendertarget and after render rendertarget to screen.
picture1

picture2:
I render the sprite to screen. No render to render terget.
picture2

the render states is:
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE );

the sprite transparents is not equal. :-(
but why?

Share this post


Link to post
Share on other sites

void render( void )
{

// BEGIN RENDER TO RENDER TARGET
m_pRenderToSurface->BeginScene( m_pTextureSurface, NULL );
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,0.0f), 1.0f, 0);

g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &g_matProjection_offscreenSurface );

D3DXMatrixTranslation( &matTranslation, 0.0f, 0.0f, 5.0f );
D3DXMatrixRotationYawPitchRoll( &matRotation, D3DXToRadian(g_fSpinX_R), D3DXToRadian(g_fSpinY_R), 0.0f );

matWorld = matRotation * matTranslation;
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
g_pd3dDevice->SetStreamSource( 0, g_pVertexBuffer, 0, sizeof(Vertex) );
g_pd3dDevice->SetFVF( Vertex::FVF_Flags );

g_pd3dDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD );
g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );

g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TEXTURE );

g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE );

g_pd3dDevice->SetTexture( 0, g_pTestTexture2 );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 4, 2 );
m_pRenderToSurface->EndScene( 0 );

// BEGIN RENDER TO SCREEN

g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f), 1.0f, 0 );

g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &g_matProjection_window );
D3DXMatrixTranslation( &matTranslation, 0.0f, 0.0f, 5.0f );
D3DXMatrixRotationYawPitchRoll( &matRotation, D3DXToRadian(g_fSpinX_L), D3DXToRadian(g_fSpinY_L), 0.0f );

g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE );

matWorld = matRotation * matTranslation;
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

g_pd3dDevice->BeginScene();

g_pd3dDevice->SetStreamSource( 0, g_pVertexBuffer, 0, sizeof(Vertex) );
g_pd3dDevice->SetFVF( Vertex::FVF_Flags );

//RENDER background
g_pd3dDevice->SetTexture( 0, g_pTestTexture1 );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 4, 2 );

//RENDER RENDERTARGET
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TEXTURE );


g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);

g_pd3dDevice->SetTexture( 0, g_pDynamicTexture );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 8, 2 );

g_pd3dDevice->EndScene();
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement