// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) Shader "MY/WeaponSpecular" { Properties{ _Color("Main Color", Color) = (1,1,1,1) _SpecColor("Specular Color", Color) = (0.5,0.5,0.5,1) [PowerSlider(5.0)] _Shininess("Shininess", Range(0.01, 1)) = 0.078125 _ReflectColor("Reflection Color", Color) = (1,1,1,0.5) _MainTex("Base (RGB) RefStrGloss (A)", 2D) = "white" {} _Cube("Reflection Cubemap", Cube) = "" {} _SpecTex("Spec", 2D) = "white" {} [Header(Rim)] _RimColor("边光颜色", Color) = (0,0,0,1) _RimPower("边光强度", Range(-10,10)) = 1 _RimRange("边光范围", Range(1,10)) = 1.8 [Header(Scroll)] _ScrollTex("流光贴图(RGB)", 2D) = "black" {} _ScrollPower("流光强度", Range(-10, 10)) = 1 _ScrollSpeedX("X流光速度", Range(-10, 10)) = 0 _ScrollSpeedY("Y流光速度", Range(-10, 10)) = 0 } SubShader{ Tags { "RenderType" = "Opaque" } LOD 400 CGPROGRAM #pragma surface surf SimpleSpecular vertex:myvert /*finalcolor:mycolor*/ nometa nolightmap nofog noinstancing exclude_path:deferred exclude_path:prepass #pragma target 3.0 sampler2D _MainTex; sampler2D _SpecTex; samplerCUBE _Cube; fixed4 _Color; fixed4 _ReflectColor; half _Shininess; // Scroll sampler2D _ScrollTex; half _ScrollPower; half _ScrollSpeedX; half _ScrollSpeedY; fixed3 _RimColor; half _RimPower; half _RimRange; struct Input { float2 uv_MainTex; float2 uv_SpecTex; float2 uv_ScrollTex; float3 viewDir; //float3 worldNormal; //float3 worldRefl; float2 scrollAdd; //INTERNAL_DATA }; 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 }; 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; c.rgb = lerp(c.rgb, s.Albedo, s.Unlit); c.a = s.Alpha; return c; } void myvert(inout appdata_full v, out Input o) { UNITY_INITIALIZE_OUTPUT(Input, o); o.scrollAdd.xy = float2(_ScrollSpeedX, _ScrollSpeedY)*_Time.x; } void surf(Input IN, inout SurfaceOutput1 o) { fixed4 tex = tex2D(_MainTex, IN.uv_MainTex); fixed4 c = tex * _Color; o.Albedo = c.rgb; fixed4 spec = tex2D(_SpecTex, IN.uv_SpecTex); o.Gloss = spec.b; o.Specular = _Shininess; fixed4 scroll = tex2D(_ScrollTex, IN.scrollAdd + IN.uv_ScrollTex); o.Unlit = 1.0 - spec.r; //float3 worldRefl = WorldReflectionVector (IN, o.Normal); //fixed4 reflcol = texCUBE(_Cube, IN.worldRefl); //reflcol *= tex.a; o.Emission = /*(reflcol.rgb * _ReflectColor.rgb) +*/ ((spec.r * _ScrollPower) * scroll.rgb); //o.Alpha = reflcol.a * _ReflectColor.a; } //void mycolor(Input IN, SurfaceOutput1 o, inout fixed4 color) //{ // fixed3 rim = saturate(1 - dot(IN.worldNormal, IN.viewDir) * _RimRange) *_RimPower * _RimColor; // color.rgb += rim; //} ENDCG } FallBack "Diffuse" }