92 lines
2.7 KiB
Plaintext
92 lines
2.7 KiB
Plaintext
|
Shader "Zhanyou/Mobile/DiffuseMetal"
|
|||
|
{
|
|||
|
Properties
|
|||
|
{
|
|||
|
_MainTex ("Base (RGB)", 2D) = "white" {}
|
|||
|
[NoScaleOffset]_BumpMap ("Normal Map", 2D) = "white" {}
|
|||
|
[NoScaleOffset]_ChannelTex("Channel(R = Specular Gloss, G = Specular Power)", 2D) = "white" {}
|
|||
|
|
|||
|
_BumpLerp ("Normal Strength", Range(0, 5)) = 1
|
|||
|
_Emission ("Emission", Range(0, 1)) = 0
|
|||
|
_Specular ("Specular", Range(0, 2)) = 0.25
|
|||
|
_Gloss ("Gloss", Range(0, 2)) = 1
|
|||
|
}
|
|||
|
SubShader
|
|||
|
{
|
|||
|
Tags { "RenderType"="Opaque" }
|
|||
|
|
|||
|
// Forward Base
|
|||
|
Pass
|
|||
|
{
|
|||
|
Name "FORWARD"
|
|||
|
Tags { "LightMode" = "ForwardBase" }
|
|||
|
|
|||
|
CGPROGRAM
|
|||
|
#define UNITY_PASS_FORWARDBASE
|
|||
|
#include "UnityGiBase.cginc"
|
|||
|
#pragma multi_compile_fwdbase
|
|||
|
#pragma multi_compile_fog
|
|||
|
#pragma multi_compile __ PLAYER_HALO_ON
|
|||
|
#pragma multi_compile __ T4M_NORMAL_OFF
|
|||
|
#pragma multi_compile __ T4M_UNITY_GI_OFF
|
|||
|
#pragma vertex vert_Base
|
|||
|
#pragma fragment frag
|
|||
|
|
|||
|
uniform sampler2D _MainTex;
|
|||
|
uniform float4 _MainTex_ST;
|
|||
|
uniform half _Emission;
|
|||
|
#if !T4M_NORMAL_OFF
|
|||
|
uniform sampler2D _BumpMap;
|
|||
|
uniform half _BumpLerp;
|
|||
|
#endif
|
|||
|
#if !T4M_UNITY_GI_OFF
|
|||
|
uniform half _Specular;
|
|||
|
uniform half _Gloss;
|
|||
|
#endif
|
|||
|
uniform sampler2D _ChannelTex;
|
|||
|
|
|||
|
fixed4 frag(v2f_Base i) : SV_TARGET
|
|||
|
{
|
|||
|
float2 uv = TRANSFORM_TEX(i.uv, _MainTex);
|
|||
|
fixed4 c = tex2D(_MainTex, uv);
|
|||
|
#if T4M_NORMAL_OFF
|
|||
|
fixed3 worldNormal = fixed3(i.tSpace0.z, i.tSpace1.z, i.tSpace2.z);
|
|||
|
#else
|
|||
|
half3 normal = UnpackNormal(tex2D(_BumpMap, uv));
|
|||
|
// 世界法线
|
|||
|
fixed3 worldNormal;
|
|||
|
worldNormal.x = dot(i.tSpace0.xyz, normal);
|
|||
|
worldNormal.y = dot(i.tSpace1.xyz, normal);
|
|||
|
worldNormal.z = dot(i.tSpace2.xyz, normal);
|
|||
|
worldNormal = normalize(worldNormal);
|
|||
|
#endif
|
|||
|
// 标准UnityGi流程
|
|||
|
GET_UNITY_GI_COLOR;
|
|||
|
fixed4 channel = tex2D(_ChannelTex, uv);
|
|||
|
#if !T4M_NORMAL_OFF
|
|||
|
// 法线强度调整功能
|
|||
|
fixed ndotlVert = LambertTerm(fixed3(i.tSpace0.z, i.tSpace1.z, i.tSpace2.z), lightDir);
|
|||
|
giColor += (ndotl - ndotlVert) * _BumpLerp * SIM_LIGHT_COLOR;
|
|||
|
#endif
|
|||
|
#if !T4M_UNITY_GI_OFF
|
|||
|
// 虚拟光源高光反射
|
|||
|
fixed3 worldViewDir = normalize(UnityWorldSpaceViewDir(worldPos));
|
|||
|
half3 h = normalize (_SpecularLight.xyz + worldViewDir);
|
|||
|
half nh = max (0, dot (worldNormal, h));
|
|||
|
half specular = pow (nh, _Specular * channel.g * 128.0) * channel.r * _Gloss * c.a;
|
|||
|
giColor += specular * atten * c.rgb;
|
|||
|
#endif
|
|||
|
#if PLAYER_HALO_ON
|
|||
|
giColor += _DirectionalLightColor * LightColorFromWorld(worldPos);
|
|||
|
#endif
|
|||
|
// 自发光功能
|
|||
|
c.rgb = giColor + c.rgb * _Emission;
|
|||
|
UNITY_APPLY_FOG(i.fogCoord, c);
|
|||
|
UNITY_OPAQUE_ALPHA(c.a);
|
|||
|
return c;
|
|||
|
}
|
|||
|
ENDCG
|
|||
|
}
|
|||
|
}
|
|||
|
Fallback "Zhanyou/Mobile/DiffuseBumpedEmit"
|
|||
|
}
|