1
votes

I have a custom shader and it doesn't work on my mobile device but works on the PC. How do I convert it so it works on a mobile device?

Following is my code:

Shader "vertexPainter/DiffuseNormalSpec_2tex_mask" {
    Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex1 ("Base 1 (RGBA)", 2D) = "white" {}
    _BumpMap1 ("Bumpmap 1 (RGB)", 2D) = "bump" {}

    _MainTex2 ("Base 2 (RGB)", 2D) ="black" {}
    _BumpMap2 ("Bumpmap 2 (RGB)", 2D) = "bump" {}
    _BlendMask ("Blend Mask", 2D) = "white" {}

    _Shininess("shininess", Range(0,0.8)) = 0.1
    _SpecColor("spec color", Color) = (0,0,0,0)
    _BlendSoft("Blend Softness", Range(0,0.8)) = 0.1
    _B_Normal("B Normal", Range(0,0.8)) = 0.1
    }
    SubShader {
    Tags { "RenderType"="Opaque" }
    LOD 600

    CGPROGRAM
    #pragma surface surf BlinnPhong vertex:vert
    #pragma target 3.0
    struct Input {
    float2 uv_MainTex1 : TEXCOORD0;
    float2 uv2_BlendMask : TEXCOORD1;
    float4 color : COLOR;
    };
    void vert (inout appdata_full v, out Input o) {
    UNITY_INITIALIZE_OUTPUT(Input,o); 
    o.color = (v.color);
    }
    uniform sampler2D _MainTex1, _MainTex2, _BlendMask;
    uniform sampler2D _BumpMap1, _BumpMap2;
    half3 _SelfIllum;
    half _BlendSoft, _B_Normal;
    fixed _Shininess;
    void surf (Input IN, inout SurfaceOutput o) {

    half4 base = tex2D(_MainTex1, IN.uv_MainTex1);
    half4 blend1 = tex2D(_MainTex2, IN.uv_MainTex1);

    half4 blendmask = tex2D(_BlendMask, IN.uv2_BlendMask);
    half transformed = ((1 - IN.color.g) - blendmask.r)/_BlendSoft;

    half mask = saturate(transformed); 
    half4 finresult = lerp(blend1, base, mask); 
    half specresultg = lerp(blend1.a, base.a, mask); 

    half3 g_normal = UnpackNormal(tex2D(_BumpMap2, IN.uv_MainTex1));
    g_normal *= 1-(blendmask.b * _B_Normal);
    half3 r_normal = UnpackNormal(tex2D(_BumpMap1, IN.uv_MainTex1));
    half3 norresultg = lerp(g_normal, r_normal, mask); 

    o.Albedo = finresult.rgb;
    o.Normal = norresultg;
    o.Alpha = 1;
    o.Specular = _Shininess;
    o.Gloss = specresultg * _SpecColor;
    }
    ENDCG
    }

    FallBack "Diffuse"
}

Screenshots for the shader:

This is what it looks like on my PC:

enter image description here

This is what it looks like on my mobile:

enter image description here

Specifications

PC: OS: Windows 10 Pro 64-bit Processor : Intel(r) Core(TM) i7-6700 CPU @ 3.40 Ghz(8CPUs), ~3.4Ghz Memory: 16,384MB RAM Graphic Card: NVIDIA GeForce GTX 960

Phone: Samsung Galaxy s7 but right now i'm using an emulator(Bluestack)

1
can you check with adb logcat to see if its giving some errors in device: answers.unity.com/questions/492681/how-to-use-adb-logcat.htmlmgear
Hey, did you figure out what the issue was? I have a similar terrain blender shader and I am having the same issue.Uzi

1 Answers

3
votes

Go Settings -> Graphics, and add the shaders you need to the "Always Included Shaders" list.

Hope it helps