135 lines
3.2 KiB
Plaintext
135 lines
3.2 KiB
Plaintext
Shader "Unlit/GradientShader"
|
|
{
|
|
Properties
|
|
{
|
|
|
|
_MainTex("MainTex",2D) = "white" {}
|
|
_LightGradient("LitGradient", 2D) = "white" {}
|
|
_LitColor("LitColor", Color) = (1,0,0,1)
|
|
_ShadowColor("ShadowColor", Color) = (0,0,1,1)
|
|
|
|
_SpecGradient("SpecGradient", 2D) = "white" {}
|
|
_SpecColor("SpecColor", Color) = (1,1,0,1)
|
|
_SpecStart("SpecStart", Range(0, 1)) = 1
|
|
_SpecEnd("SpecEnd", Range(0, 1)) = 0
|
|
_SpecStrength("SpecStrength", Range(0,1)) = 1
|
|
|
|
_RimGradient("RimGradient", 2D) = "white" {}
|
|
_RimColor("RimColor", Color) = (0,1,1,1)
|
|
_RimStart("RimStart", Range(0, 1)) = 1
|
|
_RimEnd("RimEnd", Range(0, 1)) = 0
|
|
_RimStrength("RimStrength", Range(0,1)) = 0.35
|
|
|
|
}
|
|
SubShader
|
|
{
|
|
Tags {
|
|
"RenderType" = "Opaque"
|
|
"LightMode" = "ForwardBase"
|
|
"PassFlags" = "OnlyDirectional"
|
|
}
|
|
LOD 100
|
|
|
|
Cull off
|
|
|
|
Pass
|
|
{
|
|
CGPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#pragma multi_compile_fwdbase
|
|
|
|
#include "UnityCG.cginc"
|
|
#include "AutoLight.cginc"
|
|
|
|
struct appdata
|
|
{
|
|
float4 vertex : POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
float3 normal : NORMAL;
|
|
|
|
};
|
|
|
|
struct v2f
|
|
{
|
|
float2 uv : TEXCOORD0;
|
|
float4 pos : SV_POSITION;
|
|
float3 worldNormal : NORMAL;
|
|
float3 viewDir : TEXCOORD1;
|
|
SHADOW_COORDS(2)
|
|
};
|
|
|
|
//Base Lit color and shadow color
|
|
sampler2D _LightGradient;
|
|
//float4 _LightGradient_ST;
|
|
fixed4 _LitColor;
|
|
fixed4 _ShadowColor;
|
|
|
|
//Specular Setting
|
|
sampler2D _SpecGradient;
|
|
fixed4 _SpecColor;
|
|
float _SpecStart;
|
|
float _SpecEnd;
|
|
float _SpecStrength;
|
|
|
|
//Rim
|
|
sampler2D _RimGradient;
|
|
fixed4 _RimColor;
|
|
float _RimStart;
|
|
float _RimEnd;
|
|
float _RimStrength;
|
|
|
|
sampler2D _MainTex;
|
|
float4 _MainTex_ST;
|
|
|
|
v2f vert(appdata v)
|
|
{
|
|
v2f o;
|
|
o.pos = UnityObjectToClipPos(v.vertex);
|
|
o.worldNormal = UnityObjectToWorldNormal(v.normal);
|
|
o.viewDir = WorldSpaceViewDir(v.vertex);
|
|
|
|
o.uv = v.uv + _MainTex_ST.xy * _MainTex_ST.zw;
|
|
TRANSFER_SHADOW(o)
|
|
|
|
return o;
|
|
}
|
|
|
|
fixed4 frag(v2f i) : SV_Target
|
|
{
|
|
half4 maintex = tex2D(_MainTex,i.uv);
|
|
|
|
//(value - from1) / (to1 - from1) * (to2 - from2) + from2;
|
|
float shadow = SHADOW_ATTENUATION(i);
|
|
|
|
float3 normal = normalize(i.worldNormal);
|
|
float3 viewDir = normalize(i.viewDir);
|
|
float NdotL = dot(_WorldSpaceLightPos0, normal);
|
|
|
|
float3 halfVector = normalize(_WorldSpaceLightPos0 + viewDir);
|
|
float NdotH = dot(normal, halfVector);
|
|
|
|
float specFac = clamp((NdotL * clamp(NdotH, 0.5, 1) - _SpecStart) / (_SpecEnd - _SpecStart),0,1);
|
|
float specValue = 1 - tex2D(_SpecGradient, specFac).r;
|
|
fixed4 LitColor = lerp(_LitColor, _SpecColor, specValue * _SpecStrength);
|
|
|
|
float LitFac = (NdotL + 1) / 2;
|
|
float LitValue = tex2D(_LightGradient, NdotL).r;
|
|
fixed4 shadowreceivedColor = lerp(_ShadowColor, LitColor, shadow);
|
|
fixed4 shadedColor = lerp(_ShadowColor, shadowreceivedColor, LitValue);
|
|
|
|
float rimFac = clamp((dot(normal, viewDir) - _RimStart) / (_RimEnd - _RimStart) ,0,1);
|
|
float rimValue = tex2D(_RimGradient, rimFac).r;
|
|
fixed4 rimColor = lerp(shadedColor, _RimColor, rimValue * _RimStrength) * maintex;
|
|
|
|
return rimColor;
|
|
|
|
}
|
|
ENDCG
|
|
}
|
|
|
|
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
|
|
|
|
}
|
|
}
|