Sign in to follow this  
monkeyboi

render to multi-target

Recommended Posts

I want to use shader once to render to multi-target right now the first texture is correct but the last two seems not working

struct PSFRT_OUT {
float4 Col0 : COLOR0;
float4 Col1 : COLOR1;
float4 Col2 : COLOR2;
};
PSFRT_OUT PSFRT(float2 infor2: TEXCOORD2,float2 infor3: TEXCOORD3,float2 infor4: TEXCOORD4,float2 infor5: TEXCOORD5,float2 infor6: TEXCOORD6){
PSFRT_OUT Out = (PSFRT_OUT)0;
Out.Col0 = float4(infor2,infor3);
Out.Col1 = float4(infor4,infor5);
Out.Col2 = float4(infor6,0.0f,1.0f);
return Out;
}

m_pNewPosTexture->GetSurfaceLevel( 0, &m_pNewPosSurf );
hr = m_pDevice->SetRenderTarget(0,m_pNewPosSurf);

m_pNewVelTexture->GetSurfaceLevel( 0, &m_pNewVelSurf );
hr = m_pDevice->SetRenderTarget(1,m_pNewVelSurf);

m_pNewAttributeTexture->GetSurfaceLevel( 0, &m_pNewAttributeSur);
hr = m_pDevice->SetRenderTarget(2,m_pNewAttributeSur);

hr = mFX->CommitChanges();

//Begin passes
UINT numPasses=0;
mFX->Begin(&numPasses,0);
mFX->BeginPass(0);
m_pDevice->SetFVF(INFORMATION::FVF);
m_pDevice->SetTexture(0,NULL);//m_pTex
m_pDevice->SetStreamSource(0, m_pVBQuad, 0, sizeof(INFORMATION));
m_pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2110);



plus i have checked the number of target I cud use which is 4 and the output of pixel shader is surely correct
D3DCAPS9 Caps;
bool multitarget = true;
m_pDevice->GetDeviceCaps( &Caps );
if( Caps.NumSimultaneousRTs < 2 )
multitarget = false;

so where am I wrong?

Share this post


Link to post
Share on other sites
Hope you didn't forget to;
* write mFX->EndPass(); and mFX->End(); lines.
* restore render targets.

Also, there's no need to call mFX->CommitChanges(); before any rendering operation. Because it's purpose is updating all the data in your effect sent from software (like textures, floating point values etc.) between ID3DXEffect::BeginPass(); and ID3DXEffect::EndPass() lines.

Share this post


Link to post
Share on other sites
thanks I wrote mFX->EndPass(); mFX->End(); and restore render targets.
so that means I need to call mFX->CommitChanges(); when I update the effect like

bool MyParticleSystem::Update(D3DXVECTOR3 CameraPos, float Time,D3DXMATRIX View, D3DXMATRIX projection){

vp = View * projection;
mFX->SetMatrix(m_hVPMatrix,&(vp));
mFX->SetFloat(m_hTime,Time);

return true;
}


when i swap the textures that will used in effect do I need to do that as well?

Share this post


Link to post
Share on other sites
If you pass any data after calling ID3XEffect::BeginPass(), you need to call ID3DXEffect::CommitChanges().

Like:
m_pEffect->Begin(0);
m_pEffect->SetMatrix ( blah blah blah);
m_pEffect->SetTexture( blah blah blah);
m_pEffect->BeginPass (0);
m_pEffect->SetInt ("someInt", someInt);
m_pEffect->CommitChanges (); //call this for clearly setting "someInt" variable.
m_pEffect->EndPass();
m_pEffect->End();



So, if you swap any texture that will be sent to the shader, you must send it again. And if you do it after calling ID3DXEffect::BeginPass(), you also need to call ID3DXEffect::CommitChanges().

hth
-R

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