Sign in to follow this  

[XNA2] Using the same render target more than once each frame

This topic is 3319 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 all I'm developping a software which allows the user to compose imported materials using a stage, timeline, and effects. So it is all about post-processing techniques (Pixel Shaders and sprites). I reached the stage where I want the user to be able to mix more than one effect applyed to each object, so the output of one effect is the input for the next effect. I belive that MRT (Multiple render targets) is not an option here, so I used the same render target to do accumulative effect operations. RenderTarget2D ComposeTarget Texture2D ObjTexture foreach effect { SetRenderTarget(0, ComposeTarget) ApplyEffect(ObjTexture) SetRenderTarget(0, null) ObjTexture = ComposeTarget.GetTexture } Draw obj It works fine for the first effect (90fps), but adding more effects cause the rendering to Stutter (still 50fps). Is it because I'm using the same render target more than one per frame ? Is it a garbage collection issue ? or Is there any other approach better than mine to accumulativly mix effect ?

Share this post


Link to post
Share on other sites

I'm not quite sure I understand what you're trying to do exactly there... Are you basically applying post-processing techniques to imported textures and then drawing the objects with that?

Generally speaking, you could try to swap between one of two RTs for each effect. The reason this might increase performance is that the GetTexture and SetRenderTarget call basically have to wait on eachother, moreso when using the same RT, so using two can reduce a bit of this overhead. You also might want to make sure the numLevels parameter for your RT2D constructor is set to 1 (and not 0 as is typical), so it doesn't generate an entire MIP chain for each intermediate step.

Share this post


Link to post
Share on other sites
In my application there is no 3D objects, It is full post-processing application to import graphics and materials as texture to play them live on air (Broadcasting).

Whatever, I tried switching between two RTs and still have the same stuttering effect, and this defect disapeared when I turned one of them off, but I lost effect mix feature.

any suggestions.

Note:
There is no dynamic resource creation, and the number of mip levels for all textures is 1.

Share this post


Link to post
Share on other sites

I don't think MRTs are applicable here. Afaik MRTs can output multiple textures in parallel, but the OP needs the output texture from the first 'pass' in the second.

Even when switching RTs you're going to suffer from some overhead though, since you're effectively stalling the pipeline with the effects having to wait for eachother. Still, the performance hit shouldn't be that dramatic and generally should be safely within the interactive framerates, if everything else checks out.

You could try sticking the RT stuff in a simple seperate project and checking to see how it works out there, to isolate the issue. If the performance is significantly better there, there might be something off with how everything works out in your game. If it's sluggish there as well (with reasonable texture sizes & effect complexity), we'll at least know where to look.

Share this post


Link to post
Share on other sites
I did what remigius suggest, I started a clean project with one texture and one effect and two render targets.
- rendering to the first render target with effect
- rendering to the second render target without effect
- Draw the result

The stuttering is very obvoius, when skipping the second step the render goes smooth again.
I uploaded the test project after disabling the second step to see the smoothness of the animation.
Enable this block to see this defect.

To download:
http://www.filepanda.com/file/ki2jnex70pdd/

Share this post


Link to post
Share on other sites
The problem partially solved and it is hardware related, using the render target over and over in the same frame is applicable but not cheap.
The problem disapeared when testing the project using more advanced systems.

Thank you all.

Share this post


Link to post
Share on other sites

This topic is 3319 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.

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