1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- Shader "ProFlares/Demo/Bumped Specular" {
- Properties {
- _Color ("Main Color", Color) = (1,1,1,1)
- _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
- _SpecPower ("SpecPower", Range (0.03, 2)) = 0.078125
- _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
- _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
- _SpecTex ("Spec ", 2D) = "white" {}
- _BumpMap ("Normalmap", 2D) = "bump" {}
- }
- SubShader {
- Tags { "RenderType"="Opaque" }
- LOD 400
-
- CGPROGRAM
- #pragma surface surf BlinnPhongExtra addshadow
- sampler2D _MainTex;
- sampler2D _SpecTex;
- sampler2D _BumpMap;
- fixed4 _Color;
- half _SpecPower;
- half _Shininess;
- struct Input {
- float2 uv_MainTex;
- float2 uv_BumpMap;
- fixed4 color : COLOR;
- };
- half4 LightingBlinnPhongExtra (SurfaceOutput s, fixed3 lightDir, half3 viewDir, fixed atten)
- {
- half3 h = normalize (lightDir + viewDir);
-
- fixed 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;
-
- fixed4 c;
- c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * _SpecColor.rgb * spec) * (atten * 2);
- c.a = s.Alpha + _LightColor0.a * _SpecColor.a * spec * atten;
- return c;
- }
- inline fixed4 LightingBlinnPhongExtra_PrePass (SurfaceOutput s, half4 light)
- {
- fixed spec = light.a * s.Gloss;
-
- fixed4 c;
- c.rgb = (s.Albedo * light.rgb + light.rgb * _SpecColor.rgb * spec);
- c.a = s.Alpha + spec * _SpecColor.a;
- return c;
- }
- inline half4 LightingBlinnPhongExtra_DirLightmap (SurfaceOutput s, fixed4 color, fixed4 scale, half3 viewDir, bool surfFuncWritesNormal, out half3 specColor)
- {
- UNITY_DIRBASIS
- half3 scalePerBasisVector;
-
- half3 lm = DirLightmapDiffuse (unity_DirBasis, color, scale, s.Normal, surfFuncWritesNormal, scalePerBasisVector);
-
- half3 lightDir = normalize (scalePerBasisVector.x * unity_DirBasis[0] + scalePerBasisVector.y * unity_DirBasis[1] + scalePerBasisVector.z * unity_DirBasis[2]);
- half3 h = normalize (lightDir + viewDir);
- float nh = max (0, dot (s.Normal, h));
- float spec = pow (nh, s.Specular * 128.0);
-
- // specColor used outside in the forward path, compiled out in prepass
- specColor = lm * _SpecColor.rgb * s.Gloss * spec;
-
- // spec from the alpha component is used to calculate specular
- // in the Lighting*_Prepass function, it's not used in forward
- return half4(lm, spec);
- }
- void surf (Input IN, inout SurfaceOutput o) {
- fixed4 tex = tex2D(_MainTex, IN.uv_MainTex)*IN.color;
- fixed4 spec = tex2D(_SpecTex, IN.uv_MainTex)*IN.color;
- o.Albedo = tex.rgb * _Color.rgb;
- o.Gloss = spec.r;
- o.Alpha = tex.a * _Color.a;
- o.Specular = tex.a;//_Shininess*_SpecPower;
- o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
- }
- ENDCG
- }
- FallBack "Specular"
- }
|