Search Unity

IPad performance issues with diffuse shader

Discussion in 'Shaders' started by OlegGel, Nov 26, 2010.

  1. OlegGel

    OlegGel

    Joined:
    Nov 9, 2010
    Posts:
    12
    I have Sprite with diffuse material, ambient color in Render Settings set to (0, 0, 0). I want create spot light which moves on sprite surface and search items in scene. But on ipad fps decrease to 7 fps.
    I try use VertexLit shader on material, but i don't see circle light on sprite, only when move light to vertex of sprite.

    Which shader better use for such scenarios on ipad? Sorry for english.
     
  2. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Per-pixel lighting is slow on iOS, and vertex lighting will require you have more vertices in your sprite, making it more costly as well. For a strictly 2D game, I would recommend doing lighting in a cheap deferred way, such as having a full-screen multiplicative sprite that modulates the colour of everything behind it. How you generate that sprite depends on the number of lights you want. If it's more than one, you might look into using render textures.
     
  3. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Actually pixel lighting isn't thaat slow.

    But a common error is to have shaders which have blending in in any form and thats just something the ipad dislikes.

    pixel lights have the benefit of not killing the fillrate unlike the "oldschool" overlay method which is unhappily extremely ipad unfriendly (you have 2-3 full screen redraws per frame so wasting a full one for a light overlay is not an option in the vast majority of situations, having local per light ones with rather restricted light ranges would be the way to go if we went with overlay). If you go with the overlay also ensure to change the define in the xcode project that tells unity to not use OpenGL ES 2.0, you will benefit from ARMV7 optimizations that way without the ogl es 2.0 hit

    Also, using the desktop shaders and surface shaders makes the problem of shader performance even worse, I would recommend going with GLSL if performance on iOS matters.
    Or not using shaders cause the OGL ES 2.0 path is still slower than the OGL ES 1.1, for whatever reason
     
  4. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Full-screen multiplication is a lot cheaper than PPL on everything. Fixed function shaders get translated fairly optimally to GLSLES, and the iPad can do quite a few more than 3x overdraw before you start dropping below 30fps.
     
  5. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    The shaderlab declarations indeed go over pretty well to ES 2.0 (for ES 1.1 there isn't much they can do wrong as they are either glstate setups or straight OGL ES combiner blocks), but it depends a bit on what you did. if it was trivial enough for a iPhone 3G FFP shader then its normally no problem but anything that would end on multiple passes there can normally be optimized from the output for the specific task.
    But generally as long as you don't come from surface shaders and hope to get something optimized you are fine :)
     
    Last edited: Nov 27, 2010