源战役客户端
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

394 líneas
18 KiB

  1. Shader "MyShader/PlantAni" {
  2. Properties {
  3. _Color ("Color", Color) = (1,1,0.7,1)
  4. _Diffuse ("Diffuse", 2D) = "white" {}
  5. _Normal ("Normal", 2D) = "bump" {}
  6. _Bright ("Bright", Range(0, 1)) = 1
  7. _VertexIntensity ("VertexIntensity", Range(0, 1)) = 0.02
  8. [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
  9. }
  10. SubShader {
  11. Tags {
  12. "Queue"="AlphaTest"
  13. "RenderType"="TransparentCutout"
  14. }
  15. Pass {
  16. Name "FORWARD"
  17. Tags {
  18. "LightMode"="ForwardBase"
  19. }
  20. Cull Off
  21. AlphaToMask On
  22. CGPROGRAM
  23. #pragma vertex vert
  24. #pragma fragment frag
  25. #define UNITY_PASS_FORWARDBASE
  26. #include "AutoLight.cginc"
  27. #include "Lighting.cginc"
  28. #pragma multi_compile_fwdbase_fullshadows
  29. #pragma multi_compile_fog
  30. uniform float4 _TimeEditor;
  31. uniform sampler2D _Diffuse; uniform float4 _Diffuse_ST;
  32. uniform sampler2D _Normal; uniform float4 _Normal_ST;
  33. uniform float _Bright;
  34. uniform float4 _Color;
  35. uniform float _VertexIntensity;
  36. struct VertexInput {
  37. float4 vertex : POSITION;
  38. float3 normal : NORMAL;
  39. float4 tangent : TANGENT;
  40. float2 texcoord0 : TEXCOORD0;
  41. float2 texcoord1 : TEXCOORD1;
  42. float2 texcoord2 : TEXCOORD2;
  43. float4 vertexColor : COLOR;
  44. };
  45. struct VertexOutput {
  46. float4 pos : SV_POSITION;
  47. float2 uv0 : TEXCOORD0;
  48. float2 uv1 : TEXCOORD1;
  49. float2 uv2 : TEXCOORD2;
  50. float4 posWorld : TEXCOORD3;
  51. float3 normalDir : TEXCOORD4;
  52. float3 tangentDir : TEXCOORD5;
  53. float3 bitangentDir : TEXCOORD6;
  54. float4 vertexColor : COLOR;
  55. LIGHTING_COORDS(7,8)
  56. UNITY_FOG_COORDS(9)
  57. #if defined(LIGHTMAP_ON) || defined(UNITY_SHOULD_SAMPLE_SH)
  58. float4 ambientOrLightmapUV : TEXCOORD10;
  59. #endif
  60. };
  61. VertexOutput vert (VertexInput v) {
  62. VertexOutput o = (VertexOutput)0;
  63. o.uv0 = v.texcoord0;
  64. o.uv1 = v.texcoord1;
  65. o.uv2 = v.texcoord2;
  66. o.vertexColor = v.vertexColor;
  67. #ifdef LIGHTMAP_ON
  68. o.ambientOrLightmapUV.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
  69. o.ambientOrLightmapUV.zw = 0;
  70. #elif UNITY_SHOULD_SAMPLE_SH
  71. #endif
  72. #ifdef DYNAMICLIGHTMAP_ON
  73. o.ambientOrLightmapUV.zw = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
  74. #endif
  75. o.normalDir = UnityObjectToWorldNormal(v.normal);
  76. o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz );
  77. o.bitangentDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
  78. float4 AllTime = _Time + _TimeEditor;
  79. v.vertex.xyz += (normalize((float3(1,0,0)+v.normal))*o.vertexColor.r*sin(((o.vertexColor.r*3.141592654)+AllTime.g))*_VertexIntensity);
  80. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  81. float3 lightColor = _LightColor0.rgb;
  82. o.pos = UnityObjectToClipPos( v.vertex );
  83. UNITY_TRANSFER_FOG(o,o.pos);
  84. TRANSFER_VERTEX_TO_FRAGMENT(o)
  85. return o;
  86. }
  87. float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
  88. float isFrontFace = ( facing >= 0 ? 1 : 0 );
  89. float faceSign = ( facing >= 0 ? 1 : -1 );
  90. i.normalDir = normalize(i.normalDir);
  91. i.normalDir *= faceSign;
  92. float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);
  93. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  94. float3 _Normal_var = UnpackNormal(tex2D(_Normal,TRANSFORM_TEX(i.uv0, _Normal)));
  95. float3 normalLocal = _Normal_var.rgb;
  96. float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
  97. float3 viewReflectDirection = reflect( -viewDirection, normalDirection );
  98. float4 _Diffuse_var = tex2D(_Diffuse,TRANSFORM_TEX(i.uv0, _Diffuse));
  99. clip(_Diffuse_var.a - 0.5);
  100. float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
  101. float3 lightColor = _LightColor0.rgb;
  102. float3 halfDirection = normalize(viewDirection+lightDirection);
  103. float attenuation = LIGHT_ATTENUATION(i);
  104. float3 attenColor = attenuation * _LightColor0.xyz;
  105. float gloss = 0.4;
  106. float specPow = exp2( gloss * 10.0 + 1.0 );
  107. UnityLight light;
  108. #ifdef LIGHTMAP_OFF
  109. light.color = lightColor;
  110. light.dir = lightDirection;
  111. light.ndotl = LambertTerm (normalDirection, light.dir);
  112. #else
  113. light.color = half3(0.f, 0.f, 0.f);
  114. light.ndotl = 0.0f;
  115. light.dir = half3(0.f, 0.f, 0.f);
  116. #endif
  117. UnityGIInput d;
  118. d.light = light;
  119. d.worldPos = i.posWorld.xyz;
  120. d.worldViewDir = viewDirection;
  121. d.atten = attenuation;
  122. #if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON)
  123. d.ambient = 0;
  124. d.lightmapUV = i.ambientOrLightmapUV;
  125. #else
  126. d.ambient = i.ambientOrLightmapUV;
  127. #endif
  128. Unity_GlossyEnvironmentData ugls_en_data;
  129. ugls_en_data.roughness = 1.0 - gloss;
  130. ugls_en_data.reflUVW = viewReflectDirection;
  131. UnityGI gi = UnityGlobalIllumination(d, 1, normalDirection, ugls_en_data );
  132. lightDirection = gi.light.dir;
  133. lightColor = gi.light.color;
  134. float NdotL = saturate(dot( normalDirection, lightDirection ));
  135. float3 specularColor = float3(0.2,0.2,0.2);
  136. float3 directSpecular = attenColor * pow(max(0,dot(halfDirection,normalDirection)),specPow)*specularColor;
  137. float3 specular = directSpecular;
  138. NdotL = max(0.0,dot( normalDirection, lightDirection ));
  139. float3 directDiffuse = max( 0.0, NdotL) * attenColor;
  140. float3 indirectDiffuse = float3(0,0,0);
  141. indirectDiffuse += gi.indirect.diffuse;
  142. float3 diffuseColor = (_Color.rgb*_Diffuse_var.rgb);
  143. float3 diffuse = (directDiffuse + indirectDiffuse) * diffuseColor;
  144. float3 emissive = (_Diffuse_var.rgb*_Bright);
  145. float3 finalColor = diffuse + specular + emissive;
  146. fixed4 finalRGBA = fixed4(finalColor,(_Diffuse_var.a) * 2.0 - 1.0);
  147. UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
  148. return finalRGBA;
  149. }
  150. ENDCG
  151. }
  152. Pass {
  153. Name "FORWARD_DELTA"
  154. Tags {
  155. "LightMode"="ForwardAdd"
  156. }
  157. Blend One One
  158. Cull Off
  159. CGPROGRAM
  160. #pragma vertex vert
  161. #pragma fragment frag
  162. #define UNITY_PASS_FORWARDADD
  163. #include "AutoLight.cginc"
  164. #include "Lighting.cginc"
  165. #pragma multi_compile_fog
  166. uniform float4 _TimeEditor;
  167. uniform sampler2D _Diffuse; uniform float4 _Diffuse_ST;
  168. uniform sampler2D _Normal; uniform float4 _Normal_ST;
  169. uniform float _Bright;
  170. uniform float4 _Color;
  171. uniform float _VertexIntensity;
  172. struct VertexInput {
  173. float4 vertex : POSITION;
  174. float3 normal : NORMAL;
  175. float4 tangent : TANGENT;
  176. float2 texcoord0 : TEXCOORD0;
  177. float2 texcoord1 : TEXCOORD1;
  178. float2 texcoord2 : TEXCOORD2;
  179. float4 vertexColor : COLOR;
  180. };
  181. struct VertexOutput {
  182. float4 pos : SV_POSITION;
  183. float2 uv0 : TEXCOORD0;
  184. float2 uv1 : TEXCOORD1;
  185. float2 uv2 : TEXCOORD2;
  186. float4 posWorld : TEXCOORD3;
  187. float3 normalDir : TEXCOORD4;
  188. float3 tangentDir : TEXCOORD5;
  189. float3 bitangentDir : TEXCOORD6;
  190. float4 vertexColor : COLOR;
  191. LIGHTING_COORDS(7,8)
  192. UNITY_FOG_COORDS(9)
  193. };
  194. VertexOutput vert (VertexInput v) {
  195. VertexOutput o = (VertexOutput)0;
  196. o.uv0 = v.texcoord0;
  197. o.uv1 = v.texcoord1;
  198. o.uv2 = v.texcoord2;
  199. o.vertexColor = v.vertexColor;
  200. o.normalDir = UnityObjectToWorldNormal(v.normal);
  201. o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz );
  202. o.bitangentDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
  203. float4 AllTime = _Time + _TimeEditor;
  204. v.vertex.xyz += (normalize((float3(1,0,0)+v.normal))*o.vertexColor.r*sin(((o.vertexColor.r*3.141592654)+AllTime.g))*_VertexIntensity);
  205. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  206. float3 lightColor = _LightColor0.rgb;
  207. o.pos = UnityObjectToClipPos( v.vertex );
  208. UNITY_TRANSFER_FOG(o,o.pos);
  209. TRANSFER_VERTEX_TO_FRAGMENT(o)
  210. return o;
  211. }
  212. float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
  213. float isFrontFace = ( facing >= 0 ? 1 : 0 );
  214. float faceSign = ( facing >= 0 ? 1 : -1 );
  215. i.normalDir = normalize(i.normalDir);
  216. i.normalDir *= faceSign;
  217. float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);
  218. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  219. float3 _Normal_var = UnpackNormal(tex2D(_Normal,TRANSFORM_TEX(i.uv0, _Normal)));
  220. float3 normalLocal = _Normal_var.rgb;
  221. float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
  222. float4 _Diffuse_var = tex2D(_Diffuse,TRANSFORM_TEX(i.uv0, _Diffuse));
  223. clip(_Diffuse_var.a - 0.5);
  224. float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
  225. float3 lightColor = _LightColor0.rgb;
  226. float3 halfDirection = normalize(viewDirection+lightDirection);
  227. float attenuation = LIGHT_ATTENUATION(i);
  228. float3 attenColor = attenuation * _LightColor0.xyz;
  229. float gloss = 0.4;
  230. float specPow = exp2( gloss * 10.0 + 1.0 );
  231. float NdotL = saturate(dot( normalDirection, lightDirection ));
  232. float3 specularColor = float3(0.2,0.2,0.2);
  233. float3 directSpecular = attenColor * pow(max(0,dot(halfDirection,normalDirection)),specPow)*specularColor;
  234. float3 specular = directSpecular;
  235. NdotL = max(0.0,dot( normalDirection, lightDirection ));
  236. float3 directDiffuse = max( 0.0, NdotL) * attenColor;
  237. float3 diffuseColor = (_Color.rgb*_Diffuse_var.rgb);
  238. float3 diffuse = directDiffuse * diffuseColor;
  239. float3 finalColor = diffuse + specular;
  240. fixed4 finalRGBA = fixed4(finalColor * 1,0);
  241. UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
  242. return finalRGBA;
  243. }
  244. ENDCG
  245. }
  246. Pass {
  247. Name "ShadowCaster"
  248. Tags {
  249. "LightMode"="ShadowCaster"
  250. }
  251. Offset 1, 1
  252. Cull Off
  253. CGPROGRAM
  254. #pragma vertex vert
  255. #pragma fragment frag
  256. #define UNITY_PASS_SHADOWCASTER
  257. #include "Lighting.cginc"
  258. #pragma multi_compile_shadowcaster
  259. #pragma multi_compile_fog
  260. uniform float4 _TimeEditor;
  261. uniform sampler2D _Diffuse; uniform float4 _Diffuse_ST;
  262. uniform float _VertexIntensity;
  263. struct VertexInput {
  264. float4 vertex : POSITION;
  265. float3 normal : NORMAL;
  266. float2 texcoord0 : TEXCOORD0;
  267. float2 texcoord1 : TEXCOORD1;
  268. float2 texcoord2 : TEXCOORD2;
  269. float4 vertexColor : COLOR;
  270. };
  271. struct VertexOutput {
  272. V2F_SHADOW_CASTER;
  273. float2 uv0 : TEXCOORD1;
  274. float2 uv1 : TEXCOORD2;
  275. float2 uv2 : TEXCOORD3;
  276. float4 posWorld : TEXCOORD4;
  277. float3 normalDir : TEXCOORD5;
  278. float4 vertexColor : COLOR;
  279. };
  280. VertexOutput vert (VertexInput v) {
  281. VertexOutput o = (VertexOutput)0;
  282. o.uv0 = v.texcoord0;
  283. o.uv1 = v.texcoord1;
  284. o.uv2 = v.texcoord2;
  285. o.vertexColor = v.vertexColor;
  286. o.normalDir = UnityObjectToWorldNormal(v.normal);
  287. float4 AllTime = _Time + _TimeEditor;
  288. v.vertex.xyz += (normalize((float3(1,0,0)+v.normal))*o.vertexColor.r*sin(((o.vertexColor.r*3.141592654)+AllTime.g))*_VertexIntensity);
  289. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  290. o.pos = UnityObjectToClipPos( v.vertex );
  291. TRANSFER_SHADOW_CASTER(o)
  292. return o;
  293. }
  294. float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
  295. float isFrontFace = ( facing >= 0 ? 1 : 0 );
  296. float faceSign = ( facing >= 0 ? 1 : -1 );
  297. i.normalDir = normalize(i.normalDir);
  298. i.normalDir *= faceSign;
  299. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  300. float3 normalDirection = i.normalDir;
  301. float4 _Diffuse_var = tex2D(_Diffuse,TRANSFORM_TEX(i.uv0, _Diffuse));
  302. clip(_Diffuse_var.a - 0.5);
  303. SHADOW_CASTER_FRAGMENT(i)
  304. }
  305. ENDCG
  306. }
  307. Pass {
  308. Name "Meta"
  309. Tags {
  310. "LightMode"="Meta"
  311. }
  312. Cull Off
  313. CGPROGRAM
  314. #pragma vertex vert
  315. #pragma fragment frag
  316. #define UNITY_PASS_META 1
  317. #include "Lighting.cginc"
  318. #include "UnityMetaPass.cginc"
  319. #pragma multi_compile_shadowcaster
  320. #pragma multi_compile_fog
  321. uniform float4 _TimeEditor;
  322. uniform sampler2D _Diffuse; uniform float4 _Diffuse_ST;
  323. uniform float _Bright;
  324. uniform float4 _Color;
  325. uniform float _VertexIntensity;
  326. struct VertexInput {
  327. float4 vertex : POSITION;
  328. float3 normal : NORMAL;
  329. float2 texcoord0 : TEXCOORD0;
  330. float2 texcoord1 : TEXCOORD1;
  331. float2 texcoord2 : TEXCOORD2;
  332. float4 vertexColor : COLOR;
  333. };
  334. struct VertexOutput {
  335. float4 pos : SV_POSITION;
  336. float2 uv0 : TEXCOORD0;
  337. float2 uv1 : TEXCOORD1;
  338. float2 uv2 : TEXCOORD2;
  339. float4 posWorld : TEXCOORD3;
  340. float3 normalDir : TEXCOORD4;
  341. float4 vertexColor : COLOR;
  342. };
  343. VertexOutput vert (VertexInput v) {
  344. VertexOutput o = (VertexOutput)0;
  345. o.uv0 = v.texcoord0;
  346. o.uv1 = v.texcoord1;
  347. o.uv2 = v.texcoord2;
  348. o.vertexColor = v.vertexColor;
  349. o.normalDir = UnityObjectToWorldNormal(v.normal);
  350. float4 AllTime = _Time + _TimeEditor;
  351. v.vertex.xyz += (normalize((float3(1,0,0)+v.normal))*o.vertexColor.r*sin(((o.vertexColor.r*3.141592654)+AllTime.g))*_VertexIntensity);
  352. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  353. o.pos = UnityMetaVertexPosition(v.vertex, v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST );
  354. return o;
  355. }
  356. float4 frag(VertexOutput i, float facing : VFACE) : SV_Target {
  357. float isFrontFace = ( facing >= 0 ? 1 : 0 );
  358. float faceSign = ( facing >= 0 ? 1 : -1 );
  359. i.normalDir = normalize(i.normalDir);
  360. i.normalDir *= faceSign;
  361. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  362. float3 normalDirection = i.normalDir;
  363. UnityMetaInput o;
  364. UNITY_INITIALIZE_OUTPUT( UnityMetaInput, o );
  365. float4 _Diffuse_var = tex2D(_Diffuse,TRANSFORM_TEX(i.uv0, _Diffuse));
  366. o.Emission = (_Diffuse_var.rgb*_Bright);
  367. float3 diffColor = (_Color.rgb*_Diffuse_var.rgb);
  368. float3 specColor = float3(0.2,0.2,0.2);
  369. float roughness = 1.0 - 0.4;
  370. o.Albedo = diffColor + specColor * roughness * roughness * 0.5;
  371. return UnityMetaFragment( o );
  372. }
  373. ENDCG
  374. }
  375. }
  376. FallBack "Transparent/Cutout/Diffuse"
  377. }