Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by EBhero · Aug 25, 2017 at 03:08 PM · androidshaderpc

Shader working on pc but not on Android

Hello there!

I am making a simple game where you orbit around earth and you look at it.

I downloaded a 3D model of Earth on the asset Store: https://www.assetstore.unity3d.com/en/#!/content/56841

It's neat, cities lights up when it's night time.

When the platform is pc, it works fine, but not when it's android. On android, night time 24/7

On PC: alt text

On Android: alt text

I know shaders works differently on Android that on PC. But I know sh*t about shaders. Here's the code in the shader:

 Shader "Custom/EarthShader 2"
 {
     Properties
     {
         _Color("Color", Color) = (1,1,1,1)
         _MainTex("Albedo (RGB)", 2D) = "white" {}
         _BumpMap("Bumpmap", 2D) = "bump" {}
         _Detail("Detail", 2D) = "black" {}
         _DetailIntensity("Detail Intensity", Range(0, 3)) = 0.0
         _SpecularTex("Specular (RGB)", 2D) = "black" {}
         _SpecularPower("Specular Power", Range(0, 8)) = 0.0
         _NightTex("Night Detail (RGB)", 2D) = "black" {}
         _NightIntensity("Night Detail Intensity", Range(0, 1)) = 0.0
         _NightTransitionVariable("Night Transition Variable", Range(1, 64)) = 4
         _Smoothness("Smoothness", Range(0,1)) = 0.5
         _RimColor("Rim Color", Color) = (0.26,0.19,0.16,0.0)
         _RimPower("Rim Power", Range(0.5, 64.0)) = 3.0
         _AtmosNear("Atmosphere Near Color", Color) = (0.1686275,0.7372549,1,1)
         _AtmosFar("Atmosphere Far Color", Color) = (0.4557808,0.5187039,0.9850746,1)
         _AtmosFalloff("Atmosphere Falloff", Range(0.1, 64)) = 12
     }
     SubShader
     {
         Tags{ "RenderType" = "Opaque" "Queue" = "Geometry" "IgnoreProjection" = "False" }
         LOD 200
 
         CGPROGRAM
 
         #pragma surface surf CustomLighting
         #pragma target 3.0
 
         sampler2D _MainTex;
         sampler2D _BumpMapTex;
         sampler2D _DetailTex;
         sampler2D _SpecularTex;
         sampler2D _NightTex;
 
         struct Input
         {
             fixed3 viewDir;
             fixed2 uv_MainTex;
             fixed2 uv_DetailTex;
         };
 
         struct SurfaceOutputStandardSpecularCustom
         {
             fixed3 Albedo;      // diffuse color
             fixed3 Specular;    // specular color
             fixed3 Normal;      // tangent space normal, if written
             fixed3 Emission;
             fixed Smoothness;    // 0=rough, 1=smooth
             fixed Occlusion;     // occlusion (default 1)
             fixed Alpha;        // alpha for transparencies
             fixed3 NightColor;
             fixed4 ExtraColor;
         };
 
         fixed4 _Color;
         fixed _Smoothness;
         fixed _DetailIntensity;
         fixed _SpecularPower;
         fixed _NightIntensity;
         fixed _NightTransitionVariable;
         fixed4 _RimColor;
         fixed _RimPower;
         fixed4 _AtmosNear;
         fixed4 _AtmosFar;
         fixed _AtmosFalloff;
 
         /*
         inline half4 LightingCustomLighting_PrePass(SurfaceOutputStandardSpecularCustom s, half4 light)
         {
             fixed spec = light.a * s.Smoothness;
             fixed4 c;
             c.rgb = (lerp(s.NightColor, s.Albedo * light.rgb * s.Specular.rgb * _SpecularPower, saturate(_NightTransitionVariable * light.a)));
             c.a = s.Alpha;
             return c;
         }
         */
 
         inline half4 LightingCustomLighting(SurfaceOutputStandardSpecularCustom s, fixed3 lightDir, fixed3 viewDir, fixed atten)
         {
             fixed3 h = normalize(lightDir + viewDir);
             fixed d = max(0, dot(s.Normal, lightDir));
             fixed diffuseMultiplier = d * atten;
             fixed nh = max(0, dot(s.Normal, h));
             fixed spec = pow(nh, 48.0) * s.Smoothness;
             fixed4 c;
             fixed3 dayColor = (s.Albedo * _LightColor0.rgb * diffuseMultiplier) + (_LightColor0.rgb * spec * _SpecularPower);
             c.rgb = lerp(s.NightColor, dayColor, saturate(_NightTransitionVariable * diffuseMultiplier));
             c.a = s.Alpha;
             c.rgb += (s.ExtraColor.rgb * atten * nh * s.ExtraColor.a);
 
             return c;
         }
 
         inline fixed3 AtmosphereColor(Input IN)
         {
             fixed4 Fresnel1 = fixed4(0, 0, 1, 1);
             fixed4 Fresnel2 = (1.0 - dot(normalize(fixed4(IN.viewDir.xyz, 0)), normalize(Fresnel1))).xxxx;
             fixed4 Pow0 = pow(Fresnel2, _AtmosFalloff);
             fixed4 Saturate0 = saturate(Pow0);
             fixed4 Lerp0 = lerp(_AtmosNear, _AtmosFar, Saturate0);
             fixed4 color = Lerp0 * Saturate0;
 
             return color;
         }
 
         void surf(Input IN, inout SurfaceOutputStandardSpecularCustom o)
         {
             fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
             o.NightColor = tex2D(_NightTex, IN.uv_MainTex).rgb * _NightIntensity;
             fixed maxNight = min(1, o.NightColor.g + 0.8);
             o.NightColor *= pow(maxNight, 4);
             o.Albedo = c.rgb += (tex2D(_DetailTex, IN.uv_DetailTex).rgb * _DetailIntensity);
             o.Normal = UnpackNormal(tex2D(_BumpMapTex, IN.uv_MainTex));
             o.Specular = tex2D(_SpecularTex, IN.uv_MainTex);
             o.Smoothness = _Smoothness;
             o.Alpha = c.a;
             fixed rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));
             o.ExtraColor = fixed4(_RimColor.rgb * pow(rim, _RimPower) + AtmosphereColor(IN), 2);
         }
 
         ENDCG
     }
     FallBack "Diffuse"
 }

If you ever know what can't work on Android in the shader, tell me please!

Thanks in advance

pc.png (232.9 kB)
android.png (174.3 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by FortisVenaliter · Aug 25, 2017 at 03:25 PM

Shaders have an statement execution limit. On mobile, those limits are much stricter.

That shader you posted is a behemoth. That thing probably won't even run on some older PCs.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image EBhero · Aug 25, 2017 at 03:31 PM 0
Share

Oh. Well thanks! I'll find something else!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

174 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Shader shows black lines from occluded object 1 Answer

Why does this shader give different result Editor/ Android? 0 Answers

Alternative Android Shader for Fragment? 0 Answers

Why Do Android Devices Hate This Shader? 2 Answers

Screen Orientation debug.Log 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges