Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Is this surface shader too heavy for mobile device?

Discussion in 'Shaders' started by Immortalis94, Jun 8, 2018.

  1. Immortalis94

    Immortalis94

    Joined:
    Feb 22, 2017
    Posts:
    11
    I am having problems with thermal throttling on my Samsung S8+ (It is tt for sure cause when i cool the device i don't have fps drop). I am using Beautify PP and default anti-aliasing. Rendering of the scene takes between 70-80 draw-calls where :
    - 1 Clear
    - ~50 Scene objects
    - 12 UI
    - 15 Post-Processing
    - 1 AA
    I am using bellow shader on every object except on shadow plane where i use unlit-transparent and glass transparent surface shader(I have 1 shadowplane with texture and 2 planes for glass). No shadows in the scene and only 1 directional light. I baked shadows and put it on a plane as a texture.
    Scene has 27k triangles in total (38k verts), using 3 instances of the mentioned shader 1 for the floor, 1 for the bottom part of the box and 1 for the top part. Scene is rendered in 1080p resolution with framerate of 60. Instancing is enabled and all materials use 2048 textures. I hope someone can help :)

    Shader "Custom/Mobile/DoubleSurface Bump" {
    Properties {
    _CombTex ("SurfaceMask(R) Occlusion(G) Map", 2D) = "white" {}
    _BumpMap ("Normal Map", 2D) = "bump" {}

    _AlbedoColor1 ("Color 1", Color) = (1, 1, 1, 1)
    _Metallic1 ("Metallic", Range(0,1)) = 0.0
    _Glossiness1 ("Smoothness", Range(0,1)) = 0.5
    _AlbedoColor2 ("Color 2", Color) = (1, 1, 1, 1)
    _Metallic2 ("Metallic", Range(0,1)) = 0.0
    _Glossiness2 ("Smoothness", Range(0,1)) = 0.5
    _OcclusionStrength ("Occlusion Strength", Range(0, 1)) = 1
    _OcclusionMultiplier ("Occlusion Multiplier", Range(0, 1)) = 1
    }
    SubShader {
    Tags { "RenderType"="Opaque" }
    LOD 200

    CGPROGRAM
    #pragma surface surf Standard noshadow noforwardadd noambient interpolateview
    #pragma target 3.0

    sampler2D _CombTex;
    sampler2D _BumpMap;

    struct Input {
    float2 uv_CombTex;
    float2 uv_BumpMap;
    };

    fixed4 _AlbedoColor1;
    half _Metallic1;
    half _Glossiness1;
    fixed4 _AlbedoColor2;
    half _Metallic2;
    half _Glossiness2;
    half _OcclusionStrength;
    half _OcclusionMultiplier;

    void surf (Input IN, inout SurfaceOutputStandard o) {
    // Evaluating maps
    fixed4 comb = tex2D (_CombTex, IN.uv_CombTex);
    fixed3 normals = UnpackNormal(tex2D (_BumpMap, IN.uv_BumpMap));

    // Occlusion calculation
    half occlusion = pow (comb.g, _OcclusionStrength) * _OcclusionMultiplier;
    half difference = 1 - comb.r;

    o.Albedo = _AlbedoColor1 * comb.r + _AlbedoColor2 * difference;
    o.Metallic = _Metallic1 * comb.r + _Metallic2 * difference;
    o.Smoothness = _Glossiness1 * comb.r + _Glossiness2 * difference;
    o.Normal = normals;
    o_Occlusion = occlusion;
    o.Alpha = comb.a;
    }
    ENDCG
    }
    FallBack "Diffuse"
    }

    I made it this way cause all my objects r made from like 2 types of material, lets say matte black and gold so i use 1 texture for that, better than using 1 for albedo and other for metallness, occlusion etc.
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    1,384
    This is likely too heavy :)
    Also, which specific model of S8+ are you testing on?
     
  3. Immortalis94

    Immortalis94

    Joined:
    Feb 22, 2017
    Posts:
    11
    @aleksandrk SM-G955F and i am targeting high end devices :) any suggestions on this shader, is it better to use separate albedo map and dont do calculations this way or surface shader itself is heavy for mobile? :) This happens in the next scene too, i am using the same shaders and less draw calls but more triangles (40k triangles 40-50 drawcalls) and i am getting thermal throttling too :) An thanks for reply :)
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    8,678
    That shader is fine and isn't doing anything crazy. Like @aleksandrk said doing 15 post process passes on mobile may be way over budget.

    The thing is not all passes / draw calls are the same. A shader for an object on screen is only running once per pixel on screen that the object appears (it's actually more complicated than that, but close enough for this discussion). If you have multiple objects on screen using the same or similar material and they're all opaque, for the most part it's still just running the shader once per on screen pixel.

    Post process passes are running over the entire screen, so every single on screen pixel is running the shader for each pass. This is where things really get expensive on mobile. You could have 1000 more pass for small low poly rocks or something and it probably wouldn't change the framerate as much as 15 post process passes.
     
    Last edited: Jun 8, 2018
  5. Immortalis94

    Immortalis94

    Joined:
    Feb 22, 2017
    Posts:
    11
    Yeah, thanks @bgolus . I just wanted to know that shader is not the problem and yeah 15 pp passes is hell for mobile but i wanted to check with u guys just in case cause they say beautify is optimized for mobile :) Is there any way to do bloom in 1 or 2 passes or i should just forget about bloom and lens dirt on mobile?
     
  6. bart_the_13th

    bart_the_13th

    Joined:
    Jan 16, 2012
    Posts:
    445
    bloom need at least 3 pass afaik... one for filtering, one for horizontal blur and one for vertical blur...
    as for lens dirt, I think you can just fake it using UI or quads (or even particles) infront of camera?
     
unityunity