Advertisement
Guest User

Untitled

a guest
Aug 12th, 2012
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. Shader "Custom/piGlowShader"
  2. {
  3. Properties
  4. {
  5. _Color ("_Color:" , Color) = (1,1,1,1)
  6.  
  7. _Specular ("_Specular:" , Color) = (1,1,1,1)
  8. _Shininess ("_Shininess:" , float) = 0.5
  9.  
  10. _Glow ("_Glow:" , float) = 0.0
  11. }
  12.  
  13.  
  14. SubShader
  15. {
  16. Pass
  17. {
  18. Name "FORWARD"
  19. Tags { "RenderType"="Opaque" "LightMode"="ForwardBase"}
  20.  
  21. Lighting On
  22.  
  23. // - - - - - - -
  24.  
  25. CGPROGRAM
  26.  
  27. #pragma vertex vertex_shader
  28. #pragma fragment fragment_shader
  29.  
  30. #pragma fragmentoption ARB_precision_hint_fastest
  31. #pragma multi_compile_fwdbase
  32.  
  33.  
  34. #include "HLSLSupport.cginc"
  35. #include "UnityCG.cginc"
  36. #include "Lighting.cginc"
  37. #include "AutoLight.cginc"
  38.  
  39.  
  40. // important to pass the properties here
  41. float4 _Color;
  42. float4 _Specular;
  43. float _Shininess;
  44. float _Glow;
  45.  
  46.  
  47. struct v2f
  48. {
  49. float4 position : POSITION;
  50. float4 color : COLOR;
  51. };
  52.  
  53.  
  54. // Lighting Function
  55. inline half3 LightingLambertVS (half3 normal, half3 lightDir)
  56. {
  57. half diff = max ( 0, dot( normal, lightDir ) );
  58. return _LightColor0.rgb * (diff * 2);
  59. }
  60.  
  61.  
  62. v2f vertex_shader ( appdata_base i)
  63. {
  64. v2f o;
  65.  
  66. o.position = mul(UNITY_MATRIX_MVP, i.vertex);
  67.  
  68.  
  69. // - - - AMBIENT - - -
  70.  
  71. o.color = UNITY_LIGHTMODEL_AMBIENT * _Color;
  72.  
  73.  
  74. // - - - DIFFUSE - - -
  75.  
  76. float3 worldN = mul((float3x3)_Object2World, i.normal);
  77.  
  78. float LdotN = saturate( dot ( _WorldSpaceLightPos0, worldN ) );
  79.  
  80. o.color += LdotN * _Color * _LightColor0;
  81.  
  82.  
  83. // - - - SPECULAR - - -
  84. float3 L = normalize( ObjSpaceLightDir( i.vertex ) );
  85. float3 V = normalize( ObjSpaceViewDir( i.vertex ) );
  86. float3 H = normalize( L + V );
  87.  
  88. float NdotH = saturate( dot (i.normal, H) );
  89.  
  90. float4 spec = _Specular * _LightColor0 * pow( NdotH, _Shininess * 128 );
  91.  
  92. o.color += spec;
  93.  
  94. // - - - GLOW - - -
  95.  
  96. float4 glow = _Glow * LdotN * _LightColor0;
  97. o.color += glow;
  98.  
  99. // - - - - -
  100.  
  101. return o;
  102. }
  103.  
  104. float4 fragment_shader( v2f i ) : COLOR
  105. {
  106. return i.color;
  107. }
  108. ENDCG
  109.  
  110. // - - - - - - -
  111.  
  112. }
  113. }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement