133 lines
3.4 KiB
Plaintext
133 lines
3.4 KiB
Plaintext
// Simplified Diffuse shader. Differences from regular Diffuse one:
|
||
// - no Main Color
|
||
// - fully supports only 1 directional light. Other lights can affect it, but it will be per-vertex/SH.
|
||
|
||
Shader "Zhanyou/Mobile/DiffuseEmit" {
|
||
Properties {
|
||
_MainTex ("Base (RGB)", 2D) = "white" {}
|
||
_Emission ("Emission", Range(0, 1)) = 0
|
||
}
|
||
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 vertex vert_Base
|
||
#pragma fragment frag
|
||
#pragma multi_compile __ PLAYER_HALO_ON
|
||
uniform sampler2D _MainTex;
|
||
uniform float4 _MainTex_ST;
|
||
uniform half _Emission;
|
||
|
||
fixed4 frag(v2f_Base i) : SV_TARGET
|
||
{
|
||
fixed4 c = tex2D(_MainTex, TRANSFORM_TEX(i.uv, _MainTex));
|
||
// 世界法线
|
||
fixed3 worldNormal = fixed3(i.tSpace0.z, i.tSpace1.z, i.tSpace2.z);
|
||
GET_UNITY_GI_COLOR;
|
||
// 自发光功能
|
||
c.rgb = giColor + c.rgb * _Emission;
|
||
#if PLAYER_HALO_ON
|
||
c.rgb += _DirectionalLightColor * LightColorFromWorld(worldPos);
|
||
#endif
|
||
UNITY_APPLY_FOG(i.fogCoord, c);
|
||
UNITY_OPAQUE_ALPHA(c.a);
|
||
return c;
|
||
}
|
||
ENDCG
|
||
}
|
||
|
||
// Forward Add
|
||
// 注:实际光照贴图只通过meta通道实现,Forward Add仅用于编辑器无光照贴图时预览
|
||
// 简单处理,Forward Add也使用顶点计算光照和视野方向,真实光照参数
|
||
// 该通道可以省去镜面高光等所需参数,因此按常规算法做
|
||
Pass
|
||
{
|
||
Name "FORWARD_ADD"
|
||
Tags { "LightMode" = "ForwardAdd" }
|
||
ZWrite Off
|
||
Blend One One
|
||
CGPROGRAM
|
||
#define UNITY_PASS_FORWARDADD
|
||
#include "UnityGiBase.cginc"
|
||
#pragma multi_compile_fwdadd
|
||
#pragma multi_compile_fog
|
||
#pragma skip_variants INSTANCING_ON
|
||
#pragma vertex vert_Add
|
||
#pragma fragment frag
|
||
uniform sampler2D _MainTex;
|
||
uniform float4 _MainTex_ST;
|
||
|
||
fixed4 frag(v2f_Add i) : SV_TARGET
|
||
{
|
||
#ifdef LIGHTMAP_ON
|
||
fixed4 c = fixed4(0.0, 0.0, 0.0, 0.0);
|
||
#else
|
||
fixed4 c = tex2D(_MainTex, TRANSFORM_TEX(i.uv, _MainTex));
|
||
half NtoL = max(0.0, i.lightDir.z);
|
||
UNITY_LIGHT_ATTENUATION(atten, i, i.worldPos);
|
||
c.rgb = c.rgb * atten * _LightColor0.rgb * NtoL;
|
||
#endif
|
||
UNITY_APPLY_FOG(i.fogCoord, c);
|
||
UNITY_OPAQUE_ALPHA(c.a);
|
||
return c;
|
||
}
|
||
ENDCG
|
||
}
|
||
|
||
// Meta
|
||
Pass
|
||
{
|
||
Name "Meta"
|
||
Tags { "LightMode" = "Meta" }
|
||
Cull Off
|
||
|
||
CGPROGRAM
|
||
#define UNITY_PASS_META
|
||
#include "UnityCG.cginc"
|
||
#include "UnityMetaPass.cginc"
|
||
#pragma vertex vert
|
||
#pragma fragment frag
|
||
#pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
|
||
#pragma skip_variants INSTANCING_ON
|
||
|
||
uniform sampler2D _MainTex;
|
||
uniform float4 _MainTex_ST;
|
||
uniform half _Emission;
|
||
|
||
struct v2f {
|
||
float4 pos : SV_POSITION;
|
||
float2 uv : TEXCOORD0;
|
||
};
|
||
|
||
v2f vert(appdata_full v) {
|
||
v2f o;
|
||
UNITY_INITIALIZE_OUTPUT(v2f, o);
|
||
o.pos = UnityObjectToClipPos(v.vertex);
|
||
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
|
||
return o;
|
||
}
|
||
|
||
fixed4 frag(v2f i) : SV_TARGET
|
||
{
|
||
fixed4 c = tex2D(_MainTex, i.uv);
|
||
UnityMetaInput metaIN;
|
||
UNITY_INITIALIZE_OUTPUT(UnityMetaInput, metaIN);
|
||
metaIN.Albedo = c.rgb;
|
||
metaIN.Emission = c.rgb * _Emission;
|
||
return UnityMetaFragment(metaIN);
|
||
}
|
||
ENDCG
|
||
}
|
||
}
|
||
Fallback "Mobile/VertexLit"
|
||
} |