ProFlaresBumpSpecShader.shader 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. Shader "ProFlares/Demo/Bumped Specular" {
  2. Properties {
  3. _Color ("Main Color", Color) = (1,1,1,1)
  4. _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
  5. _SpecPower ("SpecPower", Range (0.03, 2)) = 0.078125
  6. _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
  7. _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
  8. _SpecTex ("Spec ", 2D) = "white" {}
  9. _BumpMap ("Normalmap", 2D) = "bump" {}
  10. }
  11. SubShader {
  12. Tags { "RenderType"="Opaque" }
  13. LOD 400
  14. CGPROGRAM
  15. #pragma surface surf BlinnPhongExtra addshadow
  16. sampler2D _MainTex;
  17. sampler2D _SpecTex;
  18. sampler2D _BumpMap;
  19. fixed4 _Color;
  20. half _SpecPower;
  21. half _Shininess;
  22. struct Input {
  23. float2 uv_MainTex;
  24. float2 uv_BumpMap;
  25. fixed4 color : COLOR;
  26. };
  27. half4 LightingBlinnPhongExtra (SurfaceOutput s, fixed3 lightDir, half3 viewDir, fixed atten)
  28. {
  29. half3 h = normalize (lightDir + viewDir);
  30. fixed diff = max (0, dot (s.Normal, lightDir));
  31. float nh = max (0, dot (s.Normal, h));
  32. float spec = pow (nh, s.Specular*128.0) * s.Gloss;
  33. fixed4 c;
  34. c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * _SpecColor.rgb * spec) * (atten * 2);
  35. c.a = s.Alpha + _LightColor0.a * _SpecColor.a * spec * atten;
  36. return c;
  37. }
  38. inline fixed4 LightingBlinnPhongExtra_PrePass (SurfaceOutput s, half4 light)
  39. {
  40. fixed spec = light.a * s.Gloss;
  41. fixed4 c;
  42. c.rgb = (s.Albedo * light.rgb + light.rgb * _SpecColor.rgb * spec);
  43. c.a = s.Alpha + spec * _SpecColor.a;
  44. return c;
  45. }
  46. inline half4 LightingBlinnPhongExtra_DirLightmap (SurfaceOutput s, fixed4 color, fixed4 scale, half3 viewDir, bool surfFuncWritesNormal, out half3 specColor)
  47. {
  48. UNITY_DIRBASIS
  49. half3 scalePerBasisVector;
  50. half3 lm = DirLightmapDiffuse (unity_DirBasis, color, scale, s.Normal, surfFuncWritesNormal, scalePerBasisVector);
  51. half3 lightDir = normalize (scalePerBasisVector.x * unity_DirBasis[0] + scalePerBasisVector.y * unity_DirBasis[1] + scalePerBasisVector.z * unity_DirBasis[2]);
  52. half3 h = normalize (lightDir + viewDir);
  53. float nh = max (0, dot (s.Normal, h));
  54. float spec = pow (nh, s.Specular * 128.0);
  55. // specColor used outside in the forward path, compiled out in prepass
  56. specColor = lm * _SpecColor.rgb * s.Gloss * spec;
  57. // spec from the alpha component is used to calculate specular
  58. // in the Lighting*_Prepass function, it's not used in forward
  59. return half4(lm, spec);
  60. }
  61. void surf (Input IN, inout SurfaceOutput o) {
  62. fixed4 tex = tex2D(_MainTex, IN.uv_MainTex)*IN.color;
  63. fixed4 spec = tex2D(_SpecTex, IN.uv_MainTex)*IN.color;
  64. o.Albedo = tex.rgb * _Color.rgb;
  65. o.Gloss = spec.r;
  66. o.Alpha = tex.a * _Color.a;
  67. o.Specular = tex.a;//_Shininess*_SpecPower;
  68. o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
  69. }
  70. ENDCG
  71. }
  72. FallBack "Specular"
  73. }