Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Bitcoon · Apr 10, 2014 at 03:02 AM · androidmobilecrash

Android shader not accepting fallback?

Maybe this is just a lack of experience with shaders talking, but I've been dealing with major issues revolving around certain processors crashing with alpha shaders (in this day and age??) and I finally managed to work through it and find some that are decent replacements. Now that I've found the ideal shaders for PC and Android, I figured I could just apply the PC shaders and let the fallback do its thing for Android.

Well apparently that doesn't work. And despite trying to combine the subshders of the fallback shaders into the main one so it could skip to something that worked, it STILL just flat-out crashes. It may be possible to reset all the alpha materials to the proper versions manually depending on what I'm exporting to but that is not a fate I want to subject myself to.

Here's the Android shader, which has been tested and found to work just fine despite the editor complaining about ShaderWithClipAndroid:

 Shader "WV/Mobile Alphaclip"
 {
     Properties
     {
         _MainTex ("Base (RGB), Alpha (A)", 2D) = "white" {}
     }
 
     SubShader
     {
         LOD 200
 
         Tags
         {
             "Queue" = "Transparent"
             "IgnoreProjector" = "True"
             "RenderType" = "Transparent"
         }
 
         Pass
         {
             //Cull Off
             Lighting Off
             ZWrite Off
             Offset -1, -1
             Fog { Mode Off }
             ColorMask RGB
             Blend SrcAlpha OneMinusSrcAlpha
 
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             #pragma fragmentoption ARB_precision_hint_fastest
 
             #include "UnityCG.cginc"
 
             sampler2D _MainTex;
             float4 _MainTex_ST;
 
             struct appdata_t
             {
                 float4 vertex : POSITION;
                 fixed4 color : COLOR;
                 float2 texcoord : TEXCOORD0;
             };
 
             struct v2f
             {
                 float4 vertex : POSITION;
                 fixed4 color : COLOR;
                 float2 texcoord : TEXCOORD0;
                 float2 worldPos : TEXCOORD1;
             };
 
             v2f vert (appdata_t v)
             {
                 v2f o;
                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
                 o.color = v.color;
                 o.texcoord = v.texcoord;
                 o.worldPos = TRANSFORM_TEX(v.vertex.xy, _MainTex);
                 return o;
             }
 
             fixed4 frag (v2f IN) : COLOR
             {
                 // Sample the texture
                 fixed4 col = tex2D(_MainTex, IN.texcoord) * IN.color;
 
                 float2 factor = abs(IN.worldPos);
                 float val = 1.0 - max(factor.x, factor.y);
 
                 // Option 1: 'if' statement
                 if (val < 0.0) col.a = 0.0;
 
                 // Option 2: no 'if' statement -- may be faster on some devices
                 //col.a *= ceil(clamp(val, 0.0, 1.0));
 
                 return col;
             }
             ENDCG
         }
     }
 
     SubShader
     {
         Tags
         {
             "Queue" = "Transparent"
             "IgnoreProjector" = "True"
             "RenderType" = "Transparent"
         }
 
         LOD 100
         Cull Off
         Lighting Off
         ZWrite Off
         Fog { Mode Off }
         ColorMask RGB
         AlphaTest Greater .01
         Blend SrcAlpha OneMinusSrcAlpha
 
         Pass
         {
             ColorMaterial AmbientAndDiffuse
 
             SetTexture [_MainTex]
             {
                 Combine Texture * Primary
             }
         }
     }
 }

And here's the shader that I use on PC, but crashes on Android:

 Shader "WV/AlphaClip" 
 {
     Properties 
     {
         _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
         _Color ("Main Color", Color) = (1,1,1,1)
         _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
     }
 
     
     SubShader 
     {
         Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
         LOD 100
 
         Pass 
         {
              Material 
             {
                 Diffuse [_Color]
             }
             Cull Off
             Lighting Off
             Alphatest Greater [_Cutoff]
             SetTexture [_MainTex] 
             { 
                 constantColor [_Color]
                 combine texture * constant
             } 
         }
     }
     Fallback "WV/Mobile Alphaclip"
 }

Whether or not I put the fallback there, it always just crashes on my Android device. If I put the subshaders from the one that does work into there, it STILL crashes. I really just want this stupid thing to use the working shader on Android and the better shader on PC automatically. Am I just doing something wrong?

Comment
Add comment · Show 1
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 Bitcoon · Apr 11, 2014 at 05:03 AM 0
Share

Okay, now all the shaders with any sort of alpha/transparency are instantly crashing. Even trying to use a fallback to a shader that I know should work (Like mobile/diffuse) still crashes. This is absolutely unacceptable. How can it possibly be that a powerful, modern processor that can, in fact, display textures with alpha/transparency, absolutely will not allow me to use them on 3D models?

What can I possibly do about vegetation? $$anonymous$$aking all trees, bushes, flowers and stuff completely solid is a terrible and time-taking solution but it's starting to seem like the only way!

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

21 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

Related Questions

Sending crash report from a iphone or android app 0 Answers

My mobile game crashes once a certain number of textures have been loaded. What can I do about that? 0 Answers

NoClassDefFoundError exception when using Android plugin 0 Answers

Android Crash on UpdateComputeBuffers in libunity.so 0 Answers

Android 9 - Graphical freeze but scene runs in the background 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