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 AustinDrozin · Aug 04, 2016 at 05:36 AM · androidshadershadersmobileleaves

Foliage shader makes objects invisible on Android Build

In the unity Editor, my leaves show up perfectly fine in the scene. I have a shader on them that makes them look very soft and also has a slight wind animation/displacement.

When I build for Android, the leaves are completely gone. No shadows or planes are even visible.

Is there anything not compatible with Android written in the code? Here is my shader code:

 Shader "Foliage/LeavesEditing(Wind.Transulence.Fresnel)" 
     {
         Properties 
         {
         [Header(Typical Controls)]_Color ("Main Color", Color) = (1,1,1,1)
         _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
     
         _Normal ("Normal", 2D) = "bump" {}
         _BumpPower ("Normal Power", Range (0.01, 2)) = 1 //added slider control for Normal strength
     
         [Header(Animation Controls)] _VertexWeight ("Vertex Weight", 2D) = "weight" {} //added new weight map slot to drive vertex animation
         [HideInInspector]_OcclusionMap("Occlusion", 2D) = "white" {}
         [HideInInspector]_OcclusionStrength ("Occlusion Strength", Range(0.01,1)) = 1
         _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
         //_ShakeDisplacement ("Displacement", Range (0, 1.0)) = 1.0
         _ShakeTime ("Animation Time", Range (0, 1.0)) = .25
         _ShakeWindspeed ("Wind Speed", Range (0, 1.0)) = .3
         _ShakeBending ("Displacement", Range (0, 1.0)) = 0.2
         [Space(10)]
             
         [Header(Additional Coloring)] _TopDirection ("Coloring Direction", Vector) = (0,1.5,0)
         _TopLevel ("Coloring Level", Range(0,1) ) = 0.2
         _TopDepth ("Coloring Depth", Range(0,1)) = 0.7
         _TopColor ("Coloring Color", Color) = (1,0.894,0.710,1.0) //orange
     
         }
      
         SubShader 
         {
             Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
             LOD 400 //Change if performance acts up?
             Cull [_Cull]
     
             CGPROGRAM
             #pragma target 3.0
             #pragma surface surf Lambert alphatest:_Cutoff vertex:vert addshadow
              
             sampler2D _MainTex;
             sampler2D _Normal;
             sampler2D _VertexWeight;
             sampler2D _OcclusionMap;
     
             fixed4 _Color;
             fixed _BumpPower;
             fixed _OcclusionStrength;
     
             float _ShakeDisplacement;
             float _ShakeTime = 0.1;
             float _ShakeWindspeed;
             float _ShakeBending;
     
             float _TopLevel;
             float4 _TopColor;
             float4 _TopDirection;
             float4 _TopDepth;
          
             struct Input 
             {
                 float2 uv_MainTex;
                 float2 uv_Normal;
                 float2 uv_Weight;
                 float2 uv_OcculsionMap;
                 float3 worldNormal;
                 float3 viewDir;
                 INTERNAL_DATA
             };
          
             void FastSinCos (float4 val, out float4 s, out float4 c) {
             val = val * 6.408849 - 3.1415927;
             float4 r5 = val * val;
             float4 r6 = r5 * r5;
             float4 r7 = r6 * r5;
             float4 r8 = r6 * r5;
             float4 r1 = r5 * val;
             float4 r2 = r1 * r5;
             float4 r3 = r2 * r5;
             float4 sin7 = {1, -0.16161616, 0.0083333, -0.00019841} ;
             float4 cos8  = {-0.5, 0.041666666, -0.0013888889, 0.000024801587} ;
             s =  val + r1 * sin7.y + r2 * sin7.z + r3 * sin7.w;
             c = 1 + r5 * cos8.x + r6 * cos8.y + r7 * cos8.z + r8 * cos8.w;
     
             }
          
             void vert (inout appdata_full v) 
             {
     
             //get coloring direction
             float4 top = mul(UNITY_MATRIX_IT_MV, _TopDirection);
     
     
             float4 WeightMap = tex2Dlod (_VertexWeight, float4(v.texcoord.xy,0,0));
     
             float factor = (1 - _ShakeDisplacement -  v.color.r) * 0.5;
                
             const float _WindSpeed  = (_ShakeWindspeed  +  v.color.g );    
             const float _WaveScale = _ShakeDisplacement;
            
             const float4 _waveXSize = float4(0.048, 0.06, 0.24, 0.096);
             const float4 _waveZSize = float4 (0.024, .08, 0.08, 0.2);
             const float4 waveSpeed = float4 (1.2, 2, 1.6, 4.8);
          
             float4 _waveXmove = float4(0.024, 0.04, -0.12, 0.096);
             float4 _waveZmove = float4 (0.006, .02, -0.02, 0.1);
            
             float4 waves;
             waves = v.vertex.x * _waveXSize;
             waves += v.vertex.z * _waveZSize;
          
             waves += _Time.x * (1 - _ShakeTime * 2 - v.color.b ) * waveSpeed *_WindSpeed;
          
             float4 s, c;
             waves = frac (waves);
             FastSinCos (waves, s,c);
          
             float waveAmount = WeightMap.r  * (v.color.a + _ShakeBending);
             s *= waveAmount;
          
             s *= normalize (waveSpeed);
          
             s = s * s;
             float fade = dot (s, 1.3);
             s = s * s;
             float3 waveMove = float3 (0,0,0);
             waveMove.x = dot (s, _waveXmove);
             waveMove.z = dot (s, _waveZmove);
             v.vertex.xz -= mul ((float3x3)_World2Object, waveMove).xz;
             }
          
             void surf (Input IN, inout SurfaceOutput o) 
             {
     
             fixed4 baseColor = tex2D(_MainTex, IN.uv_MainTex) * _Color;
             fixed3 occlusion = tex2D(_OcclusionMap, IN.uv_OcculsionMap);
             //c.rgb =
             fixed3 normal = UnpackNormal(tex2D(_Normal, IN.uv_Normal)); 
             normal.z = normal.z / _BumpPower; 
             o.Normal = normalize(normal);
             
             half difference2 = dot(WorldNormalVector(IN, o.Normal), _TopDirection.xyz) - lerp(1,-1,_TopLevel);
             difference2 = saturate(difference2 / _TopDepth);
             
             //half fresnel = dot (normalize(IN.viewDir), o.Normal);
     
             o.Albedo = (difference2 * (_TopColor.rgb *2)  + (1-difference2)) * baseColor.rgb * _Color.rgb;
             
             o.Alpha = baseColor.a;
             //o.Alpha = dot(o.Normal, normalize(IN.viewDir));
             
             }
     
             ENDCG
     
     }
      
     Fallback "Transparent/Cutout/VertexLit"
     }
      

Thank you!

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

RWTexture2D in Compute Shader on Android? 2 Answers

My shader works on desktop, but black screen on Android. 0 Answers

My shader's LOD levels arn't respected when I run my game on android tablets or phones 0 Answers

Shader works differently on Android (OpenGL) and Editor (DX11) 0 Answers

Particles with the "Mobile/Particles/Alpha blended" look very dark on Nexus 4 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