TGEA 1.7.1 -- Multiple Render Targets?
by Matt Vitelli · in Torque Game Engine Advanced · 12/15/2008 (11:03 pm) · 7 replies
Hello, I have been experimenting with multiple render targets. I cannot find any references in TGEA that use more than just Color0 or sDefaultDepthStencil. When I try outputting the results of MRTs, all but Color0 appear black, as if nothing was rendered into them at all. Could anyone offer insight into how to use MRTs? Below is an example of my code and pixel shader output.
Thanks,
Matt Vitelli
GFX->pushActiveRenderTarget(); mTarget->attachTexture( GFXTextureTarget::DepthStencil, GFXTextureTarget::sDefaultDepthStencil ); mTarget->attachTexture( GFXTextureTarget::Color0, surf0 ); mTarget->attachTexture( GFXTextureTarget::Color1, surf1 ); mTarget->attachTexture( GFXTextureTarget::Color2, surf2 ); mTarget->attachTexture( GFXTextureTarget::Color3, surf3 ); GFX->setActiveRenderTarget( mTarget ); GFX->clear( GFXClearTarget, ColorI(0,0,0,0), 1.0f, 0 );
struct Fragout
{
float4 Col0: COLOR0;
float4 Col1: COLOR1;
float4 Col2: COLOR2;
float4 Col3: COLOR3;
};Thanks,
Matt Vitelli
#2
//Edit:
And the corresponding deactivation code should probably set all render targets except for Color0 to NULL.
12/16/2008 (6:35 am)
Should probably look something like this (untested):// Set all the surfaces into the appropriate slots.
for( U32 i = GFXTextureTarget::Color0, rtIndex = 0; i <= GFXTextureTarget::Color4; ++ i, ++ rtIndex )
if( gdtt->mTargets[ i ] != NULL )
D3D9Assert( mD3DDevice->SetRenderTarget( rtIndex, gtdd->mTargets[ i ] ),
avar( "GFXD3D9Device::setActiveRenderTarget - failed to set slot '%i' for texture target", rtIndex ) );//Edit:
And the corresponding deactivation code should probably set all render targets except for Color0 to NULL.
#3
12/16/2008 (7:39 pm)
Indeed, that would make sense, but upon implementation this yields bizarre results. If anyone has anymore insight into this, it'd be greatly appreciated.
#4
Off the top of my head
Formats don't have to match but bit depth does.
D3D will set the view port to the full size of the last render target set.
12/17/2008 (10:49 am)
What are the bizarre results? These could be for many reasons.Off the top of my head
Formats don't have to match but bit depth does.
D3D will set the view port to the full size of the last render target set.
#5
12/18/2008 (6:20 am)
Specifically, things do not render. The screen is black while facing meshes(which are invoking the multiple render targets). The texture formats are identical to each other.
#6
I implemented the above change and the corresponding cleanup in 1.8 and everything works fine. Haven't actually tried making use of MRT but at least Color0 isn't affected at all--and as all the SetRenderTarget calls are there, MRT *should* work (but okay, that's a statement worth little until it actually is proven to run).
Are you sure you are complying with all restrictions that apply to MRT? Max number of simultaneous render targets supported by your card, etc. (see here)
//EDIT: typos
12/18/2008 (7:38 am)
By "screen is black" do you mean that Color0 isn't getting any data, too? (otherwise the bizarre results after the change are the same bizarre results as before the change--black render targets :)I implemented the above change and the corresponding cleanup in 1.8 and everything works fine. Haven't actually tried making use of MRT but at least Color0 isn't affected at all--and as all the SetRenderTarget calls are there, MRT *should* work (but okay, that's a statement worth little until it actually is proven to run).
Are you sure you are complying with all restrictions that apply to MRT? Max number of simultaneous render targets supported by your card, etc. (see here)
//EDIT: typos
#7
12/19/2008 (6:35 am)
Yes, essentially neither of the render targets appear to be receiving any data. I've worked with Multiple Render Targets before and the current settings match all of the qualifications.
Associate Rene Damm
Same goes for 1.8 BTW.
Here's the snippet from 1.7.1:
// Deal with texture target case. if(GFXPCD3D9TextureTarget *gdtt = dynamic_cast<GFXPCD3D9TextureTarget*>(target)) { // Clear the state indicator. gdtt->stateApplied(); // Set all the surfaces into the appropriate slots. D3D9Assert(mD3DDevice->SetRenderTarget(0, gdtt->mTargets[GFXTextureTarget::Color0]), "GFXD3D9Device::setActiveRenderTarget - failed to set slot 0 for texture target!" ); D3D9Assert(mD3DDevice->SetDepthStencilSurface(gdtt->mTargets[GFXTextureTarget::DepthStencil]), "GFXD3D9Device::SetDepthStencilSurface - failed to set depthstencil target!" ); // Reset the viewport. D3DSURFACE_DESC desc; gdtt->mTargets[GFXTextureTarget::Color0]->GetDesc( &desc ); RectI vp( 0,0, desc.Width, desc.Height ); setViewport( vp ); // Exit! return; }