自定义着色器无法在手机上运行(Unity)

问题描述 投票:1回答:1

我有一个自定义着色器,它不能在我的移动设备上工作,但在PC上工作。如何将其转换为可在移动设备上使用?

以下是我的代码:

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"
}

着色器的屏幕截图:

这就是我的电脑上的样子:

enter image description here

这就是我的手机上的样子:

enter image description here

Specifications

PC:操作系统:Windows 10 Pro 64位处理器:Intel(r)Core(TM)i7-6700 CPU @ 3.40 Ghz(8CPU),~3.4Ghz内存:16,384MB RAM显卡:NVIDIA GeForce GTX 960

电话:三星Galaxy s7但是现在我正在使用模拟器(Bluestack)

android unity3d shader
1个回答
1
投票

转到“设置” - >“图形”,然后将所需的着色器添加到“始终包含的着色器”列表中。

希望能帮助到你

© www.soinside.com 2019 - 2024. All rights reserved.