123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
- ///
- /// ----- Allen 2018 -----
- /// 尝试使用rim texture和 specular texture
- /// support lambert diffuse && blinn specular
- /// 支持Unity线性的雾
- Shader "Am/FantacyQuanlity/livings_ui"
- {
- Properties {
- //diffuse 贴图
- _MainTex("Base(RGB)", 2D) = "white"{}
- //边缘发光
- _RimLookup("Rim LUT(LookUp Table)", 2D) = "white" {}
- _SpecularLookup("Specular LUT(LookUp Table", 2D) = "white" {}
- _LightProbeDiffuseStrength("LightProbe Diff Strength", Vector) = (0.5, 0.5, 0.5)
- _RealtimeDiffuseStrength("Realtime Diff Strength", Vector) = (0.5, 0.5, 0.5)
- _RealtimeLightColor("RealTime Light Color", Color) = (0.5, 0.5, 0.5)
- _RealtimeLightDirection("RealTime Light Direction", Vector) = (0, -0.5, 0)
- //最终决定贴图的alpha
- _Alpha("alpha", Range(0, 1)) = 1
- _DiffuseStr("Diffuse Strength", Range(0, 2)) = 0.5
- _LightProbeRimStrength("LightProbe Rim Strength", float) = 0.5
- _LightProbeSpecularStrength("LightProbe Spec Strength", Range(0, 1)) = 0.5
- _RealtimeRimStrength("RealTime Rim Strength", float) = 0.5
- _RealtimeSpecularStrength("RealTime Specular Strength", Range(0, 1)) = 0.5
-
- _RimClamp("Rim Clamp", float) = 0.5
- _RimColor("Rim Color", Color) = (1.0, 1.0, 1.0, 1.0)
- _RimStr("Rim Strength", float) = 0.5
- _RimSpecularMaskStrength("Rim Specular Mask Strength", float) = 0.5
- _SpecularStr("Specular Strength", Range(0, 1)) = 0.5
- _FlowColor("Flow Color", Color) = (1,1,1,1)
- _FlowRange("Flow Range", Float) = 0.01
- _BrightScale("Light scale", Float) = 0.1
- }
- SubShader {
- Tags { "Queue"="Geometry" "RenderType"="Opaque" "LightMode"="ForwardBase" }
- LOD 100
- Pass {
- CGPROGRAM
- #pragma shader_feature _SCAN_ON
- #pragma vertex vert
- #pragma fragment frag
- #pragma target 2.0
- #include "UnityCG.cginc"
- struct appdata_t
- {
- float4 vertex : POSITION;
- float2 texcoord : TEXCOORD0;
- float3 normal : NORMAL;
- };
-
- struct v2f
- {
- float4 vertex : SV_POSITION;
- float4 texcoord : TEXCOORD0; //第0,1是UV0信息, 第2是雾的距离,第3是fresnel值
- float2 angle : TEXCOORD1; //0 : lightprobe specular(UV) 1 : realtime light specular(UV)
- float3 probecolor : COLOR0;
- float3 color : COLOR1;
- float nr : TEXCOORD2;
- };
- sampler2D _MainTex;
- sampler2D _RimLookup;
- sampler2D _SpecularLookup;
- float4 _MainTex_ST;
- float3 _RealtimeLightColor;
- float3 _RealtimeLightDirection;
- float3 _RealtimeDiffuseStrength;
- float3 _LightProbeDiffuseStrength;
-
- float _Alpha;
- float _DiffuseStr;
- float _LightProbeRimStrength;
- float _LightProbeSpecularStrength;
- float _RealtimeRimStrength;
- float _RealtimeSpecularStrength;
- float _RimClamp;
- float3 _RimColor;
- float _RimStr;
- float _RimSpecularMaskStrength;
- float _SpecularStr;
- float4 _FlowColor;
- float _FlowRange;
- float _BrightScale;
- v2f vert (appdata_t v)
- {
- v2f o;
- UNITY_INITIALIZE_OUTPUT(v2f,o);
- o.vertex = UnityObjectToClipPos(v.vertex);
- // Transforms 2D UV by scale/bias property
- o.texcoord.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
-
- //获得世界坐标中的normal
- float3 worldNormal = normalize(mul((float3x3)unity_ObjectToWorld, v.normal));
- float3 worldlook = normalize(_WorldSpaceCameraPos - mul(unity_ObjectToWorld, v.vertex).xyz);
- //for fresnel
- o.texcoord.w = dot(worldlook, worldNormal);
- //use lambert's law diffuse
- float3 rt_dir_lit = -_RealtimeLightDirection;
- float ndot = max(0, dot(worldNormal, rt_dir_lit));
- float3 color = _RealtimeLightColor * ndot * _RealtimeDiffuseStrength;
- o.color = color + fixed3(1, 1, 1) * _BrightScale * max(0, dot(v.normal, rt_dir_lit));
- return o;
- }
- fixed4 frag (v2f i) : SV_Target
- {
- fixed4 col = tex2D(_MainTex, i.texcoord.xy);
- col.rgb = col.rgb * _DiffuseStr;
- fixed fresnel = i.texcoord.w;
- fixed3 rtspec = _RealtimeLightColor * tex2D(_SpecularLookup, fixed2(i.angle.y, i.angle.y)) * _RealtimeSpecularStrength;
- fixed3 reflectionContribution = rtspec * col.a * _SpecularStr;
- col.rgb = col.rgb * i.color.rgb;
- col.rgb = col.rgb + reflectionContribution;
- fixed4 rimcolor = tex2D(_RimLookup, float2(fresnel, fresnel));
- col.rgb = col.rgb + _RimColor.rgb * rimcolor.rgb * _RimStr;
- col.a = _Alpha;
- return col;
- }
- ENDCG
- }
- }
- }
|