贴花着色器无法在设备上工作



我真的是新手,这是我第一次为Unity手机游戏编写着着色器。这是着色器,在编辑器上运行良好,但在我的Android设备上不工作:

                Shader "Decal" {
            Properties {
             _Skin("Skin (RGB)", 2D) = "white" {}
             _Dirt("Dirt (RGBA)", 2D) = "black" {}
             _Outfit("Outfit (RGBA)", 2D) = "black" {}
             _Painting("Painting (RGBA)", 2D) = "black" {}
             _Cheek("Cheek (RGBA)", 2D) = "black" {}
             _LipStick("LipStick (RGBA)", 2D) = "black" {}
             _Eye("Eye (RGBA)", 2D) = "black" {}
             _EyeLid("EyeLid (RGBA)", 2D) = "black" {}
             _ShadowHat("ShadowHat (RGBA)", 2D) = "black" {}
            }
            SubShader {
            Tags { "RenderType"="Opaque" }
            LOD 150
            CGPROGRAM
            #pragma surface surf Lambert noforwardadd
            sampler2D _Skin;
            sampler2D _Dirt;
            sampler2D _Outfit;
            sampler2D _Painting;
            sampler2D _Cheek;
            sampler2D _LipStick;
            sampler2D _Eye;
            sampler2D _EyeLid;
            sampler2D _ShadowHat;
            struct Input {
            float2 uv_Skin;
            };
            void surf (Input IN, inout SurfaceOutput o) {
            fixed4 c = tex2D(_Skin, IN.uv_Skin);
            fixed4 dirt = tex2D(_Dirt, IN.uv_Skin);
            fixed4 outfit = tex2D(_Outfit, IN.uv_Skin);
            fixed4 painting = tex2D(_Painting, IN.uv_Skin);
            fixed4 cheek = tex2D(_Cheek, IN.uv_Skin);
            fixed4 lipstick = tex2D(_LipStick, IN.uv_Skin);
            fixed4 eye = tex2D(_Eye, IN.uv_Skin);
            fixed4 eyelid = tex2D(_EyeLid, IN.uv_Skin);
            fixed4 shadowHat = tex2D(_ShadowHat, IN.uv_Skin);
            c.rgb = lerp (c.rgb, dirt.rgb, dirt.a);
            c.rgb = lerp (c.rgb, outfit.rgb, outfit.a);
            c.rgb = lerp (c.rgb, painting.rgb, painting.a);
            c.rgb = lerp (c.rgb, cheek.rgb, cheek.a);
            c.rgb = lerp (c.rgb, lipstick.rgb, lipstick.a);
            c.rgb = lerp (c.rgb, eye.rgb, eye.a);
            c.rgb = lerp (c.rgb, eyelid.rgb, eyelid.a);
            c.rgb = lerp (c.rgb, shadowHat.rgb, shadowHat.a);
            o.Albedo = c.rgb;
            o.Alpha = c.a;
            }
            ENDCG
            }
            Fallback "Mobile/VertexLit"
            }

所以非常欢迎任何帮助::),而且要澄清的一件事,我不确定此着色器的性能是否足以移动?

非常感谢您!

根据此统一手册,OpenGL ES 2.0仅支持一个阴暗器中的8个纹理。另外,如果您转到编辑>图形仿真菜单,然后选择 OpenGL ES 2.0 ,您可以看到它的着色器警告。

我不确定此着色器的性能是否足以用于移动?

您在一个着色器中使用了太多 Sampler2d的。另外,您应该避免使用着色器代码中的昂贵数学功能。您的着色器对于手机很昂贵。

您可以在此处和此处阅读有关移动优化的更多信息。

,所以现在我觉得我以错误的方式这样做。此着色器是针对角色定制的,我的着色器技能接近0,因此我将放弃此解决方案。

最后,我认为最好在运行时合并所需的纹理并将结果应用于移动着色器。

相关内容

  • 没有找到相关文章

最新更新