239 lines
6.6 KiB
Plaintext
239 lines
6.6 KiB
Plaintext
![]() |
Shader "MY/Player"
|
||
|
{
|
||
|
Properties
|
||
|
{
|
||
|
[HDR]_Color("Color", Color) = (1,1,1,1)
|
||
|
_MainTex("Albedo (RGBA)", 2D) = "white" {}
|
||
|
|
||
|
_Saturation("Saturation", Range(0,2)) = 1
|
||
|
|
||
|
_Unlit("Unlit", Range(0,1)) = 1
|
||
|
|
||
|
_Cube("Reflection Cubemap", Cube) = "" {}
|
||
|
_ReflectColor("Reflection Color", Color) = (0,0,0,1)
|
||
|
|
||
|
[Header(Color)]
|
||
|
[Toggle] _CastColor("ColorCast?", Float) = 0
|
||
|
_ColorTex("ColorTex (RGBA)", 2D) = "white" { }
|
||
|
_CastColorR("CastColorR", Color) = (1,1,1,1)
|
||
|
_CastColorG("CastColorG", Color) = (1,1,1,1)
|
||
|
_CastColorB("CastColorB", Color) = (1,1,1,1)
|
||
|
|
||
|
[Header(Rim)]
|
||
|
_RimColor("边光颜色", Color) = (0,0,0,1)
|
||
|
_RimPower("边光强度", Range(0,10)) = 1
|
||
|
_RimRange("边光范围", Range(1,10)) = 1.8
|
||
|
|
||
|
[Header(Scroll)]
|
||
|
[KeywordEnum(None, Scroll, Flash)] _ScrollMode("_ScrollModel mode", Float) = 0
|
||
|
_ScrollTex("流光贴图(RGB)", 2D) = "black" {}
|
||
|
_ScrollPower("流光强度", Range(-10, 10)) = 1
|
||
|
_ScrollSpeedX("X流光速度", Range(-10, 10)) = 0
|
||
|
_ScrollSpeedY("Y流光速度", Range(-10, 10)) = 0
|
||
|
|
||
|
[Header(Fresnel)]
|
||
|
_FresnelColor("FresnelColor", Color) = (0.345,0.541,0.737,1)
|
||
|
_FresnelExp("FresnelExp", Range(0,10)) = 0.5
|
||
|
[Enum(UnityEngine.Rendering.CullMode)] _Cull("Cull Mode", Float) = 2
|
||
|
|
||
|
}
|
||
|
SubShader
|
||
|
{
|
||
|
Tags { "Queue" = "Geometry" "RenderType" = "Opaque" }
|
||
|
LOD 200
|
||
|
Cull[_Cull]
|
||
|
|
||
|
Pass
|
||
|
{
|
||
|
Name "Glow"
|
||
|
|
||
|
ColorMask RGB
|
||
|
Blend One One
|
||
|
ZWrite Off
|
||
|
ZTest Greater
|
||
|
Fog {Mode Off}
|
||
|
|
||
|
CGPROGRAM
|
||
|
#pragma vertex vert
|
||
|
#pragma fragment frag
|
||
|
#include "UnityCG.cginc"
|
||
|
|
||
|
fixed4 _FresnelColor;
|
||
|
fixed _FresnelExp;
|
||
|
|
||
|
struct VertexInput
|
||
|
{
|
||
|
half4 vertex : POSITION;
|
||
|
half3 normal : NORMAL;
|
||
|
};
|
||
|
|
||
|
struct VertexOutput
|
||
|
{
|
||
|
half4 pos : SV_POSITION;
|
||
|
half3 color : TEXCOORD0;
|
||
|
};
|
||
|
|
||
|
VertexOutput vert(VertexInput v)
|
||
|
{
|
||
|
VertexOutput o;
|
||
|
o.pos = UnityObjectToClipPos(v.vertex);
|
||
|
half3 normalDir = UnityObjectToWorldNormal(v.normal);
|
||
|
half3 viewDir = normalize(WorldSpaceViewDir(v.vertex));
|
||
|
o.color = _FresnelColor.rgb * pow(1.0 - max(0, dot(normalDir, viewDir)), _FresnelExp);
|
||
|
return o;
|
||
|
}
|
||
|
|
||
|
fixed4 frag(VertexOutput i) : COLOR
|
||
|
{
|
||
|
return fixed4(i.color,1);
|
||
|
}
|
||
|
|
||
|
ENDCG
|
||
|
}
|
||
|
|
||
|
CGPROGRAM
|
||
|
|
||
|
#pragma multi_compile __ _CASTCOLOR_ON
|
||
|
#pragma multi_compile __ _SCROLLMODE_SCROLL _SCROLLMODE_FLASH
|
||
|
// Physically based Standard lighting model, and enable shadows on all light types
|
||
|
#pragma surface surf SimpleSpecular vertex:myvert finalcolor:mycolor nometa nolightmap nofog noforwardadd exclude_path:deferred exclude_path:prepass
|
||
|
// Use shader model 3.0 target, to get nicer looking lighting
|
||
|
#pragma target 3.0
|
||
|
|
||
|
struct SurfaceOutput1
|
||
|
{
|
||
|
fixed3 Albedo; // diffuse color
|
||
|
fixed3 Normal; // tangent space normal, if written
|
||
|
fixed3 Emission; //
|
||
|
half3 Specular; // specular power in 0..1 range
|
||
|
fixed Gloss; // specular intensity
|
||
|
fixed Unlit;
|
||
|
fixed Alpha; // alpha for transparencies
|
||
|
};
|
||
|
|
||
|
half3 mix(half3 x, half3 y, half a)
|
||
|
{
|
||
|
return x * (1 - a) + y * a;
|
||
|
}
|
||
|
|
||
|
half4 LightingSimpleSpecular(SurfaceOutput1 s, half3 lightDir, half3 viewDir, half atten)
|
||
|
{
|
||
|
half3 h = normalize(lightDir + viewDir);
|
||
|
|
||
|
half diff = max(0, dot(s.Normal, lightDir));
|
||
|
|
||
|
float nh = max(0, dot(s.Normal, h));
|
||
|
float spec = pow(nh, s.Specular*128.0) * s.Gloss;
|
||
|
|
||
|
half4 c;
|
||
|
c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec)* atten;
|
||
|
|
||
|
h = s.Albedo + spec * atten;
|
||
|
|
||
|
c.rgb = lerp(c.rgb, h, s.Unlit);
|
||
|
c.a = s.Alpha;
|
||
|
return c;
|
||
|
}
|
||
|
|
||
|
struct Input
|
||
|
{
|
||
|
float2 uv_MainTex;
|
||
|
float2 uv_ColorTex;
|
||
|
float2 uv_ScrollTex;
|
||
|
float2 scrollAdd;
|
||
|
float3 viewDir;
|
||
|
float3 worldNormal;
|
||
|
float3 worldRefl;
|
||
|
};
|
||
|
|
||
|
sampler2D _MainTex;
|
||
|
sampler2D _ColorTex;
|
||
|
|
||
|
samplerCUBE _Cube;
|
||
|
fixed4 _ReflectColor;
|
||
|
|
||
|
fixed4 _Color;
|
||
|
half _Saturation;
|
||
|
half _Unlit;
|
||
|
|
||
|
// Scroll
|
||
|
sampler2D _ScrollTex;
|
||
|
half _ScrollPower;
|
||
|
half _ScrollSpeedX;
|
||
|
half _ScrollSpeedY;
|
||
|
|
||
|
fixed3 _RimColor;
|
||
|
half _RimPower;
|
||
|
half _RimRange;
|
||
|
|
||
|
fixed4 _CastColorR;
|
||
|
fixed4 _CastColorG;
|
||
|
fixed4 _CastColorB;
|
||
|
|
||
|
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
|
||
|
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
|
||
|
// #pragma instancing_options assumeuniformscaling
|
||
|
UNITY_INSTANCING_BUFFER_START(Props)
|
||
|
// put more per-instance properties here
|
||
|
UNITY_INSTANCING_BUFFER_END(Props)
|
||
|
|
||
|
void myvert(inout appdata_full v, out Input o)
|
||
|
{
|
||
|
UNITY_INITIALIZE_OUTPUT(Input, o);
|
||
|
#ifdef _SCROLLMODE_SCROLL
|
||
|
o.scrollAdd.xy = float2(_ScrollSpeedX, _ScrollSpeedY)*_Time.y;
|
||
|
#elif _SCROLLMODE_FLASH
|
||
|
o.scrollAdd.x = sin(_Time.y * _ScrollSpeedX * 20.0);
|
||
|
o.scrollAdd.y = sin(_Time.y * _ScrollSpeedY * 20.0);
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
void mycolor(Input IN, SurfaceOutput1 o, inout fixed4 color)
|
||
|
{
|
||
|
fixed3 rim = saturate(1 - saturate(dot(IN.worldNormal, IN.viewDir)) * _RimRange) *_RimPower * _RimColor;
|
||
|
color.rgb += rim;
|
||
|
}
|
||
|
|
||
|
void surf(Input IN, inout SurfaceOutput1 o)
|
||
|
{
|
||
|
// Albedo comes from a texture tinted by color
|
||
|
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;//
|
||
|
|
||
|
half3 cc = c.rgb;
|
||
|
#ifdef _CASTCOLOR_ON
|
||
|
fixed4 m = tex2D(_ColorTex, IN.uv_ColorTex);
|
||
|
cc = mix(cc.rgb, (_CastColorR.rgb * c.rgb), m.r);
|
||
|
cc = mix(cc.rgb, (_CastColorG.rgb * c.rgb), m.g);
|
||
|
cc = mix(cc.rgb, (_CastColorB.rgb * c.rgb), m.b);
|
||
|
#endif
|
||
|
half gray = Luminance(cc.rgb);
|
||
|
fixed3 grayColor = fixed3(gray, gray, gray);
|
||
|
cc.rgb = lerp(grayColor, cc.rgb, _Saturation);
|
||
|
|
||
|
o.Albedo = cc.rgb;
|
||
|
// Metallic and smoothness come from slider variables
|
||
|
o.Specular = 0.5f;
|
||
|
//o.Gloss = 1.0 - m.a;
|
||
|
o.Unlit = _Unlit;
|
||
|
|
||
|
fixed4 reflcol = texCUBE(_Cube, IN.worldRefl);
|
||
|
//reflcol *= (1 - m.a);
|
||
|
o.Emission = reflcol.rgb * _ReflectColor.rgb;
|
||
|
|
||
|
#ifdef _SCROLLMODE_SCROLL
|
||
|
fixed4 sc = tex2D(_ScrollTex, IN.scrollAdd + IN.uv_ScrollTex);
|
||
|
o.Emission += (sc.a * _ScrollPower) * sc.rgb;
|
||
|
#elif _SCROLLMODE_FLASH
|
||
|
fixed4 sc = tex2D(_ScrollTex, IN.uv_ScrollTex);
|
||
|
o.Emission += (sc.a * _ScrollPower * step(IN.scrollAdd.x,0))* sc.rgb;
|
||
|
cc = tex2D(_ScrollTex, -IN.uv_ScrollTex);
|
||
|
o.Emission += (sc.a * _ScrollPower * step(IN.scrollAdd.y,0))* sc.rgb;
|
||
|
#endif
|
||
|
o.Alpha = c.a;
|
||
|
}
|
||
|
ENDCG
|
||
|
}
|
||
|
|
||
|
FallBack "Diffuse"
|
||
|
}
|