• 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 Filipp_Kuzmenko · Jul 23, 2017 at 07:49 AM · androidunity 5shaderandroid buildshader writing

My simple shader not working correctly on Android

My simple shader not working correctly on Android platform. How to fix it? alt textPC-Editoralt textAndroid bulid

 Shader "Car" {
     Properties {
         _Color ("Color", Color) = (1,1,1,1)
         _MainTex("Albedo (RGBA)", 2D) = "white" {}
         _NormalTex("Normalmap", 2D) = "bump" {}
         _NormalScale("Scale", Range(-1, 1)) = 1.0
         _Smoothness ("Smoothness", Range(0.01, 1.0)) = 0.5
         _Cubemap ("Reflections", CUBE) = "" {}
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         LOD 200
         
         CGPROGRAM
         #pragma surface surf Custom
         #pragma target 2.0
 
         sampler2D _MainTex;
         sampler2D _NormalTex;
         samplerCUBE _Cubemap;
 
         struct Input {
             float2 uv_MainTex;
             float2 uv_NormalTex;
             float3 worldRefl;
             INTERNAL_DATA
         };
 
         half _NormalScale;
         half _Smoothness;
         fixed4 _Color;
 
         UNITY_INSTANCING_CBUFFER_START(Props)
             // put more per-instance properties here
         UNITY_INSTANCING_CBUFFER_END
 
         fixed4 LightingCustom(SurfaceOutput s, fixed3 lightDir, half3 viewDir, fixed atten)
         {
             float NdotL = max(0, dot(s.Normal, lightDir));
             float3 halfVector = normalize(lightDir + viewDir);
             float NdotH = max(0, dot(s.Normal, halfVector));
             float spec = pow(NdotH, _Smoothness * 500.0) *  min(_Smoothness * 2.0, 1);
             float4 c;
             c.rgb = (s.Albedo * _LightColor0.rgb * (NdotL * 0.8 + 0.2)) + (_LightColor0.rgb * spec) * atten;
             c.a = s.Alpha;
             return c;
         }
 
         half3 UnpackNormalScale(half4 packednormal, half Scale)
         {
             half3 normal;
             normal.xy = (packednormal.wy * 2 - 1);
             normal.xy *= Scale;
             normal.z = sqrt(1.0 - saturate(dot(normal.xy, normal.xy)));
             return normal;
         }
 
         void surf (Input IN, inout SurfaceOutput o) 
         {
             o.Albedo = lerp(tex2D (_MainTex, IN.uv_MainTex),  _Color, 1.0 - tex2D(_MainTex, IN.uv_MainTex).a).rgb;
             o.Normal = UnpackNormalScale(tex2D(_NormalTex, IN.uv_NormalTex), _NormalScale);
             o.Specular = _Smoothness;
             o.Emission = texCUBE(_Cubemap, WorldReflectionVector(IN, o.Normal)).rgb * o.Specular * 0.25;
         }
         ENDCG
     }
     FallBack "Diffuse"
 }


android.jpg (27.9 kB)
pc-editor.jpg (45.6 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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

221 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 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

Pink custom shader on Android build 0 Answers

Why an Android build doesnt make a _Data file. 1 Answer

How do I Optimize Resources/Unity_Builtin_Extra 2 Answers

Input Fields not actually taking in user data on android build 0 Answers

Realistic metalic on mobile 0 Answers


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