Advertisement
Guest User

Shader

a guest
Jan 29th, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1.  
  2. Shader "Surface/Colored Specular Bumped with Illumination" {
  3. Properties {
  4. _MainTex ("Texture", 2D) = "white" {}
  5. _SpecMap ("SpecMap(RGB) Illum(A)", 2D) = "white" {}
  6. _BumpMap ("Normalmap", 2D) = "bump" {}
  7. _Shininess ("Shininess", Range (0.01, 1)) = 0.078125
  8. _CubeMap ("Reflections" ,CUBE)="" {}
  9. _ReflectionAmmount ("Reflection Ammount", Range(0.0,1.0)) = 0.0
  10. }
  11. SubShader {
  12. Tags { "RenderType" = "Opaque" }
  13. LOD 1
  14. CGPROGRAM
  15. #pragma surface surf ColoredSpecular
  16. #pragma target 3.0
  17. struct MySurfaceOutput {
  18. half3 Albedo;
  19. half3 Normal;
  20. half3 Emission;
  21. half Specular;
  22. half3 GlossColor;
  23. half Alpha;
  24. };
  25.  
  26.  
  27. inline half4 LightingColoredSpecular (MySurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
  28. {
  29. half3 h = normalize (lightDir + viewDir);
  30.  
  31. half diff = max (0, dot (s.Normal, lightDir));
  32.  
  33. float nh = max (0, dot (s.Normal, h));
  34. float spec = pow (nh, 32.0 * s.Specular);
  35. half3 specCol = spec * s.GlossColor;
  36.  
  37. half4 c;
  38. c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * specCol) * (atten * 2);
  39. c.a = s.Alpha;
  40. return c;
  41. }
  42.  
  43. inline half4 LightingColoredSpecular_PrePass (MySurfaceOutput s, half4 light)
  44. {
  45. half3 spec = light.a * s.GlossColor;
  46.  
  47. half4 c;
  48. c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
  49. c.a = s.Alpha + spec * _SpecColor.a;
  50. return c;
  51. }
  52.  
  53.  
  54. struct Input {
  55. float2 uv_MainTex;
  56. float2 uv_SpecMap;
  57. float2 uv_BumpMap;
  58. float3 worldRefl;
  59. INTERNAL_DATA
  60. };
  61.  
  62. sampler2D _MainTex;
  63. sampler2D _SpecMap;
  64. sampler2D _BumpMap;
  65. samplerCUBE _CubeMap;
  66. half4 _Color;
  67. half _Shininess;
  68. float _ReflectionAmmount;
  69.  
  70. void surf (Input IN, inout MySurfaceOutput o)
  71. {
  72. half3 c = tex2D (_MainTex, IN.uv_MainTex).rgb;
  73. o.Albedo = c;
  74. half4 spec = tex2D (_SpecMap, IN.uv_SpecMap);
  75. o.GlossColor = spec.rgb;
  76. o.Emission = texCUBE(_CubeMap, WorldReflectionVector(IN,o.Normal)).rgb*_ReflectionAmmount;
  77. o.Specular = _Shininess;
  78. o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
  79. }
  80. ENDCG
  81. }
  82. Fallback "Diffuse"
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement