- Home /
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?
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!
Your answer
Follow this Question
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