Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Fullscreen Post Effects, performances and profiling.

Discussion in 'PSM' started by Spidyy, May 22, 2014.

  1. Spidyy

    Spidyy

    Joined:
    Mar 6, 2011
    Posts:
    184
    Hello there.

    It was destined to come, since I talk about RenderTextures in one of my post, so here is the talking about Image Effects.

    First, I'll say the Vita is perfectly capable of displaying post-effects. The two example games I know are Killzone Mercenary and Toukiden.

    Just see the images :

    Killzone Mercenary use blur to have some depth of view :
    $Killzone-Mercenary-7.jpg

    Killzone Mercenary use bloom and tone mapping :
    $Killzone-Mercenary-screenshot-11.jpg

    Toukiden use tone mapping, bloom and image distortion :
    $2014-05-22-214400.jpg

    And both works at a sturdy 30 frame per seconds.

    Now on Unity side.

    To create an image effect on Unity, it is quite simple :
    - Create a script and attach it to your main camera
    - On Start, create needed materials for your effects
    - Prepare your RenderTextures with RenderTexture.GetTemporary and RenderTexture.ReleaseTemporary
    - Override OnPreCull or OnPreRender to create a temporary camera and use it to render your additionnal rendering using RenderWithShader method
    - Override OnRenderImage to retrieve the source image from your main camera, add your effects and give them to the destination image.

    If you know how to work with CG shaders and textures, you can achieve some good looking effects. That is the theory.

    But the practical way is a bit weird when using it on your Vita.

    I did a rather complicated image effect to have dynamic glow and shadows on a top down 2D shooter. Their execution is rather simple. It require for me 5 RenderTextures, 5 Shaders, 3 as replacement shaders, 2 as effect shader.

    The result is really delicious (taken from my babe) :

    $2014-05-22-221023.jpg

    Using the System.Diagnostic.Stopwatch, we can have really precise time measures, in tenth of milliseconds, and here what this little shaders use as time on my script :
    - 1.5ms to call OnPreCull, with not more than 0.3ms to render 3 of the 5 textures.
    - 0.7ms to call OnRenderImage, with at least 5 call to Graphics.Blit.
    It is furiously fast.

    SO WHY OH WHY? Why do my game runs only at 26fps without Vsync?

    The answer in the profiler :
    $Profiler.jpg
    (Right click and Open the image in a new tab.)

    What in the world is this "Other" tab, filling of a bright red all my available time? Some topics on the forum said Gfx.WaitForPresent is about VSync... Ok.

    I didn't activated Vsync for the test, as show my quality settings to the right, which is the ONLY quality settings set for my project. But it is still activated? And it takes so much more than what I use for a frame? Sweet Jesus.

    And strangely, if I deactivate my Image Effect, this Gfx stuff don't appear anymore.

    So, the aim here is to kill this Gfx stuff, but how?
     
    Last edited: May 22, 2014
  2. blackbird

    blackbird

    Joined:
    Aug 9, 2011
    Posts:
    588
    how about if you remove a directional light or deactivate the shadows then check how much frames you get ?
     
    Last edited: May 24, 2014
  3. jesusluvsyooh

    jesusluvsyooh

    Joined:
    Jan 10, 2012
    Posts:
    375
    I have no performance issues on the ps vita, here i am running a MULTIPLAYER GAME, with SHADOWS, DIRECTION LIGHT, and 200+ randomly spawned objects over the network. and its running at 88 frames per second.
    roughly 200+ draw calls, 10k, triangles when looking through player camera (according to unity editor)

    $2014-05-14-114116.jpg $2014-05-14-114139.jpg
     
  4. bakanekofr

    bakanekofr

    Joined:
    Feb 28, 2014
    Posts:
    118
    Any tips for obtaining such performances ? What should be used, and what should not ?
     
  5. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    Hi bakanekofr,

    I have tried many ways to implement post-process effects on vita, and all lower the performance by 50-70%.
    The diference between KillZone Mercenary and Unity for PSM is "Tiled deferred" based rendering. PsVita GPU is optimized for Tiled deffered path and works even better than forward rendering on PsVita. In the other hand, deferred rendering on Unity PSM is worse than forward.
    You can only use forward and that limits to much the performance of PsVita.

    P.D: And realtime shadows.............. are very bad implemented for sure, Uncharted and killzone show realtime shadows with solid 30fps. Wait for newer version of Unity PSM (official build, not beta) and we will see if they fix it ( as the camera culling faces, terrible with skyboxes...).

    Edit: I was wrong, Killzone Mercenary uses forward rendering. They decided to go forward to mantain full native resolution+MSAA.
     
    Last edited: May 25, 2014
  6. blackbird

    blackbird

    Joined:
    Aug 9, 2011
    Posts:
    588
    one more thing killzone use dynamic resolution scaling thats mean the resolution change everytime when there is some action going on
     
  7. Spidyy

    Spidyy

    Joined:
    Mar 6, 2011
    Posts:
    184
    Oh, seems their is a misunderstanding.

    My game is a 2D game, and don't use ANY Unity built-in shaders, it is 100% hand-made shaders.

    I don't use the Unity Lighting or Shadow system. The Shadows are don't using a Fullscreen Post-effect, light is pre-rendered from 3DS max.
     
  8. bakanekofr

    bakanekofr

    Joined:
    Feb 28, 2014
    Posts:
    118
    OK, thanks for your replies.
     
  9. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    IIRC this is not only VSync. The CPU and GPU run asynchronously, and if the CPU is 'faster' (== has less work) then it need to stall for the GPU at some point. Depending on the architecture this can happen at various different points, but it sounds like the time you see in WaitForPresent is the time taken to render your Image Effect.
     
  10. Spidyy

    Spidyy

    Joined:
    Mar 6, 2011
    Posts:
    184
    So that mean my Image Effects are really slow. :(

    Ok, thanks.
     
    FireBird110 likes this.