Advertisement
Guest User

Untitled

a guest
Dec 12th, 2015
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. Shader "Custom/OpaqueShader" {
  2. Properties {
  3. dColor ("Diffuse Color", Color) = (1.0, 1.0, 1.0, 1.0)
  4. sColor ("Specular Color", Color) = (1.0, 1.0, 1.0, 1.0)
  5. sPow ("Specular Power", Float) = 50.0
  6. fPow ("Fresnel Power", Float) = 10
  7. sStre ("Specular Strength", Float) = 20.0
  8. fStre ("Fresnel Strength", Float) = 10
  9. _MainTex ("Diffuse Texture", 2D) = "white" {}
  10. }
  11. SubShader {
  12. Pass {
  13. Tags { "LightMode" = "ForwardBase" "RenderType" = "Opaque" }
  14. Cull Back
  15. CGPROGRAM
  16. #pragma vertex vert
  17. #pragma fragment frag
  18. #pragma target 3.0
  19. #pragma glsl
  20. #pragma multi_compile_fwdbase
  21. #include "UnityCG.cginc"
  22. #include "AutoLight.cginc"
  23.  
  24. sampler2D _MainTex;
  25.  
  26. float sPow;
  27. float sStre;
  28. float fPow;
  29. float fStre;
  30.  
  31. float4 dColor;
  32. float4 sColor;
  33. float4 _LightColor0;
  34.  
  35. struct vOut {
  36. float4 pos : SV_POSITION;
  37. float2 uv : TEXCOORD0;
  38. float4 pW : TEXCOORD1;
  39. float3 nW : TEXCOORD2;
  40. //float3 tW : TEXCOORD3;
  41. //float3 bI : TEXCOORD4;
  42. LIGHTING_COORDS(3,4)
  43. };
  44.  
  45. vOut vert(appdata_base v){
  46. vOut o;
  47.  
  48. o.nW = normalize( mul( float4(v.normal, 0.0), _World2Object).xyz);
  49. //o.tW = normalize( mul(_Object2World, v.tangent).xyz );
  50. //o.bI = normalize( cross(o.nW, o.tW) * v.tangent.w);
  51.  
  52. o.pW = mul(_Object2World, v.vertex);
  53. o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  54. o.uv = v.texcoord.xy;
  55.  
  56. TRANSFER_VERTEX_TO_FRAGMENT(o);
  57.  
  58. return o;
  59. }
  60.  
  61. float4 frag(vOut i) : COLOR {
  62. float3 l = normalize( _WorldSpaceLightPos0.xyz );
  63. float3 n = normalize( i.nW );
  64. float3 v = normalize( _WorldSpaceCameraPos.xyz - i.pW.xyz );
  65. float3 h = normalize(v + l);
  66. float at = LIGHT_ATTENUATION(i);
  67.  
  68. float3 ndotL = _LightColor0.rgb * saturate( dot(n, l)) * dColor.rgb;
  69. float3 spec = (saturate( pow(dot(n, v), sPow)) * sColor.rgb) * sStre;
  70. float3 fres = saturate(1.0f - pow(dot(v, n), fPow)) * fStre;
  71.  
  72. spec *= ndotL;
  73. fres *= ndotL;
  74. ndotL *= at;
  75. spec *= at;
  76. fres *= at;
  77.  
  78. return float4(ndotL + spec + fres, 1.0);
  79. }
  80.  
  81. ENDCG
  82. }
  83. }
  84. Fallback "Diffuse"
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement