ShadowGun : Optimising for Mobile

Discussion in 'Unity Support' started by willgoldstone, Mar 30, 2012.

  1. willgoldstone

    willgoldstone

    Unity Technologies

    Joined:
    Oct 2, 2006
    Messages:
    487
    Hi everyone, we wanted to help you with optimizing your mobile game, so we recently published a blog post with some tips and tricks from the game ShadowGun, courtesy of MadFinger Games. We provide a sample level with some awesome shaders from the game that you are free to use in your games - the rest of the sample (meshes, textures) are copyright of MadFinger.

    Please use this forum to discuss the tips therein, and related optimization issues.

    Check out the blog post below -

    http://blogs.unity3d.com/2012/03/23/shadowgun-optimizing-for-mobile-sample-level/

    nb. Please note that dynamic fluid surfaces should be discussed in separate threads.
  2. Andrea Monzini

    Andrea Monzini

    Member

    Joined:
    Oct 9, 2008
    Messages:
    447
    As suggested i rewrite my question here:

    The project with my Mac 10.7.3 and Unity Pro 3.5 have lost all references.
    I have tried to download it again, but it doesn't works.
    Could you provide an .unitypackage or how i can rebuilt library references?

    Thank you.
    Last edited: Mar 30, 2012
  3. chaneya

    chaneya

    Member

    Joined:
    Jan 12, 2010
    Messages:
    110
    Thanks for moving this to the forums Will.

    Copy of my reply on the Blog Post:

    Thanks for the replies.
    My problem is if I target armv7, my framerate is crippled on iPad 1. It’s easily a 50% performance hit. Targeting Universal armv6 and armv7, both cripples performance and results in a build size that makes it impossible using Unity to hit the 20meg limit for mobile downloads.

    My game is based on breaking glass so I use very simple glass shaders to make very low poly objects look like glass with a heavy reliance on the physics system for breakage. Since the whole world is made of glass, I’m using shaders with Tags to designate the render Queue allowing for transparent overlapping objects that I can control. (Background, Background+1, playerQueue, OverLay for in front of player) The shaders are shockingly simple with a simple color property for different colored glass and blending (Blend One One) for additive or Blend ScrAlpha OneMinusAlpha for real alpha blending. Oddly enough (armv6 ES1.1) handles this setup admirably. (armv7 ES2.0) on the other hand seems to immediately hit me with a 50% penalty.

    I would love to move to armv7 so I can use some of the effects demonstrated by MadFinger. I’ll keep researching.

    Allan
    Last edited: Mar 30, 2012
  4. mikolo

    mikolo

    New Member

    Joined:
    Nov 27, 2009
    Messages:
    245
  5. michelhabib

    michelhabib

    New Member

    Joined:
    Mar 12, 2012
    Messages:
    7
    This is no less than releasing Doom Source Code many years ago :)
    But the last thing i would imagine is that the waving flag is an animated shader!!!
    Kudos, You have an amazing Shaders Team, I must say that Shaders are one of the Heroes on this project, and for this only i find the sample level EPIC, even without any gameplay features revealed.
    Perfect Again, thank you, will bug you again in the comments.
  6. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Messages:
    11,043
    It's a milestone in unity blog postings. I've asked many a time for unity to put some exciting blogs out and also asked many times for insights into the techniques in shadowgun, mostly the tricks used for character shading, and both madfinger and unity have delivered.

    I honestly didn't expect much and had already shut up about it when this came along...! Props to all involved, this is important for not just mobile, but for any developer wishing to optimise.

    For an indie with very serious time constraints, can you imagine how important it is?


    Once again - thank you.

    Jason Amstrad will have to wait longer for his wet dream.
  7. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Messages:
    11,043
    You are 100% totally wasting your time supporting Arm 6. I'll go on record saying you'll make a grand total of zero sales for arm 6 (the iphone 3G original).

    The problem with iPad is that the opengl ES 2.0 shaders appear to be much slower, I'm not sure why, they just are. I can only assume black magic.
  8. DarthJosh85

    DarthJosh85

    New Member

    Joined:
    Mar 30, 2012
    Messages:
    3
    I love that unity decided to share this information with us. But the think I want to know most is how they did their cover system. I am more of an artist that a programmer and I just can't seem to figure out where to even start.
  9. chaneya

    chaneya

    Member

    Joined:
    Jan 12, 2010
    Messages:
    110
    Hippocoder,

    I'm not so much "targeting" avrmv6 as I am just using what works. I fully intend to release for iPhone 3GS and up devices. I test on all of them.

    Armv6:
    My game runs at 60fps with no hiccups on iPad2. It runs great on iPhone 4 and 4S. I've been using the iPad 1 as the baseline since it is the slowest due to the higher resolution. (I do have performance problems on the 3GS but I think that is due to the physics/slower cpu). Given the much lower resolution on the 3GS, the 3GS likely renders equal or faster than the iPad1.

    I agree with you however. I am going to try to get things running on armv7.

    So the question is why would this simple shader crush armv7? Granted I'm using it on multiple materials with different color values and different render Queue Tags so I can control the Draw order of my transparent/glass objects. But ES1.1 handles it fine but ES2.0 is sees 40-50% drop in FPS.
    This is the code for the BackgroundQueueAdditive.
    Code (csharp):
    1.  
    2. hader "Mobile/BackgroundQueueAdditive"
    3. {
    4.     Properties
    5.     {
    6.         _Color ("Main Color", Color) = (.5,.5,.5,0)
    7.        _EnvMap ("EnvMap", 2D) = "black" { TexGen SphereMap }
    8.     }
    9.    
    10.     Category
    11.     {
    12.         Tags { "Queue"="Background" "IgnoreProjector" = "True" "RenderType"="Background"}
    13.         //SeparateSpecular On
    14.         Lighting Off
    15.         Zwrite off
    16.         Fog { Mode Off }
    17.         //Ztest Always
    18.         //Cull off //Will Show back thorugh front
    19.        
    20.         Blend One One                       // additive
    21.         //Blend One OneMinusSrcColor          // soft additive
    22.         //Blend SrcAlpha OneMinusSrcAlpha     // real alpha blending
    23.  
    24.         SubShader
    25.         {
    26.           Pass
    27.           {
    28.             SetTexture [_EnvMap]
    29.             {
    30.                 combine texture
    31.             }
    32.             SetTexture [_EnvMap]
    33.             {
    34.                 constantColor [_Color]
    35.                 Combine previous * constant DOUBLE, previous * constant
    36.             }  
    37.           }
    38.       }
    39.    }
    40. }
    41.  
    Last edited: Apr 1, 2012
  10. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Messages:
    11,043
    This is something you'll see happen quite a lot using shaderlab stuff, it just is a lot slower on ES 2.0, but a lot faster on 1.1. I do not know why this is, but if I had to hazard a guess it is because that shader is written with fixed function in mind. 2.0 hasn't got any fixed function, so what happens is the shader is automatically converted from fixed function to GLSL, but something is being added (probably lighting stuff and so on) which will slow it right down.

    I don't know the specifics, but it means the only way to match 1.1 speeds is to write the shader in either cg, or glsl (both which I suck at and can't really help you with).
  11. tristamus

    tristamus

    New Member

    Joined:
    Mar 30, 2012
    Messages:
    1
    Could someone please assist in getting this to open properly in unity?

    I am using Unity version 3.5.0f5, yet when I open the _Level unity scene file, all I get are a bunch of lights and nothing else. It also reads "The referenced script on this Behaviour is missing!"

    Don't know how to get this to work!

    I've tried re-downloading it multiple times, all yielding the same results.
  12. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Messages:
    3,531
    @Chaneya: Have you tried writing actual pixel vertex shaders as opposed to using the fixed function pipeline which is emulated?

    From looking at the shader you posted, i would imaging that _EnvMap ("EnvMap", 2D) = "black" { TexGen SphereMap } is not great for performance on the GLES 1.1. emulated shader path.

    As you can see in Shadowgun, you can get the iPad1 to perform well on pretty high-end scenes.
    But you have to actually dig into your shaders and make sure they are well optimized. Especially on surfaces that cover a lot of pixels.


    Maybe you should start with the shadowgun shaders as a basis and tweak them for your specific needs?
  13. chaneya

    chaneya

    Member

    Joined:
    Jan 12, 2010
    Messages:
    110
    Joachim,

    I am working with the Shadowgun shaders but many of them are way over my head. Many of them are very very complex.

    Although it may be _EnvMap ("EnvMap", 2D) = "black" { TexGen SphereMap } that is causing the crush in ES2.0, if I comment out my use the following lines that apply the color, I get great framerate in ES2.0.

    _Color ("Main Color", Color) = (.5,.5,.5,0)

    SetTexture [_EnvMap]
    {
    constantColor [_Color]
    Combine previous * constant DOUBLE, previous * constant
    }

    Thanks for the tip though.

    Allan
  14. Neogene

    Neogene

    Member

    Joined:
    Dec 29, 2010
    Messages:
    41
    I cleared the lighmapping, changed some light and baked again: bug on 3.5:

    Something went wrong in the Beast lightmapper: Job Execution Failure This is a bug - please report it with a scene reproducing the issue.

    File : /Applications/buildAgent/work/<RANDOM NUMBERS>/Editor/Src/Lightmapping.cpp at line 42
  15. Andrea Monzini

    Andrea Monzini

    Member

    Joined:
    Oct 9, 2008
    Messages:
    447
    I have similar problem.

    Unity 3.50f5, Lion 10.7.3 and when i open the level, in the project panel i can see only "Shaders" Folder that is in this path:

    ShadowgunSampleLevel/ShadowGunSample/Assets/Assets/Shaders

    EDIT: i have tried to rename the second folder Assets/Shaders to Assets2/Shaders, so i am able to open the level but (obviously ) all shaders references are lost.

    In any case could you provide an .unitypackage?
    Last edited: Mar 31, 2012
  16. garyhaus

    garyhaus

    Member

    Joined:
    Dec 16, 2006
    Messages:
    514
    Assets are broken. Only a Shader folder and no meshes. They all show as red in the hierarchy.

    Gary
  17. Andrea Monzini

    Andrea Monzini

    Member

    Joined:
    Oct 9, 2008
    Messages:
    447
    I agree, i have tried with Snow Leopard too, and i have the same problems.
    The project works with Mac or only with Windows?
  18. Andrea Monzini

    Andrea Monzini

    Member

    Joined:
    Oct 9, 2008
    Messages:
    447
    It works but after some tricks!

    In fact the Assets/Assets folder brokes the references library.

    1- Copy Assets/Shaders

    2-Delete Assets/Shaders

    3-Open project

    4-Paste Assets/Shaders with Finder

    5-Rename Assets/Shaders to Assets2/Shaders

    6-Save all

    7-Play!
    Last edited: Mar 31, 2012
  19. pigzlz

    pigzlz

    Member

    Joined:
    Jul 28, 2010
    Messages:
    78
    @chaneya

    I tried to port your shader to cgsl but I can't currently test it on a mobile device.
    Can you test it and report back if it's also crushing your performance?

    Code (csharp):
    1.  
    2. Shader "Mobile/BackgroundQueueAdditive2"
    3. {
    4. Properties {
    5.         _Color ("Main Color", Color) = (0.5, 0.5, 0.5, 0)
    6.         _EnvTex ("EnvMap", 2D) = "black" {}                                                  
    7.     }
    8.     SubShader {
    9. //      Tags { "Queue"="Background" "IgnoreProjector" = "True" "RenderType"="Background"}
    10.         Tags { "Queue"="Transparent" "IgnoreProjector" = "True" "RenderType"="Transparent"}
    11.        
    12.         Pass{
    13. //          Alphatest Greater 0
    14. //          Cull Off
    15.             ZWrite Off
    16.  
    17. //          Blend SrcAlpha OneMinusSrcAlpha     // Alpha blending
    18.             Blend One One                       // Additive
    19. //          Blend One OneMinusDstColor          // Soft Additive
    20. //          Blend DstColor Zero                 // Multiplicative
    21. //          Blend DstColor SrcColor             // 2x Multiplicative
    22.            
    23.             CGPROGRAM
    24.             #pragma vertex vert
    25.             #pragma fragment frag
    26.             #include "UnityCG.cginc"
    27.            
    28.             //Declare Properties
    29.             sampler2D _EnvTex;
    30.             fixed4 _Color;
    31.             //------------------
    32.            
    33.             //Declare structures
    34.             struct v2f{
    35.                 float4 pos : SV_POSITION;
    36.                 //half4 color : COLOR0;
    37.                 //half2 uv : TEXCOORD1;
    38.                 half2 uvSphere : TEXCOORD0;
    39.             };
    40.             struct appdata_custom {
    41.                 float4 vertex : POSITION;
    42.                 //float4 tangent : TANGENT;
    43.                 half3 normal : NORMAL;
    44.                 //half4 texcoord : TEXCOORD0;
    45.                 //half4 color : COLOR;
    46.             };
    47.             //--------------------
    48.            
    49.             half4 _EnvTex_ST;;
    50.            
    51.             //vertex shader
    52.             v2f vert (appdata_custom v)
    53.             {
    54.                 v2f o;
    55.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    56.                
    57.                 //Sphere mapping ported from http://www.ozone3d.net/tutorials/glsl_texturing_p04.php
    58.                 half3 u = normalize( mul(UNITY_MATRIX_MV, v.vertex));
    59.                 half3 n = mul(UNITY_MATRIX_IT_MV, float4(v.normal.xyz,0));
    60.                 half3 r = reflect( u, n);
    61.                
    62.                 half m = 2.0 * sqrt( r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0) );
    63.                 o.uvSphere = half2(r.x/m+0.5, r.y/m+0.5);
    64.                 //---------------
    65.                                
    66.                 //o.uv = TRANSFORM_TEX (v.texcoord, _EnvTex);;
    67.                 //o.color = v.color;
    68.                 return o;
    69.             }
    70.            
    71.             //fragment shader
    72.             fixed4 frag (v2f i) : COLOR {
    73.                 fixed4 tex = tex2D(_EnvTex, i.uvSphere) * _Color;
    74.                 tex.rgb *= 2;   //double the color values, but leave alpha untouched
    75.                 return tex;
    76.             }
    77.             ENDCG
    78.            
    79.         }
    80.     }
    81. }
    82.  
    83.  
    84.  
    Hope it works on iPad. Also, if it looks slightly different on mobile, it's because I changed lots of variables from floats to halfs, so it's faster but less precise. It's just a quick test and I didn't clean it up. : )
    Last edited: Apr 1, 2012
  20. chaneya

    chaneya

    Member

    Joined:
    Jan 12, 2010
    Messages:
    110
    vwekker,

    Wow you just made my week!

    Your shader translation appears to work great and as far as I can tell it fixes the crushing performance problems when deploying to an iPad1 targeting platform armv7(OpenGL ES 2.0) (in Player Settings).

    I still find it odd that emulating such a simple ES1.1 shader would have such profound performance destruction in ES 2.0. It really is a 50% overall hit in framerate. Thanks so much for doing this.

    For anyone interested, this relatively simple shader gives you:
    - glass that looks like glass on mobile with very little performance hit. (Doesn't break batching as other glass shaders seemed to do in the past)
    - alter color using the color picker on your material
    - control the rendering layer, rendering Queue or Draw Order (however you want to refer to it) by changing the Tag Queue in the SubShader. This gives you complete control over how your overlapping glass objects are displayed.
    - You can compress a spheremapped texture down to 64 X 64 RGBA PVRTC 4bits (2.0kb) and the glass will still look great. (I've attached the spheremap texture I've been using)
    - change the blending option by commenting and uncommenting the lines for additive, alphablending, Soft Additive etc. Using alphablending will make your glass look dark and bold where additive makes it appear more pastel in color.

    Attached Files:

  21. chaneya

    chaneya

    Member

    Joined:
    Jan 12, 2010
    Messages:
    110
    vwekker,

    The only minor note I would make is if you choose alphablending(Blend SrcAlpha OneMinusSrcAlpha) instead of additive (Blend One One), the alpha setting seems to be cut in half as far as effect. In other words an alpha value of 125 gives you basically full opacity where before you didn't see full opacity until about 205.

    Is this a result of using halfs instead of floats? (It's worth the performance gain since all you have to do is change your alpha values on your material.)

    Thanks again
    Allan
  22. pigzlz

    pigzlz

    Member

    Joined:
    Jul 28, 2010
    Messages:
    78
    Thats probably my mistake. I accidently "DOUBLED" the alpha value, too.
    Just change

    Code (csharp):
    1. //fragment shader
    2. fixed4 frag (v2f i) : COLOR {
    3.     fixed4 tex = tex2D(_EnvTex, i.uvSphere) * _Color*2;
    4.     return tex;
    5. }
    to:
    Code (csharp):
    1.  
    2. //fragment shader
    3. fixed4 frag (v2f i) : COLOR {
    4.     fixed4 tex = tex2D(_EnvTex, i.uvSphere) * _Color;
    5.     tex.rgb *= 2; //double the color values, but leave alpha untouched
    6.     return tex;
    7. }
    and it should finally do the same. I will edit this into the last post in case somebody stumbles over it.
  23. chaneya

    chaneya

    Member

    Joined:
    Jan 12, 2010
    Messages:
    110
    Yep that did it.

    Thanks a ton.
  24. chaneya

    chaneya

    Member

    Joined:
    Jan 12, 2010
    Messages:
    110
    @vwekker,

    Further testing shows that performance is not as good using the cgsl shader in armv7 ES2.0 as my old shader was in ES1.1 armv6.

    Do you have any other ideas of how this shader might be further optimized? For example removing color from the shader. I could probably use different colored textures in order to achieve the different colors. Of course I would lose the alpha control which would be a downside for the alphablended version. But perhaps just removing color from the additive version where alpha is not used would help.

    It looks like batching is not functioning as efficiently now. Even with very low poly static objects that are sharing the same material. They don't seem to be batching as effectively as before.

    I attempted to remove the color stuff from the shader but had no luck.

    Any thoughts would be appreciated.
  25. chaneya

    chaneya

    Member

    Joined:
    Jan 12, 2010
    Messages:
    110
    vwekker,

    I found the performance problem with the shader. :) The shader currently breaks static batching if you do not specify the IngnoreProjector and RenderType in the Tag Queue section. So:
    This:
    Tags {"Queue" = "Transparent" }
    or
    Tags {"Queue" = "Background"}

    Needs to be This:
    Tags { "Queue"="Transparent" "IgnoreProjector" = "True" "RenderType"="Transparent"}
    or
    Tags { "Queue"="Background" "IgnoreProjector" = "True" "RenderType"="Background"}

    The same applies if you have your tag set to Overlay or anything else.

    You only see it when you have a scene with dozens and dozens of objects over lapping each other. Out of my 23 levels so far, I have 2-3 scenes that have this setup and I was seeing FPS drops by 30-40% in only those larger scenes with Draw Calls way up in the editor due to the static batching not functioning.

    I've modified my original shader to fix that. And of course I'm curious if this is what led to the emulation performance problem as well with the older shader. when deploying to armv7 and OpenGL ES2.0.

    I'm now seeing an improved framerate of probably 5-10 FPS with your new shader in ES2.0 vs my old shader in ES1.1.

    I would recommend that you also edit your shader post to include the ignoreprojector and rendertype in the Tag Queue section just so no one else gets tripped up on it.
  26. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Messages:
    11,043
    Thanks for sharing your findings. I had no idea that it would break batching like that.
  27. pigzlz

    pigzlz

    Member

    Joined:
    Jul 28, 2010
    Messages:
    78
    @chaneya, Thank you for sharing that, i edited the shader post.
    I would've never guessed that changing the tags could improve the shader this much : ).
    And I would've never guessed that stupidly ignoring tags (as I did) could break batching : (

    Would be cool if there are no further problems with Arm7 so you can use some of the Shadowgun shader stuff.

    And on a sidenote, in one of your comments below the blog post you wrote that you try to hit the 20meg limit for mobile downloads.
    Apple just raised the limit from 20mb to 50mb 3-4 weeks ago, just so you know
  28. DarthJosh85

    DarthJosh85

    New Member

    Joined:
    Mar 30, 2012
    Messages:
    3
    Does anyone know how to paint and bake the vertex color alphas in Maya? I am trying to recreate the animated flag with my own assets and I can't get past this part. Thanks!
  29. chaneya

    chaneya

    Member

    Joined:
    Jan 12, 2010
    Messages:
    110
    DarthJosh85,

    I couldn't figure out how to do it either in Blender. It turns out Blender does not allow you to paint with alpha, only rgb. I ended up buying Vertex Painter from the Asset store. That allows you to paint the vertexes of any mesh you have in Unity within Unity.

    I don't own Maya so I can't help you there.
  30. DarthJosh85

    DarthJosh85

    New Member

    Joined:
    Mar 30, 2012
    Messages:
    3
    So it does work with the vertex painter plug in though? If so I will just buy that then. Thank you by the way.
  31. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Messages:
    11,043
    Yes, should work fine with any vertex painter tool which supports alpha. Vertex alpha, is vertex alpha.
  32. chaneya

    chaneya

    Member

    Joined:
    Jan 12, 2010
    Messages:
    110
    DarthJosh85,

    Yes it does indeed work with Vertex Painter. I modeled my very own plane in Blender, pulled it into Unity, used Vertex Painter to paint increasing alpha values on each row of vertices on the flag mesh, saved, used the ShadowGun shader on a material, created my own flag texture in Photoshop, dragged onto material and finally used the Beast Lightmapping stuff in Unity to create a lightmap of a spotlight I placed in the scene shining on the flag (And removed after baking) and I had my very own flapping flag that uses only one draw call and is static batched and it looks great.

    In my game by the way, this flag replaced a flag I was using that I crafted using Line Renderers that took 7 draw calls.

    It's very impressive to be able to have animating objects that are static that use one draw call.

    The other benefit from a mobile perspective is I was able to compress the flag texture down to 128 X 128 PVRTc 4 bits for 8kb and the lightmap to 32 X 32 PCRTc 4 bits for .8kb.
  33. slinky696

    slinky696

    New Member

    Joined:
    Apr 3, 2012
    Messages:
    1
    This does not work for windows!!

    All shader links are broken !!



    The shadowgun sample level is for mac only!!
  34. Poupi

    Poupi

    Member

    Joined:
    Jan 11, 2012
    Messages:
    51
    Works fine for me on Windows 7 64 bits, no broken links.
  35. jrDev

    jrDev

    Member

    Joined:
    Nov 5, 2008
    Messages:
    1,212
    So I just looked over this and one part struck me:

    Alpha Blending kills. Isn't this counter to what people have been shouting for months now about using alpha blended shaders. Also the blog says this but doesn't give ways of how not to use alpha blended shaders/or in replacement of alpha blended shaders?????
  36. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Messages:
    11,043
    People have said all along that alpha blending kills. You must be having an absurd moment. Alpha = more fill rate used. And we don't like fill rate abuse.
  37. jrDev

    jrDev

    Member

    Joined:
    Nov 5, 2008
    Messages:
    1,212
    Ok then, I must be misremembering, or is it alpha testing kills, it has to be something that I read..anyways...

    So...the tip says this but what do you do if you don't use alpha objects?
  38. chaneya

    chaneya

    Member

    Joined:
    Jan 12, 2010
    Messages:
    110
    @jrricky,

    Actually you're getting alphablending mixed up with alpha testing.

    @hippocdoer....actually that's wrong. Alpha blending does not kill performance. The Unity IOS optimize graphics page recommends switching any alpha testing shaders to alpha blending for performance reasons.
    http://unity3d.com/support/documentation/Manual/Optimizing%20Graphics%20Performance.html

    My entire game uses alpha blending. My entire game world is made of glass with multiple overlapping levels of objects. I make great use of particle effects...most of which use alpha blending.

    Hope that helps.
    Allan
  39. jrDev

    jrDev

    Member

    Joined:
    Nov 5, 2008
    Messages:
    1,212
    I knew I read this somewhere, thanks.

    But that just makes the statement "Alpha Blending Kills" more puzzling...
  40. Mr Turnip Head

    Mr Turnip Head

    Member

    Joined:
    Feb 9, 2010
    Messages:
    34
    Like chaneya, I am also having issues with performance.

    If I run GLES 1.1 I get at least 40 fps, but as soon as I switch to GLES 2.0 this drops below 20. I am running it on a Motorola Xoom and have tried so many different combinations of settings to improve performance but don't seem to be getting anywhere.

    I was using the standard Unity Mobile Diffuse and Unity Unlit (Supports Lightmap) shaders. I have now changed all my materials to use the Madfinger Virtual Gloss Per-Vertex Shader (This seems to be the most commonly used shader in the demo scene) as a test. The stats on both theirs and my scene are similar, around 60 draw calls and similar vert count. However my scene still only just goes over 20 fps.

    Does anyone know what I could be missing?

    The Shadowgun demo never drops below 30fps on the Xoom.
  41. Mr Turnip Head

    Mr Turnip Head

    Member

    Joined:
    Feb 9, 2010
    Messages:
    34
    Like chaneya, I am also having issues with performance.

    If I run GLES 1.1 I get at least 40 fps, but as soon as I switch to GLES 2.0 this drops below 20. I am running it on a Motorola Xoom and have tried so many different combinations of settings to improve performance but don't seem to be getting anywhere.

    I was using the standard Unity Mobile Diffuse and Unity Unlit (Supports Lightmap) shaders. I have now changed all my materials to use the Madfinger Virtual Gloss Per-Vertex Shader (This seems to be the most commonly used shader in the demo scene) as a test. The stats on both theirs and my scene are similar, around 60 draw calls and similar vert count. However my scene still only just goes over 20 fps.

    Does anyone know what I could be missing?

    The Shadowgun demo never drops below 30fps on the Xoom.
  42. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Messages:
    11,043
    Alpha blending kills performance when you overlap too many in the same place, as it constantly redraws pixels to get the final pixel colour. You can test this by doing a scene where 1,000 blobs don't overlap, and a scene where they're draw on top of each other. It's bad but not terrible. Alpha testing on mobile is far worse (both are bad don't get me wrong) and will cripple your framerate.

    By bad, it's all relative to your game, device and resolution, but you should avoid alpha blend wherever possible as well as alpha test. There is only so much fill rate / overdraw to go around and this is a weak point in mobile.

    For the highest performance you should be using opaque shaders where possible.

    I can use a small blob with alpha test on mobile and it'll run 60 fps. That doesn't prove anything. Wait until you start testing on crud devices like ipad1 and iPhone 4. You can draw the screen about 3- 4 times before everything goes to hell.
    Last edited: Apr 25, 2012
  43. Mr Turnip Head

    Mr Turnip Head

    Member

    Joined:
    Feb 9, 2010
    Messages:
    34
    Projectors!

    I had a projector on my vehicle for a drop shadow and turning this off has got my fps up to over 50. I really didn't think it would be that expensive.
  44. maik

    maik

    Member

    Joined:
    Dec 4, 2011
    Messages:
    59
    Are there specific build settings for this project?
    When xcode installs this on the ipod touch (4th gen) it crashes...

    I only get this:
    2012-05-29 17:45:25.459 shadowgunTest[22172:707] -> registered mono modules 0x6233d4
    -> applicationDidFinishLaunching()
    Mono path[0] = '/var/mobile/Applications/5A7A1F42-6CC3-4312-B7C3-D16D2418D91C/shadowgunTest.app/Data/Managed'
    PlayerConnection::Initialize
    PlayerConnection constructor
    Playerconnection 3
    Timed out. Continuing without host connection.
    * Assertion: should not be reached at tramp-arm.c:724
  45. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Messages:
    11,043
    its only meant to learn from I think, its ripped out the final game. That it compiles at all is decent hehe
  46. maik

    maik

    Member

    Joined:
    Dec 4, 2011
    Messages:
    59
    I solved it :p

    It runs perfectly (30+ fps) on ipod touch 4th gen and ipad 1
  47. gargam

    gargam

    New Member

    Joined:
    Jun 14, 2012
    Messages:
    1
    Hello everyone.

    First I have to thank the team for giving away freely this bundle of incredible shaders that you could easily sell for 50-70 $ on the asset store.

    Since I am creating a huge unity environnement (outside), I found your ideas and shaders quite interesting for optimisation, even if I design it for computers instead of mobiles. However I have 2 questions for you if you can answer, I'd be grateful.

    1. How do you actually use the BRDFLit shader for characters ? I can see the common diffuse and normal map. But the last map seems to interact quite stangely with the bumpiness and shininess of the body. If you can give further explanations...

    2.You might not be familiar with it, but I really need a solution to improve performances with grass. Built-in solution won't make it : it really is fps-killing, and draw calls rise really fast. If you have any ideas for this, I'll take it;


    Thank you again and looking further for your next-gen games on my iphone ;)
  48. Eyeofgod

    Eyeofgod

    Member

    Joined:
    Jun 25, 2010
    Messages:
    110
    Can anyone upload the project again. The link seems to be broken
  49. moctezumagames

    moctezumagames

    New Member

    Joined:
    Jun 9, 2009
    Messages:
    395
    Thank you for the resource.
    Works perfect on my Win7 Unity 3.5.0f5 Pro.
  50. kurylo3d

    kurylo3d

    Member

    Joined:
    Nov 7, 2009
    Messages:
    872
    Im not sure if this question was asked, but what is better for performance in a decal transparent shader. cutout? or normal transparency. What is better for mobile?