Reputation: 1
I'm really novice and this is first time I wrote a shader for unity mobile game. Here is the shader, working well on Editor but not on my android device :
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"
}
So any help would be very welcome :),and also one thing to clarify, I'm not sure the performance of this shader is good enough for mobile ?
Thanks you very much !
Upvotes: 0
Views: 840
Reputation: 1
So now I feel I'm doing it the wrong way. This shader is done for a character customisation and my shader skills are near to 0 so I will give up for this solution.
Finally I think it's better to merge needed texture at runtime and apply the result to a mobile shader.
Upvotes: 0
Reputation: 10137
According to this Unity Manual, OpenGL ES 2.0 only supports the maximum of 8 textures in a single shader. Also, if you go to the Edit > Graphics Emulation menu and choose OpenGL ES 2.0, you can see the shader warnings for it.
I'm not sure the performance of this shader is good enough for mobile ?
You're using too many sampler2D's in a single shader. Also you should avoid expensive math functions in shader code. Your shader is expensive for mobile.
You can read more about mobile optimization here and here.
Upvotes: 1