ro-webgl/Assets/Shaders/Actor/TouShi.shader
2021-12-21 09:40:39 +08:00

151 lines
4.1 KiB
Plaintext

// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Hero/TouShi" {
Properties
{
_Color("Main Color", Color) = (1,1,1,1)
_MainTex("Main Texture", 2D) = "white" {}
_MaskTex("Mask (RGB)", 2D) = "white" {}
_Strength("Strength", Range(0, 2)) = 2
_Muti_Color("Muti Color", Color) = (1,1,1,1)
_Add_Color("Add Color", Color) = (0,0,0,1)
_OutlineColor ("Outline Color", Color) = (0,0,0,1)
_Outline ("Outline width", Range (0, 0.1)) = .01
_OutlineStrength("OutlineStrength", Range (0, 1)) = .75
_ClrStrength("ClrStrength", Range(0, 1.7)) = 1.7
_StatueDegree("StatueDegree", Range(0, 1)) = 0
}
SubShader
{
Tags {
"RenderType" = "Opaque"
}
LOD 100
// note that a vertex shader is specified here but its using the one above
Pass
{
Name "OUTLINE"
Tags{ "LightMode" = "Always" }
Cull Front
ZWrite On
/*ColorMask RGB*/
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform fixed4 _OutlineColor;
uniform half _Outline;
half _OutlineStrength;
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _MaskTex;
struct appdata {
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 texCoord : TEXCOORD0;
};
struct v2f {
float4 pos : POSITION;
float4 tex : TEXCOORD0;
};
v2f vert(appdata v) {
// just make a copy of incoming vertex data but scaled according to normal direction
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
float3 norm = mul((float3x3)UNITY_MATRIX_IT_MV, v.normal);
float2 offset = TransformViewToProjection(norm.xy);
o.pos.xy += offset * _Outline * 0.5;
o.tex.xy = TRANSFORM_TEX(v.texCoord, _MainTex);
return o;
}
fixed4 frag(v2f i) :COLOR
{
fixed4 cDark = tex2D(_MainTex, i.tex.xy);
cDark = cDark * _OutlineStrength;// *cDark * cDark;
cDark.a = 1; // weapon had alpha?
cDark.rgb = cDark.rgb + _OutlineColor.rgb;
return cDark;
}
ENDCG
} // outline Pass
Pass
{
Name "FORWARD"
Tags {
"LightMode" = "ForwardBase"
}
CGPROGRAM
#pragma fragmentoption ARB_precision_hint_fastest
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#include "UnityCG.cginc"
#include "AutoLight.cginc"
uniform fixed3 _LightColor0;
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _Color;
fixed _Strength;
half _ClrStrength;
fixed4 _Muti_Color;
fixed4 _Add_Color;
fixed _StatueDegree;
struct V2f {
fixed4 pos : SV_POSITION;
fixed2 uv0 : TEXCOORD0;
fixed4 posWorld : TEXCOORD1;
fixed3 normalDir : TEXCOORD2;
fixed3 col : COLOR;
UNITY_FOG_COORDS(4)
};
V2f vert(appdata_full v) {
V2f o;
o.uv0 = TRANSFORM_TEX(v.texcoord, _MainTex);
float3 worldNormal = UnityObjectToWorldNormal(v.normal);
o.normalDir = worldNormal;
o.posWorld = mul(unity_ObjectToWorld, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);
UNITY_TRANSFER_FOG(o,o.pos);
fixed3 lightDirection = _WorldSpaceLightPos0.xyz;
fixed3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - o.posWorld.xyz);
float ff = saturate(1 - max(0, dot(o.normalDir, viewDirection)));
o.col = lerp(max(0,dot(lightDirection, o.normalDir))*_LightColor0,UNITY_LIGHTMODEL_AMBIENT.rgb,0.2 );
return o;
}
fixed4 frag(V2f i) : SV_Target{
fixed4 diff = tex2D(_MainTex, i.uv0) * _Color * _ClrStrength;
fixed4 col = fixed4((diff.rgb * _Muti_Color + diff.rgb * i.col + _Add_Color.rgb),1);
fixed3 lpCol = diff.rgb;
col.rgb = lpCol * _Strength;
fixed grey = dot(col.rgb, fixed3(0.299, 0.587, 0.114));
col.rgb = lerp(col.rgb, fixed3(grey, grey, grey), _StatueDegree);
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
} //normal pass
}
//FallBack "Diffuse"
}