Search Unity

ShadowGun : Optimising for Mobile

Discussion in 'Editor & General Support' started by willgoldstone, Mar 30, 2012.

  1. yobuddy

    yobuddy

    Joined:
    Jul 4, 2012
    Posts:
    6
    thanx alot.
     
  2. Deleted User

    Deleted User

    Guest

    With Unity 3.5 I get warnings at build time (on Android) for any cutout shader that it may have poor performance on certain devices (Adreno...), so I avoid them.
     
  3. Colombu

    Colombu

    Joined:
    Aug 17, 2012
    Posts:
    1
    Hi there,

    thanks for the initiative to provide the scene.

    Ee are finalizing a game for mobile and we are having a hard time optimizing it.

    Running on the iPhone 3GS, in a scene with four characters, each with 200 poligos, 11 bones each, a scenario with 4000 polygons, all the texture are around 256x256, and the game runs at 15 ~ 12 fps.

    we do not know what else to do to optimize, since we take polygons, bones, decrease the resolution of all textures...There is nothing more to do.

    Any idea that can help us?
     
  4. YasanthaPrabath

    YasanthaPrabath

    Joined:
    Jul 2, 2010
    Posts:
    10
    can some one please explain how to use BRDFLit Shader
     
  5. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    1,646
    Might be a quirky question, but:
    Can these mobile shaders, etc (not the textures or models) also be used with windows/max/webplayer projects?
     
  6. ilya_ca

    ilya_ca

    Joined:
    Nov 19, 2011
    Posts:
    274
    Didn't work for me, all the materials are pink. Why would they save the project itself instead of making a package?
     
  7. detonator

    detonator

    Joined:
    Jul 15, 2012
    Posts:
    17
    For insert shaders in my project, i make unity package of ShadowGunSamplelevel and unity package of my project. Start new project, and add 2 packages to it. All work fine, no pink.
     
  8. Eizdieler

    Eizdieler

    Joined:
    Aug 13, 2010
    Posts:
    3
    Hi,

    can anyone help me ? If I apply the Virtual Gloss Per-Vertex Additive Shader, my object just turns black. Any ideas why this happens ? :(
    Thanks for help in advance !!!
     
  9. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Without having seen the package (will do soon) i'm assuming theres a funny looking square texture of shaded colours along with normal and diffuse maps

    You'll find an explanation of how to create them here: https://www.youtube.com/watch?v=_Y_0cgWu5bQ&feature=plcp
     
  10. Vanini

    Vanini

    Joined:
    Jan 8, 2013
    Posts:
    1
    Shadowgun has some very cool screen distortion effects. I'v found the blog that explains the manipulation part of the effect but it seem the most performance intensive part of the effect was the act of grabbing the screen image. Does anyone know how it was done in shadowgun or has other solutions. Thanks!
     
  11. jessica1986

    jessica1986

    Joined:
    Feb 7, 2012
    Posts:
    622
    What is the polygon size of shadowgun main character ??

    and what is the polygon size of those enemies ?

    Is there any similar kind of asset available with same quality and optimized for mobile ??
     
  12. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    320
    I downloaded the shadowgun demo and pressed play. The camera scrolled through the level and everything looked very nice and complete, nothing missing. Then I tried to rebake the lightmaps, just to see if I could get the same awesome lighting results.

    Beast lightmapper CRASHED.

    I am using Unity 3.5.7f6 and mac OSX v. 10.6.8

    Any idea what went wrong? If there are other files needed besides Assets, Library, and ProjectSettings, please let me know.

    I agree with others that a .unitypackage would be very useful.

    EDIT: Figured it out. Apparently it is not safe to just click "Bake Scene." I don't know why this button even exists-- it is a trap. Instead, select the Static geometry (Madfinger's demo scene nicely parents all the static geometry to an Empty, so you can just select that object,) and click Bake Selected.

    It gets slow during GI Calculation 5 of 5-- sometimes slower than the entire rest of the bake process put together-- but it does bake correctly and finish.
     

    Attached Files:

    Last edited: Jun 11, 2013
  13. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    914
    HELP~
     

    Attached Files:

  14. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    914
    Why the resource not update correct files???has almost pass half a year!!!SomeBody can upload the right package here??thank you in advance!
     
  15. gdg

    gdg

    Joined:
    Jul 8, 2013
    Posts:
    9
    It worked fine for me, the pink unlinked materials got linked after pasting the assets folder at step 4
     
  16. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    914
    hi,gdg,
    Can you upload you right package here,thank you very much!
     
  17. TriplePAF

    TriplePAF

    Joined:
    Aug 19, 2009
    Posts:
    246
    Hello,

    I'm currently trying to understand the cubmap environment shader. Especially this line:

    Code (csharp):
    1.  
    2. c.xyz += texCUBE(_EnvTex,i.refl) * c.a;
    3.  
    It takes the alpha value from the main texture and multiplies it. Correct? In my case it doesn't work. What do I have to put inside the alpha channel to make it work (or is it using just the main textures alpha slider to set a value and that's it). The texture compression from that picture is set to rgba.


    Is there a considerable performance overhead if I change it to this:

    Code (csharp):
    1.  
    2. c.xyz += texCUBE(_EnvTex,i.refl).rgb * _Spread;
    3.  

    Kind regards,


    Peter Fonk.


    -------------------------------------------------------------------------------------------------------------------------

    Code (csharp):
    1.  
    2.  
    3. Shader "MADFINGER/Environment/Cube env map (Supports Lightmap)" {
    4.  
    5. Properties
    6. {
    7.         _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    8.         _EnvTex ("Cube env tex", CUBE) = "black" {}
    9.         _Spread("Spread", Range (0.1,0.5)) = 0.5
    10. }
    11.  
    12. SubShader {
    13.         Tags { "RenderType"="Opaque" "LightMode"="ForwardBase"}
    14.         LOD 100
    15.        
    16.        
    17.        
    18.         CGINCLUDE
    19.         #include "UnityCG.cginc"
    20.        
    21.         sampler2D _MainTex;
    22.         samplerCUBE _EnvTex;
    23.        
    24.         #ifndef LIGHTMAP_OFF
    25.         float4 unity_LightmapST;
    26.         sampler2D unity_Lightmap;
    27.         #endif
    28.  
    29.         float3 _SpecColor;
    30.         float _Shininess;
    31.         float _Spread;
    32.        
    33.         struct v2f {
    34.                 float4 pos : SV_POSITION;
    35.                 float2 uv : TEXCOORD0;
    36.                 #ifndef LIGHTMAP_OFF
    37.                 float2 lmap : TEXCOORD1;
    38.                 #endif
    39.                 float3 refl : TEXCOORD2;
    40.         };
    41.  
    42.        
    43.         v2f vert (appdata_full v)
    44.         {
    45.                 v2f o;
    46.                
    47.                 o.pos        = mul(UNITY_MATRIX_MVP, v.vertex);
    48.                 o.uv                = v.texcoord;
    49.                
    50.                 float3 worldNormal = mul((float3x3)_Object2World, v.normal);
    51.                 o.refl = reflect(-WorldSpaceViewDir(v.vertex), worldNormal);
    52.                 o.refl.x = -o.refl.x;
    53.                
    54.                 #ifndef LIGHTMAP_OFF
    55.                 o.lmap = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
    56.                 #endif
    57.                
    58.                
    59.                 return o;
    60.         }
    61.         ENDCG
    62.  
    63.  
    64.         Pass {
    65.                 CGPROGRAM
    66.                 #pragma vertex vert
    67.                 #pragma fragment frag
    68.                 #pragma fragmentoption ARB_precision_hint_fastest                
    69.                 fixed4 frag (v2f i) : COLOR
    70.                 {
    71.                         fixed4 c         = tex2D (_MainTex, i.uv.xy);
    72.                        
    73.                         #ifndef LIGHTMAP_OFF
    74.                         c.xyz *= DecodeLightmap (tex2D(unity_Lightmap, i.lmap));
    75.                         #endif
    76.                        
    77.                         c.xyz += texCUBE(_EnvTex,i.refl) * c.a;
    78.                        
    79.                         return c;
    80.                 }
    81.                 ENDCG
    82.         }        
    83. }
    84. }
    85.  
    86.  
     
  18. dbarth

    dbarth

    Joined:
    Sep 10, 2013
    Posts:
    6
    The videos for the blog post no longer seem to be up/working. Can we get that fixed?
     
  19. philwinkel

    philwinkel

    Joined:
    Jun 6, 2013
    Posts:
    298
    was just thinking the same thing, wtf.. upload to youtube.
     
  20. pArmitage

    pArmitage

    Joined:
    Apr 21, 2013
    Posts:
    1
    Project doesn't work, at least for U4Indie.
     
  21. Loic Joint

    Loic Joint

    Joined:
    Feb 23, 2012
    Posts:
    45
    Yes please, upload the video on youtube or other. This page is very important for many developers.
     
  22. guppyd

    guppyd

    Joined:
    Jan 28, 2013
    Posts:
    2
    I cleared the lightmap and rebuild it again without any change, but found the uv packing is different.
    Just like the pictures attached below.
    First one is the original litmap. (size is 1024*512)
    $擷取.JPG
    Second one is baked by myself. (size is 1024*1024)
    $擷取2.JPG

    Do you guys do some tricks in Beast? :p
     
  23. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,106
    there were mention of some Tegra 3 optimizations coming (from unite 2011?), and a BRDF asset was going to be added to the store.. did any of those make it or just included in the sample project?
     
  24. ThisIsSparta

    ThisIsSparta

    Joined:
    May 4, 2014
    Posts:
    142
    Well this is quite impressive and I'm watching it and studiyng from a coupe of days...2 questions:

    when I run the demo the characters don't seem to be affected by the brdf shader (and btw on the interview they said the shader is integrated in unity but I can't find it)

    someone can give further explanation about a brdf light shader? ty
     
  25. chelnok

    chelnok

    Joined:
    Jul 2, 2012
    Posts:
    673
    bumb (request for working package)
     
  26. rezilausiv

    rezilausiv

    Joined:
    Nov 18, 2010
    Posts:
    126
    Hi

    With final version of "Shadowgun" for Android (which you can download in the Play Store for free), the Bluetooth game controller "idroid" from Snakebyte perfectly works as expected: > The left joystick = moving around in the scene. > The right joystick = looking around in the scene.

    Well if you make a new Unity project with a FPS in the scene and export this to Android, the Unity Input Manager is set by default that the left joystick works fine for moving within the scene. But the right joystick isn't working at all.

    Therefore, can anyone tell us here in this community how to set the Unity Input Manager to get the right joystick to look around in the scene?

    And maybe some one also knows how to manage all the buttons of that Android standard game controller too?

    Android devices comes more and more to the market as an alternative for game devices like Sony Playstation@Mobile. Look at the new Samsung Tap Pro 8.4 which has a superb display and 3D performance too..

    However, for games like Shadowgun, game controllers like idroid from Snakebyte are the best way to direct interact with those games.

    To know how to manage the Unity Input Manager in this case is a key knowledge which should described in the Unity documentation, but isn't...

    Thanks for discover this, for all of us
    Roman
    rezilausiv >< visualizer
     
    Last edited: May 30, 2014
  27. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,869
    Hi there. for anyone having troubles with getting the right stick to work, you don't use the x and y axis, they are the left stick. instead, use the other axis marked in the editor, and swap around until it works! :) And yes, this isn't very well documented, but after seeing it, it's pretty self-explanatory: use x and y for left stick, use a pair of one of the others for right stick. (this can differ, and is usually on 3rd and 4th axis. maybe 5 even!)

    And I actually made a few modifications to the BRDF:
    BRDFFakeScreen.png
    What do you think? I did this so it would work correctly with shadow mapping without it doing the whole 'shadow acne' thing it gets. I also did this so I could get linear-space-like shading in unity free.

    I also set it up to get it working with dual lightmaps, so that's covered too. overall, the graphics thread runs for 0.7-0.2 milliseconds each frame render.
     
  28. Soy13

    Soy13

    Joined:
    Oct 28, 2013
    Posts:
    2
    Ty vry much MadFinger Games!!! Great work and thanks again for the shaders.
     
  29. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    239
    Code (CSharp):
    1.  
    2. Shader "MADFINGER/Transparent/Blinking GodRays Billboarded" {
    3.  
    4. Properties {
    5.     _MainTex ("Base texture", 2D) = "white" {}
    6.     _FadeOutDistNear ("Near fadeout dist", float) = 10  
    7.     _FadeOutDistFar ("Far fadeout dist", float) = 10000  
    8.     _Multiplier("Color multiplier", float) = 1
    9.     _Bias("Bias",float) = 0
    10.     _TimeOnDuration("ON duration",float) = 0.5
    11.     _TimeOffDuration("OFF duration",float) = 0.5
    12.     _BlinkingTimeOffsScale("Blinking time offset scale (seconds)",float) = 5
    13.     _SizeGrowStartDist("Size grow start dist",float) = 5
    14.     _SizeGrowEndDist("Size grow end dist",float) = 50
    15.     _MaxGrowSize("Max grow size",float) = 2.5
    16.     _NoiseAmount("Noise amount (when zero, pulse wave is used)", Range(0,0.5)) = 0
    17.     _VerticalBillboarding("Vertical billboarding amount", Range(0,1)) = 1
    18.     _ViewerOffset("Viewer offset", float) = 0
    19.     _Color("Color", Color) = (1,1,1,1)
    20. }
    21.  
    22.    
    23. SubShader {
    24.    
    25.    
    26.     Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    27.    
    28.     Blend One One
    29.     Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) }
    30.    
    31.     LOD 100
    32.    
    33.     CGINCLUDE  
    34.     #include "UnityCG.cginc"
    35.     sampler2D _MainTex;
    36.    
    37.     float _FadeOutDistNear;
    38.     float _FadeOutDistFar;
    39.     float _Multiplier;
    40.     float    _Bias;
    41.     float _TimeOnDuration;
    42.     float    _TimeOffDuration;
    43.     float _BlinkingTimeOffsScale;
    44.     float _SizeGrowStartDist;
    45.     float _SizeGrowEndDist;
    46.     float _MaxGrowSize;
    47.     float _NoiseAmount;
    48.     float _VerticalBillboarding;
    49.     float _ViewerOffset;
    50.     float4 _Color;
    51.    
    52.    
    53.     struct v2f {
    54.         float4    pos    : SV_POSITION;
    55.         float2    uv        : TEXCOORD0;
    56.         fixed4    color    : TEXCOORD1;
    57.     };
    58.  
    59.     void CalcOrthonormalBasis(float3 dir,out float3 right,out float3 up)
    60.     {
    61.         up     = abs(dir.y) > 0.999f ? float3(0,0,1) : float3(0,1,0);      
    62.         right = normalize(cross(up,dir));      
    63.         up    = cross(dir,right);  
    64.     }
    65.  
    66.     float CalcFadeOutFactor(float dist)
    67.     {
    68.         float        nfadeout    = saturate(dist / _FadeOutDistNear);
    69.         float        ffadeout    = 1 - saturate(max(dist - _FadeOutDistFar,0) * 0.2);
    70.  
    71.         ffadeout *= ffadeout;
    72.        
    73.         nfadeout *= nfadeout;
    74.         nfadeout *= nfadeout;
    75.        
    76.         nfadeout *= ffadeout;
    77.  
    78.         return nfadeout;
    79.     }
    80.    
    81.     float CalcDistScale(float dist)
    82.     {
    83.         float        distScale    = min(max(dist - _SizeGrowStartDist,0) / _SizeGrowEndDist,1);
    84.        
    85.         return distScale * distScale * _MaxGrowSize;
    86.     }
    87.    
    88.    
    89.     v2f vert (appdata_full v)
    90.     {
    91.         v2f         o;
    92.        
    93.                
    94.         #if 0
    95.         // cheap view space billboarding
    96.         float3    centerOffs        = float3(float(0.5).xx - v.color.rg,0) * v.texcoord1.xyy;
    97.         float3    BBCenter        = v.vertex + centerOffs.xyz;  
    98.         float3    viewPos            = mul(UNITY_MATRIX_MV,float4(BBCenter,1)) - centerOffs;
    99.         #else
    100.        
    101.         float3    centerOffs        = float3(float(0.5).xx - v.color.rg,0) * v.texcoord1.xyy;
    102.         float3    centerLocal    = v.vertex.xyz + centerOffs.xyz;
    103.         float3    viewerLocal    = mul(_World2Object,float4(_WorldSpaceCameraPos,1));          
    104.         float3    localDir            = viewerLocal - centerLocal;
    105.                
    106.         localDir[1] = lerp(0,localDir[1],_VerticalBillboarding);
    107.        
    108.         float        localDirLength=length(localDir);
    109.         float3    rightLocal;
    110.         float3    upLocal;
    111.        
    112.         CalcOrthonormalBasis(localDir / localDirLength,rightLocal,upLocal);
    113.  
    114.         float        distScale        = CalcDistScale(localDirLength) * v.color.a;      
    115.         float3    BBNormal        = rightLocal * v.normal.x + upLocal * v.normal.y;
    116.         float3    BBLocalPos    = centerLocal - (rightLocal * centerOffs.x + upLocal * centerOffs.y) + BBNormal * distScale;
    117.  
    118.         BBLocalPos += _ViewerOffset * localDir;
    119.  
    120.         #endif
    121.        
    122.         float        time             = _Time.y + _BlinkingTimeOffsScale * v.color.b;              
    123.         float        fracTime    = fmod(time,_TimeOnDuration + _TimeOffDuration);
    124.         float        wave            = smoothstep(0,_TimeOnDuration * 0.25,fracTime)  * (1 - smoothstep(_TimeOnDuration * 0.75,_TimeOnDuration,fracTime));
    125.         float        noiseTime    = time *  (6.2831853f / _TimeOnDuration);
    126.         float        noise            = sin(noiseTime) * (0.5f * cos(noiseTime * 0.6366f + 56.7272f) + 0.5f);
    127.         float        noiseWave    = _NoiseAmount * noise + (1 - _NoiseAmount);
    128.    
    129.         wave = _NoiseAmount < 0.01f ? wave : noiseWave;
    130.         wave += _Bias;
    131.        
    132.         o.uv        = v.texcoord.xy;
    133.         o.pos    = mul(UNITY_MATRIX_MVP, float4(BBLocalPos,1));
    134.         o.color    = CalcFadeOutFactor(localDirLength) * _Color * _Multiplier * wave;
    135.                        
    136.         return o;
    137.     }
    138.     ENDCG
    139.  
    140.  
    141.     Pass {
    142.         CGPROGRAM
    143.         #pragma vertex vert
    144.         #pragma fragment frag
    145.         #pragma fragmentoption ARB_precision_hint_fastest      
    146.         fixed4 frag (v2f i) : COLOR
    147.         {      
    148.             return tex2D (_MainTex, i.uv.xy) * i.color;
    149.         }
    150.         ENDCG
    151.     }  
    152. }
    153.  
    154.  
    155. }
    156.  

    i am trying to use this shader on a simple quad to make it billboard but i feel this shader requires my mesh to be in certain condition(May be with some vertex color and modified normals).
    This shader works fine with the mesh in sample level but i cant make it work with my mesh.
    Can you guys please help me with setting up the mesh so that i can use this on my mesh
     
  30. Quadropups

    Quadropups

    Joined:
    May 23, 2017
    Posts:
    14
    Sorry for bumping this old topic but I'm new to Unity development and just wanted to say how helpful this example project file was to me.
    Right off the bat I attempted to port the Survival Shooter tutorial game to the android platform and fps was abysmal so I had to figure out what I'm doing wrong but it turned out there are so many way to screw up that I was clueless where to even start.

    But since this example is 5 years old now I wanted to ask if there's any more examples like this? Ones that are using some of the more modern techniques of optimization for example.
    Thanks in advance!
     
  31. MichiealO

    MichiealO

    Joined:
    Jul 7, 2013
    Posts:
    61
    I realize that this is an "Ancient Topic" and I'm not trying to necro it... but.... I just downloaded the sample project because unity showed it up on the related blog posts, and I clicked it to check it out.
    So, I found out quickly that for Unity 2018.2.6 that everything is broken. Could someone that got it working just put the thing in a .UnityPackage file somewhere so that we (me and others that stumble on it) aren't pulling our hair out trying to figure out all of the mappings to reassemble that project? I'd love to see it. But, all of the materials are pink, and the scene only contains lights.
    Thank you!!!!!!
     
  32. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,869
    Could very well be the ShadowGun pseudo-BRDF is doing something that maybe the DX11 HLSL compiler isn't liking; check all the shaders have compiled without errors. (If you're not sure how to do that, I can look into it later when I'm home if you like)
     
unityunity