Unity Community


Page 1 of 4 123 ... LastLast
Results 1 to 20 of 73
  1. Unity Fanboy



    Location
    London, UK
    Posts
    455

    ShadowGun : Optimising for Mobile

    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/...-sample-level/

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


  2. Location
    Italy
    Posts
    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 by Andrea Monzini; 03-30-2012 at 08:31 AM.


  3. Location
    Tulsa, OK
    Posts
    85
    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 by chaneya; 03-30-2012 at 10:30 AM.



  4. Posts
    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.

  5. Super Moderator
    Location
    Great Britain
    Posts
    9,643
    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.
    Currently working with Sony on our new
    PS4 and Vita game in Unity!

    This post is not representative of Simian Squared Ltd

  6. Super Moderator
    Location
    Great Britain
    Posts
    9,643
    Quote Originally Posted by chaneya View Post
    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
    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.
    Currently working with Sony on our new
    PS4 and Vita game in Unity!

    This post is not representative of Simian Squared Ltd


  7. Posts
    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.


  8. Location
    Tulsa, OK
    Posts
    85
    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:  
    1. hader "Mobile/BackgroundQueueAdditive"
    2. {
    3.     Properties
    4.     {
    5.         _Color ("Main Color", Color) = (.5,.5,.5,0)
    6.        _EnvMap ("EnvMap", 2D) = "black" { TexGen SphereMap }
    7.     }
    8.    
    9.     Category
    10.     {
    11.         Tags { "Queue"="Background" "IgnoreProjector" = "True" "RenderType"="Background"}
    12.         //SeparateSpecular On
    13.         Lighting Off
    14.         Zwrite off
    15.         Fog { Mode Off }
    16.         //Ztest Always
    17.         //Cull off //Will Show back thorugh front
    18.        
    19.         Blend One One                       // additive
    20.         //Blend One OneMinusSrcColor          // soft additive
    21.         //Blend SrcAlpha OneMinusSrcAlpha     // real alpha blending
    22.  
    23.         SubShader
    24.         {
    25.           Pass
    26.           {
    27.             SetTexture [_EnvMap]
    28.             {
    29.                 combine texture
    30.             }
    31.             SetTexture [_EnvMap]
    32.             {
    33.                 constantColor [_Color]
    34.                 Combine previous * constant DOUBLE, previous * constant
    35.             }  
    36.           }
    37.       }
    38.    }
    39. }
    Last edited by chaneya; 04-01-2012 at 01:12 PM.

  9. Super Moderator
    Location
    Great Britain
    Posts
    9,643
    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).
    Currently working with Sony on our new
    PS4 and Vita game in Unity!

    This post is not representative of Simian Squared Ltd


  10. Location
    San Francisco, CA
    Posts
    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.


  11. Location
    Unity Technologies HQ, Copenhagen
    Posts
    3,514
    @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?
    Joachim Ante


  12. Location
    Tulsa, OK
    Posts
    85
    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


  13. Posts
    40
    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


  14. Location
    Italy
    Posts
    447
    Quote Originally Posted by tristamus View Post
    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.
    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 by Andrea Monzini; 03-31-2012 at 04:59 AM.


  15. Location
    Canandaigua, NY
    Posts
    498
    Assets are broken. Only a Shader folder and no meshes. They all show as red in the hierarchy.

    Gary
    Imagine. Inspire. Innovate.

    Game Designer / World Builder / 3D Artist
    www.garyhaus.com


  16. Location
    Italy
    Posts
    447
    Quote Originally Posted by garyhaus View Post
    Assets are broken. Only a Shader folder and no meshes. They all show as red in the hierarchy.

    Gary
    I agree, i have tried with Snow Leopard too, and i have the same problems.
    The project works with Mac or only with Windows?


  17. Location
    Italy
    Posts
    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 by Andrea Monzini; 03-31-2012 at 06:03 AM.


  18. Location
    Hessen, Germany
    Posts
    59
    @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:  
    1. Shader "Mobile/BackgroundQueueAdditive2"
    2. {
    3. Properties {
    4.         _Color ("Main Color", Color) = (0.5, 0.5, 0.5, 0)
    5.         _EnvTex ("EnvMap", 2D) = "black" {}                                                  
    6.     }
    7.     SubShader {
    8. //      Tags { "Queue"="Background" "IgnoreProjector" = "True" "RenderType"="Background"}
    9.         Tags { "Queue"="Transparent" "IgnoreProjector" = "True" "RenderType"="Transparent"}
    10.        
    11.         Pass{
    12. //          Alphatest Greater 0
    13. //          Cull Off
    14.             ZWrite Off
    15.  
    16. //          Blend SrcAlpha OneMinusSrcAlpha     // Alpha blending
    17.             Blend One One                       // Additive
    18. //          Blend One OneMinusDstColor          // Soft Additive
    19. //          Blend DstColor Zero                 // Multiplicative
    20. //          Blend DstColor SrcColor             // 2x Multiplicative
    21.            
    22.             CGPROGRAM
    23.             #pragma vertex vert
    24.             #pragma fragment frag
    25.             #include "UnityCG.cginc"
    26.            
    27.             //Declare Properties
    28.             sampler2D _EnvTex;
    29.             fixed4 _Color;
    30.             //------------------
    31.            
    32.             //Declare structures
    33.             struct v2f{
    34.                 float4 pos : SV_POSITION;
    35.                 //half4 color : COLOR0;
    36.                 //half2 uv : TEXCOORD1;
    37.                 half2 uvSphere : TEXCOORD0;
    38.             };
    39.             struct appdata_custom {
    40.                 float4 vertex : POSITION;
    41.                 //float4 tangent : TANGENT;
    42.                 half3 normal : NORMAL;
    43.                 //half4 texcoord : TEXCOORD0;
    44.                 //half4 color : COLOR;
    45.             };
    46.             //--------------------
    47.            
    48.             half4 _EnvTex_ST;;
    49.            
    50.             //vertex shader
    51.             v2f vert (appdata_custom v)
    52.             {
    53.                 v2f o;
    54.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    55.                
    56.                 //Sphere mapping ported from http://www.ozone3d.net/tutorials/glsl_texturing_p04.php
    57.                 half3 u = normalize( mul(UNITY_MATRIX_MV, v.vertex));
    58.                 half3 n = mul(UNITY_MATRIX_IT_MV, float4(v.normal.xyz,0));
    59.                 half3 r = reflect( u, n);
    60.                
    61.                 half m = 2.0 * sqrt( r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0) );
    62.                 o.uvSphere = half2(r.x/m+0.5, r.y/m+0.5);
    63.                 //---------------
    64.                                
    65.                 //o.uv = TRANSFORM_TEX (v.texcoord, _EnvTex);;
    66.                 //o.color = v.color;
    67.                 return o;
    68.             }
    69.            
    70.             //fragment shader
    71.             fixed4 frag (v2f i) : COLOR {
    72.                 fixed4 tex = tex2D(_EnvTex, i.uvSphere) * _Color;
    73.                 tex.rgb *= 2;   //double the color values, but leave alpha untouched
    74.                 return tex;
    75.             }
    76.             ENDCG
    77.            
    78.         }
    79.     }
    80. }

    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 by vwekker; 04-01-2012 at 01:22 PM. Reason: Enabled "ZWrite Off", and alpha cleanup, incorporated tips from chaneya


  19. Location
    Tulsa, OK
    Posts
    85
    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 Images  

Page 1 of 4 123 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •