StandardAlpha.shader 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. Shader "TriLib/StandardAlpha"
  2. {
  3. Properties
  4. {
  5. //_MetallicGlossMap
  6. [NoScaleOffset]_MainTex("_MainTex", 2D) = "white" {}
  7. [HDR]_Color("_Color", Color) = (1, 1, 1, 1)
  8. _Cutoff("_Cutoff", Range(0, 1)) = 0.5
  9. [NoScaleOffset][Normal]_BumpMap("_BumpMap", 2D) = "white" {}
  10. _BumpScale("_BumpScale", Range(0, 1)) = 1
  11. [NoScaleOffset]_EmissionMap("_EmissionMap", 2D) = "white" {}
  12. [HDR]_EmissionColor("_EmissionColor", Color) = (0, 0, 0, 0)
  13. _Metallic("_Metallic", Range(0, 1)) = 0
  14. _Glossiness("_Glossiness", Range(0, 1)) = 0
  15. [NoScaleOffset]_OcclusionMap("_OcclusionMap", 2D) = "white" {}
  16. _OcclusionStrength("_OcclusionStrength", Float) = 1
  17. _Tilling("_Tilling", Vector) = (1, 1, 0, 0)
  18. _Offset("_Offset", Vector) = (0, 0, 0, 0)
  19. [NoScaleOffset]_MetallicGlossMap("_MetallicGlossMap", 2D) = "white" {}
  20. [NoScaleOffset]_SpecGlossMap("_SpecGlossMap", 2D) = "white" {}
  21. [KeywordEnum(Fade, Transparent)] _TRANSPARENCY("_TRANSPARENCY", Float) = 1
  22. [KeywordEnum(Standard, Specular, Roughness)] _TYPE("_TYPE", Float) = 0
  23. }
  24. SubShader
  25. {
  26. Tags { "Queue" = "Transparent" "RenderType" = "Transparent"}
  27. Cull Off
  28. LOD 200
  29. CGPROGRAM
  30. #if _TRANSPARENCY_FADE
  31. #if _TYPE_STANDARD
  32. #pragma surface surf Standard fullforwardshadows alpha:fade
  33. #elif _TYPE_SPECULAR
  34. #pragma surface surf StandardSpecular fullforwardshadows alpha:fade
  35. #else
  36. #pragma surface surf Standard fullforwardshadows alpha:fade
  37. #endif
  38. #else
  39. #if _TYPE_STANDARD
  40. #pragma surface surf Standard fullforwardshadows alpha:blend
  41. #elif _TYPE_SPECULAR
  42. #pragma surface surf StandardSpecular fullforwardshadows alpha:blend
  43. #else
  44. #pragma surface surf Standard fullforwardshadows alpha:blend
  45. #endif
  46. #endif
  47. #pragma target 3.0
  48. struct Input
  49. {
  50. float2 uv_MainTex;
  51. fixed facing : VFACE;
  52. };
  53. sampler2D _MainTex;
  54. float4 _Color;
  55. float _Cutoff;
  56. sampler2D _BumpMap;
  57. float _BumpScale;
  58. sampler2D _EmissionMap;
  59. float4 _EmissionColor;
  60. float _Metallic;
  61. float _Glossiness;
  62. sampler2D _OcclusionMap;
  63. float _OcclusionStrength;
  64. float2 _Tilling;
  65. float2 _Offset;
  66. sampler2D _MetallicGlossMap;
  67. sampler2D _SpecGlossMap;
  68. UNITY_INSTANCING_BUFFER_START(Props)
  69. UNITY_INSTANCING_BUFFER_END(Props)
  70. void surf (Input IN, inout SurfaceOutputStandard o)
  71. {
  72. float2 uv = IN.uv_MainTex + _Offset * _Tilling;
  73. float4 c = tex2D(_MainTex, uv) * _Color;
  74. if (c.a > _Cutoff) {
  75. discard;
  76. }
  77. o.Albedo = c.xyz;
  78. #if _TYPE_STANDARD
  79. float4 glossmap = tex2D(_MetallicGlossMap, IN.uv_MainTex);
  80. o.Metallic = glossmap.r * _Metallic;
  81. o.Smoothness = glossmap.a * _Glossiness;
  82. #else
  83. float4 specmap = tex2D(_SpecGlossMap, IN.uv_MainTex);
  84. o.Metallic = 0.0;
  85. o.Smoothness = specmap.a * _Glossiness;
  86. #endif
  87. o.Occlusion = tex2D(_OcclusionMap, uv) * _OcclusionStrength;
  88. o.Normal = tex2D(_BumpMap, uv).xyz * _BumpScale;
  89. if (IN.facing < 0.5)
  90. {
  91. o.Normal *= -1.0;
  92. }
  93. o.Emission = tex2D(_EmissionMap, uv).xyz * _EmissionColor.xyz;
  94. o.Alpha = c.a;
  95. }
  96. ENDCG
  97. }
  98. FallBack "Diffuse"
  99. }