Hi.
I’ve coded several image effects which modify a passed texture using Graphics.Blit with specific shader and pass it to a next effect. Forming a chain of effects. You know, like an algorithm: 1. blur, 2. threshold, 3. edge detect.
This chain has many calls to Graphics.Blit, which as I understand is a separate draw call itself.
So, is it a good approach or I’ll get myself into serious performance problems pretty soon?
1 Answer
1
Having them as separate scripts gives you flexibility to add/remove/disable/enable them as needed. But for performance reasons it would be best to combine the effects into a single OnRenderImage call when possible.
So a better approach is to combine as many of your effects as you can into a single effect. Every Graphics.Blit of a fullscreen quad is of course expensive, therefore the less you do it, the more you save.
You can also render to a RenderTexture instead of to the screen, as this will read back from screen to the Texture pass to OnRenderImage.
Finally, you can also downscale your RenderTexture which will reduce the number of texels from the RenderTexture that have to be processed and improve performance.
If you can combine effects then do - but I'm guessing that many of those effects need to process the previous result - so you have little choice?
– whydoidoitYeah, effects need result of previous ones. I just wonder how much this will hurt performance. If I got like 100 of them combined == 100 more draw calls.
– valyardThe question is are these draw calls lightweight or it doesn't matter? I'd guess that uploading a quad and initializing a texture with a shader wouldn't be such a bottleneck. Comparing to rendering huge meshes with giant shaders.
– valyard100 - wow - I can't wait to see what you are making! Must be amazing! Well if the quads cover the whole screen then you have minimum 100x full screen resolution overdraw which might screw up fill rate on some devices (and clearly would never fly on mobile platforms).
– whydoidoitSo no they aren't lightweight - they're pretty heavy because lets face it the vertex part of a shader is called a lot less than the fragment part - then you've got auto culling due to obscured depth normally etc etc.
– whydoidoit