- Home /
Question by
Milgiray · Jul 23, 2017 at 07:49 AM ·
androidunity 5shaderandroid buildshader writing
My simple shader not working correctly on Android
My simple shader not working correctly on Android platform. How to fix it? PC-Editor
Android bulid
Shader "Car" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex("Albedo (RGBA)", 2D) = "white" {}
_NormalTex("Normalmap", 2D) = "bump" {}
_NormalScale("Scale", Range(-1, 1)) = 1.0
_Smoothness ("Smoothness", Range(0.01, 1.0)) = 0.5
_Cubemap ("Reflections", CUBE) = "" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Custom
#pragma target 2.0
sampler2D _MainTex;
sampler2D _NormalTex;
samplerCUBE _Cubemap;
struct Input {
float2 uv_MainTex;
float2 uv_NormalTex;
float3 worldRefl;
INTERNAL_DATA
};
half _NormalScale;
half _Smoothness;
fixed4 _Color;
UNITY_INSTANCING_CBUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_CBUFFER_END
fixed4 LightingCustom(SurfaceOutput s, fixed3 lightDir, half3 viewDir, fixed atten)
{
float NdotL = max(0, dot(s.Normal, lightDir));
float3 halfVector = normalize(lightDir + viewDir);
float NdotH = max(0, dot(s.Normal, halfVector));
float spec = pow(NdotH, _Smoothness * 500.0) * min(_Smoothness * 2.0, 1);
float4 c;
c.rgb = (s.Albedo * _LightColor0.rgb * (NdotL * 0.8 + 0.2)) + (_LightColor0.rgb * spec) * atten;
c.a = s.Alpha;
return c;
}
half3 UnpackNormalScale(half4 packednormal, half Scale)
{
half3 normal;
normal.xy = (packednormal.wy * 2 - 1);
normal.xy *= Scale;
normal.z = sqrt(1.0 - saturate(dot(normal.xy, normal.xy)));
return normal;
}
void surf (Input IN, inout SurfaceOutput o)
{
o.Albedo = lerp(tex2D (_MainTex, IN.uv_MainTex), _Color, 1.0 - tex2D(_MainTex, IN.uv_MainTex).a).rgb;
o.Normal = UnpackNormalScale(tex2D(_NormalTex, IN.uv_NormalTex), _NormalScale);
o.Specular = _Smoothness;
o.Emission = texCUBE(_Cubemap, WorldReflectionVector(IN, o.Normal)).rgb * o.Specular * 0.25;
}
ENDCG
}
FallBack "Diffuse"
}
android.jpg
(27.9 kB)
pc-editor.jpg
(45.6 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612130925im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to use #extension with GLSL shader 0 Answers
Unity android Unable to forward network traffic to device 7 Answers
i need help. Why my character looks so weird when i change Platform from standalone to android 0 Answers
Android target api 26, google says its 24 1 Answer
How come when I generate a signed APK it produces out a JKS file? 0 Answers