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

Started by
8 comments, last by Fadiii 15 years, 5 months ago
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 ?
Advertisement

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.
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
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.
Use multiple rendertarget is the best options in your case

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.
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
What sort of hardware are you running this on? Post-processing passes in general should be cheap...usually a fraction of a millisecond for each.
I'm using NVIDIA GeForce 7300 GS (128bm video ram)
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/
I forgot to say that you have to use arrow keys to play the animation
Left-Right ..... to roll the paper
Up-Down ...... to change the size of the roll
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.

This topic is closed to new replies.

Advertisement