Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Shader not working in android device

Discussion in 'Shaders' started by dail, May 16, 2019.

  1. dail

    dail

    Joined:
    Dec 5, 2013
    Posts:
    10
    This shader works in the editor but in android it gets all pink. Is there anything I can do to make it work on android?

    Code (CSharp):
    1. Shader "yy/dust" {
    2.     Properties {
    3.         _MainTex ("MainTex", 2D) = "white" {}
    4.         [MaterialToggle] _pickupCh ("pickupCh", Float ) = 0
    5.         _emissive ("emissive", Float ) = 2
    6.         _texDensity ("texDensity", Float ) = 2
    7.         [MaterialToggle] _useR ("useR", Float ) = 0
    8.         [MaterialToggle] _useG ("useG", Float ) = 0
    9.         [MaterialToggle] _useB ("useB", Float ) = 0
    10.         _alphaDensity ("alphaDensity", Float ) = 1
    11.         _alphaPower ("alphaPower", Float ) = 1
    12.         _vertColorDensity ("vertColorDensity", Float ) = 1
    13.         _color ("color", Color) = (1,1,1,1)
    14.         _uvDynCorrect ("uvDynCorrect", Float ) = 1
    15.         [MaterialToggle] _haveAlpha ("haveAlpha", Float ) = 0
    16.         _depthBlend ("depthBlend", Float ) = 1
    17.         [MaterialToggle] _useDepthBlend ("useDepthBlend", Float ) = 1
    18.     }
    19.     SubShader {
    20.         Tags {
    21.             "IgnoreProjector"="True"
    22.             "Queue"="Transparent"
    23.             "RenderType"="Transparent"
    24.         }
    25.         Pass {
    26.             Name "FORWARD"
    27.             Tags {
    28.                 "LightMode"="ForwardBase"
    29.             }
    30.             Blend One One
    31.             ZWrite Off
    32.            
    33.             CGPROGRAM
    34.             #pragma vertex vert
    35.             #pragma fragment frag
    36.             #define UNITY_PASS_FORWARDBASE
    37.             #include "UnityCG.cginc"
    38.             #pragma multi_compile_fwdbase
    39.             #pragma multi_compile_fog
    40.             #pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2
    41.             #pragma target 3.0
    42.             uniform sampler2D _CameraDepthTexture;
    43.             uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
    44.             uniform fixed _pickupCh;
    45.             uniform float _emissive;
    46.             uniform float _texDensity;
    47.             uniform fixed _useR;
    48.             uniform fixed _useG;
    49.             uniform fixed _useB;
    50.             uniform float _alphaDensity;
    51.             uniform float _alphaPower;
    52.             uniform float _vertColorDensity;
    53.             uniform float4 _color;
    54.             uniform float _uvDynCorrect;
    55.             uniform fixed _haveAlpha;
    56.             uniform float _depthBlend;
    57.             uniform fixed _useDepthBlend;
    58.             struct VertexInput {
    59.                 float4 vertex : POSITION;
    60.                 float2 texcoord0 : TEXCOORD0;
    61.                 float4 vertexColor : COLOR;
    62.             };
    63.             struct VertexOutput {
    64.                 float4 pos : SV_POSITION;
    65.                 float2 uv0 : TEXCOORD0;
    66.                 float4 vertexColor : COLOR;
    67.                 float4 projPos : TEXCOORD1;
    68.                 UNITY_FOG_COORDS(2)
    69.             };
    70.             VertexOutput vert (VertexInput v) {
    71.                 VertexOutput o = (VertexOutput)0;
    72.                 o.uv0 = v.texcoord0;
    73.                 o.vertexColor = v.vertexColor;
    74.                 o.pos = UnityObjectToClipPos(v.vertex );
    75.                 UNITY_TRANSFER_FOG(o,o.pos);
    76.                 o.projPos = ComputeScreenPos (o.pos);
    77.                 COMPUTE_EYEDEPTH(o.projPos.z);
    78.                 return o;
    79.             }
    80.             float4 frag(VertexOutput i) : COLOR {
    81.                 float sceneZ = max(0,LinearEyeDepth (UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)))) - _ProjectionParams.g);
    82.                 float partZ = max(0,i.projPos.z - _ProjectionParams.g);
    83. ////// Lighting:
    84. ////// Emissive:
    85.                 float node_1439 = (i.vertexColor.r*_uvDynCorrect);
    86.                 float node_5474_if_leA = step(node_1439,32.0);
    87.                 float node_5474_if_leB = step(32.0,node_1439);
    88.                 float node_335_if_leA = step(node_1439,16.0);
    89.                 float node_335_if_leB = step(16.0,node_1439);
    90.                 float node_9756 = 32.0;
    91.                 float node_6486_if_leA = step(node_1439,node_9756);
    92.                 float node_6486_if_leB = step(node_9756,node_1439);
    93.                 float node_9176 = 16.0;
    94.                 float node_4634_if_leA = step(node_1439,node_9176);
    95.                 float node_4634_if_leB = step(node_9176,node_1439);
    96.                 float node_5287 = (node_1439-node_9176);
    97.                 float node_8482 = (node_1439-node_9756);
    98.                 float node_6486 = lerp((node_6486_if_leA*lerp((node_4634_if_leA*node_1439)+(node_4634_if_leB*node_5287),node_5287,node_4634_if_leA*node_4634_if_leB))+(node_6486_if_leB*node_8482),node_8482,node_6486_if_leA*node_6486_if_leB);
    99.                 float node_9617_if_leA = step(node_6486,12.0);
    100.                 float node_9617_if_leB = step(12.0,node_6486);
    101.                 float node_8029_if_leA = step(node_6486,8.0);
    102.                 float node_8029_if_leB = step(8.0,node_6486);
    103.                 float node_5532_if_leA = step(node_6486,4.0);
    104.                 float node_5532_if_leB = step(4.0,node_6486);
    105.                 float node_2748 = 2.0;
    106.                 float node_5742 = 1.0;
    107.                 float node_1090 = 0.0;
    108.                 float2 node_2677 = ((i.uv0*0.25)+(floor(float2(node_1439,lerp((node_9617_if_leA*lerp((node_8029_if_leA*lerp((node_5532_if_leA*3.0)+(node_5532_if_leB*node_2748),node_2748,node_5532_if_leA*node_5532_if_leB))+(node_8029_if_leB*node_5742),node_5742,node_8029_if_leA*node_8029_if_leB))+(node_9617_if_leB*node_1090),node_1090,node_9617_if_leA*node_9617_if_leB)))/4.0));
    109.                 float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(node_2677, _MainTex));
    110.                 float3 node_5708 = pow(_MainTex_var.rgb,_texDensity).rgb;
    111.                 float node_516 = 0.0;
    112.                 float node_5474 = lerp((node_5474_if_leA*lerp((node_335_if_leA*lerp( node_5708.r, ((lerp( node_516, node_5708.r, _useR )+lerp( node_516, node_5708.g, _useG ))+lerp( node_516, node_5708.b, _useB )), _pickupCh ))+(node_335_if_leB*node_5708.g),node_5708.g,node_335_if_leA*node_335_if_leB))+(node_5474_if_leB*node_5708.b),node_5708.b,node_5474_if_leA*node_5474_if_leB);
    113.                 float3 emissive = (node_5474*_color.rgb*_emissive*(pow(i.vertexColor.a,_vertColorDensity)*(pow(lerp( node_5474, _MainTex_var.a, _haveAlpha ),_alphaDensity)*_alphaPower)*lerp( 1.0, saturate((sceneZ-partZ)/_depthBlend), _useDepthBlend )));
    114.                 float3 finalColor = emissive;
    115.                 fixed4 finalRGBA = fixed4(finalColor,1);
    116.                 UNITY_APPLY_FOG_COLOR(i.fogCoord, finalRGBA, fixed4(0,0,0,1));
    117.                 return finalRGBA;
    118.             }
    119.             ENDCG
    120.         }
    121.     }
    122.     CustomEditor "ShaderForgeMaterialInspector"
    123. }
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,238
    OpenGL ES 3.0 is the default graphics API for modern android devices, and your shader is excluding that as a renderer target. Delete that line.
     
  3. dail

    dail

    Joined:
    Dec 5, 2013
    Posts:
    10
    It worked. thank you very much