Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2014
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.55 KB | None | 0 0
  1.  
  2. Shader "Wetness_Shader" {
  3. Properties {
  4. _Gloss ("Gloss", Float ) = 0.75
  5. _Specularity ("Specularity", Float ) = 0.88
  6. _Texture ("Texture", 2D) = "white" {}
  7. _NormalMap ("Normal Map", 2D) = "bump" {}
  8. }
  9. SubShader {
  10. Tags {
  11. "RenderType"="Opaque"
  12. }
  13. Pass {
  14. Name "ForwardBase"
  15. Tags {
  16. "LightMode"="ForwardBase"
  17. }
  18.  
  19.  
  20. CGPROGRAM
  21. #pragma vertex vert
  22. #pragma fragment frag
  23. #define UNITY_PASS_FORWARDBASE
  24. #include "UnityCG.cginc"
  25. #include "AutoLight.cginc"
  26. #pragma multi_compile_fwdbase_fullshadows
  27. #pragma exclude_renderers xbox360 ps3 flash d3d11_9x
  28. #pragma target 3.0
  29. uniform float4 _LightColor0;
  30. uniform sampler2D _Texture; uniform float4 _Texture_ST;
  31. uniform float _Specularity;
  32. uniform sampler2D _NormalMap; uniform float4 _NormalMap_ST;
  33. uniform float _Gloss;
  34. struct VertexInput {
  35. float4 vertex : POSITION;
  36. float3 normal : NORMAL;
  37. float4 tangent : TANGENT;
  38. float2 texcoord0 : TEXCOORD0;
  39. };
  40. struct VertexOutput {
  41. float4 pos : SV_POSITION;
  42. float2 uv0 : TEXCOORD0;
  43. float4 posWorld : TEXCOORD1;
  44. float3 normalDir : TEXCOORD2;
  45. float3 tangentDir : TEXCOORD3;
  46. float3 binormalDir : TEXCOORD4;
  47. LIGHTING_COORDS(5,6)
  48. };
  49. VertexOutput vert (VertexInput v) {
  50. VertexOutput o;
  51. o.uv0 = v.texcoord0;
  52. o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
  53. o.tangentDir = normalize( mul( _Object2World, float4( v.tangent.xyz, 0.0 ) ).xyz );
  54. o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
  55. o.posWorld = mul(_Object2World, v.vertex);
  56. o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  57. TRANSFER_VERTEX_TO_FRAGMENT(o)
  58. return o;
  59. }
  60. fixed4 frag(VertexOutput i) : COLOR {
  61. i.normalDir = normalize(i.normalDir);
  62. float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir);
  63. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  64. /////// Normals:
  65. float2 node_158 = i.uv0;
  66. float node_148 = 0.0;
  67. float4 node_2 = tex2D(_Texture,TRANSFORM_TEX(node_158.rg, _Texture));
  68. float3 normalLocal = saturate(( saturate((node_148+node_2.b)) > 0.5 ? (1.0-(1.0-2.0*(saturate((node_148+node_2.b))-0.5))*(1.0-saturate((UnpackNormal(tex2D(_NormalMap,TRANSFORM_TEX(node_158.rg, _NormalMap))).rgb+node_148)))) : (2.0*saturate((node_148+node_2.b))*saturate((UnpackNormal(tex2D(_NormalMap,TRANSFORM_TEX(node_158.rg, _NormalMap))).rgb+node_148))) ));
  69. float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
  70. float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
  71. float3 halfDirection = normalize(viewDirection+lightDirection);
  72. ////// Lighting:
  73. float attenuation = LIGHT_ATTENUATION(i);
  74. float3 attenColor = attenuation * _LightColor0.xyz;
  75. /////// Diffuse:
  76. float NdotL = dot( normalDirection, lightDirection );
  77. float3 diffuse = max( 0.0, NdotL) * attenColor + UNITY_LIGHTMODEL_AMBIENT.rgb;
  78. ///////// Gloss:
  79. float gloss = _Gloss;
  80. float specPow = exp2( gloss * 10.0+1.0);
  81. ////// Specular:
  82. NdotL = max(0.0, NdotL);
  83. float3 specularColor = float3(_Specularity,_Specularity,_Specularity);
  84. float3 specular = (floor(attenuation) * _LightColor0.xyz) * pow(max(0,dot(halfDirection,normalDirection)),specPow) * specularColor;
  85. float3 finalColor = 0;
  86. float3 diffuseLight = diffuse;
  87. finalColor += diffuseLight * node_2.rgb;
  88. finalColor += specular;
  89. /// Final Color:
  90. return fixed4(finalColor,1);
  91. }
  92. ENDCG
  93. }
  94. Pass {
  95. Name "ForwardAdd"
  96. Tags {
  97. "LightMode"="ForwardAdd"
  98. }
  99. Blend One One
  100.  
  101.  
  102. Fog { Color (0,0,0,0) }
  103. CGPROGRAM
  104. #pragma vertex vert
  105. #pragma fragment frag
  106. #define UNITY_PASS_FORWARDADD
  107. #include "UnityCG.cginc"
  108. #include "AutoLight.cginc"
  109. #pragma multi_compile_fwdadd_fullshadows
  110. #pragma exclude_renderers xbox360 ps3 flash d3d11_9x
  111. #pragma target 3.0
  112. uniform float4 _LightColor0;
  113. uniform sampler2D _Texture; uniform float4 _Texture_ST;
  114. uniform float _Specularity;
  115. uniform sampler2D _NormalMap; uniform float4 _NormalMap_ST;
  116. uniform float _Gloss;
  117. struct VertexInput {
  118. float4 vertex : POSITION;
  119. float3 normal : NORMAL;
  120. float4 tangent : TANGENT;
  121. float2 texcoord0 : TEXCOORD0;
  122. };
  123. struct VertexOutput {
  124. float4 pos : SV_POSITION;
  125. float2 uv0 : TEXCOORD0;
  126. float4 posWorld : TEXCOORD1;
  127. float3 normalDir : TEXCOORD2;
  128. float3 tangentDir : TEXCOORD3;
  129. float3 binormalDir : TEXCOORD4;
  130. LIGHTING_COORDS(5,6)
  131. };
  132. VertexOutput vert (VertexInput v) {
  133. VertexOutput o;
  134. o.uv0 = v.texcoord0;
  135. o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
  136. o.tangentDir = normalize( mul( _Object2World, float4( v.tangent.xyz, 0.0 ) ).xyz );
  137. o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
  138. o.posWorld = mul(_Object2World, v.vertex);
  139. o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  140. TRANSFER_VERTEX_TO_FRAGMENT(o)
  141. return o;
  142. }
  143. fixed4 frag(VertexOutput i) : COLOR {
  144. i.normalDir = normalize(i.normalDir);
  145. float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir);
  146. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  147. /////// Normals:
  148. float2 node_159 = i.uv0;
  149. float node_148 = 0.0;
  150. float4 node_2 = tex2D(_Texture,TRANSFORM_TEX(node_159.rg, _Texture));
  151. float3 normalLocal = saturate(( saturate((node_148+node_2.b)) > 0.5 ? (1.0-(1.0-2.0*(saturate((node_148+node_2.b))-0.5))*(1.0-saturate((UnpackNormal(tex2D(_NormalMap,TRANSFORM_TEX(node_159.rg, _NormalMap))).rgb+node_148)))) : (2.0*saturate((node_148+node_2.b))*saturate((UnpackNormal(tex2D(_NormalMap,TRANSFORM_TEX(node_159.rg, _NormalMap))).rgb+node_148))) ));
  152. float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
  153. float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
  154. float3 halfDirection = normalize(viewDirection+lightDirection);
  155. ////// Lighting:
  156. float attenuation = LIGHT_ATTENUATION(i);
  157. float3 attenColor = attenuation * _LightColor0.xyz;
  158. /////// Diffuse:
  159. float NdotL = dot( normalDirection, lightDirection );
  160. float3 diffuse = max( 0.0, NdotL) * attenColor;
  161. ///////// Gloss:
  162. float gloss = _Gloss;
  163. float specPow = exp2( gloss * 10.0+1.0);
  164. ////// Specular:
  165. NdotL = max(0.0, NdotL);
  166. float3 specularColor = float3(_Specularity,_Specularity,_Specularity);
  167. float3 specular = attenColor * pow(max(0,dot(halfDirection,normalDirection)),specPow) * specularColor;
  168. float3 finalColor = 0;
  169. float3 diffuseLight = diffuse;
  170. finalColor += diffuseLight * node_2.rgb;
  171. finalColor += specular;
  172. /// Final Color:
  173. return fixed4(finalColor * 1,0);
  174. }
  175. ENDCG
  176. }
  177. }
  178. FallBack "Diffuse"
  179. CustomEditor "ShaderForgeMaterialInspector"
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement