Search Unity

Using grabpass too costly on ios? Is there an alternative?

Discussion in 'Shaders' started by kjetilh, Oct 8, 2011.

  1. kjetilh

    kjetilh

    Joined:
    Oct 1, 2010
    Posts:
    82
    Hey!

    I tried creating a distortion shader, for use with ios. Basically mangling the, I think it was a glass shader that comes with unity pro.

    So it's setup like blow, the grabpass stores the "screen" in a predefined texture for use.

    I had a pretty minimal shader using this, and I got roughly 7 fps on my iphone4. No Go.
    So, I wonder, is GrabPass the only way I get get the screen texture? It seems to me as something that should be readily available for use in a shader already, and in theory should be quite cheap to access?

    If anyone has made a image distortion shader for ios, I'd love to see how that was done! Thanks!


    Code (csharp):
    1. GrabPass
    2. {                          
    3.     Name "BASE"
    4.     Tags { "LightMode" = "Always" }
    5.  }
    6. Pass
    7. {
    8.     Name "BASE"
    9.     Tags { "LightMode" = "Always" }
    10.     etc etc..
     
  2. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Check out the talk the shadowgun guys did at unite - its on youtube. They talk about exactly this.
     
  3. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    I saw this talk the Shadowgun guys did, and they talk about using a vertex-grid based post fx. I don't really understand what this means and I know very little about writing shaders, but can someone clarify this technique to me? Thanks.
     
  4. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Grabpass isn't very fast compared to a lot of other things you might do with a shader, but it's by far the fastest way of getting what you need for a distortion shader.

    If I recall correctly, the Shadowgun distortion approach reduced the cost by using a grid mesh instead of a full-screen quad for the postprocess effect, and they distorted the vertex positions rather than using a distortion texture. This removed the texture read (which made the other read independent), and moved the actual distortion arithmetic to the vertex shader and interpolators. These are both good things on iOS, where you're likely to have far fewer pixels than vertices, and texture reads are already slow.
     
  5. brn

    brn

    Joined:
    Feb 8, 2011
    Posts:
    320
    Just adding to what Daniel has said which is spot on. It's reading from the framebuffer on IOS that's slow. you can avoid doing this by creating your own render targets and using those to read from. Its been a while since I've been on the forums but here are some old posts of mine that cover similar issues.

    With Unity 4 things might have improved as far as reading from the framebuffer (my guess is that it hasn't, because this would be a hardware or OS limitation?)

    Aras might be able to clear things up further. Perhaps in Unity 4 they now avoid the frame buffer write until everything else has been done using custom buffers anyhow.

    http://forum.unity3d.com/threads/143887-DOF-on-IOS-How-we-did-it-(mini-post-mortem)
    http://www.photonworkshop.com/index.php/blog/dof-bloom-package/

    Kind regards
    Bruno