New_Hair.shader 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. Shader "New_hair"
  2. {
  3. Properties
  4. {
  5. [Header(BaseInfo)]
  6. [Space(8)]
  7. [Enum(UnityEngine.Rendering.CullMode)]
  8. _Cull ("Culling", Float) = 0
  9. [Toggle(_ENABLEVFACE)]
  10. _EnableVest ("Black Vest", Float) = 0
  11. [Enum(Off,0,On,1)]_Coverage ("Alpha To Coverage", Float) = 1
  12. _BaseMap("Albedo (RGB) Alpha (A)", 2D) = "white" {}
  13. _BaseColor ("Base Color", Color) = (1,1,1,1)
  14. _BumpMap ("Normal Map", 2D) = "bump" {}
  15. _BumpScale ("Normal Str", Float) = 1.0
  16. [NoScaleOffset] _MaskMap ("Shift(B) Occ(G)", 2D) = "white" {}
  17. _SpecColor ("Specular", Color) = (0.2, 0.2, 0.2)
  18. _Smoothness ("Smoothness", Range(0.0, 1.0)) = 1
  19. [KeywordEnum(Bitangent,Tangent)]
  20. _StrandDir ("Connect Direction", Float) = 0
  21. _SpecularShift ("Specular Shift", Range(-1.0, 1.0)) = 0.1
  22. [HDR] _SpecularTint ("Specular Tint", Color) = (1, 1, 1, 1)
  23. _SpecularExponent ("Smoothness", Range(0.0, 1)) = .85
  24. [Toggle(_RIMLIGHTING)]
  25. _Rim ("Rim Lighting", Float) = 0
  26. [HDR] _RimColor ("Rim Color", Color) = (0.5,0.5,0.5,1)
  27. _RimPower ("Rim Power", Float) = 2
  28. }
  29. SubShader
  30. {
  31. Tags { "RenderType" = "Opaque" }
  32. LOD 100
  33. Pass
  34. {
  35. Name "ForwardLit"
  36. Tags{"LightMode" = "UniversalForward"}
  37. Stencil {
  38. Ref [_Stencil]
  39. ReadMask [_ReadMask]
  40. WriteMask [_WriteMask]
  41. Comp [_StencilComp]
  42. Pass [_StencilOp]
  43. Fail [_StencilFail]
  44. ZFail [_StencilZFail]
  45. }
  46. ZWrite On
  47. Cull [_Cull]
  48. AlphaToMask [_Coverage]
  49. HLSLPROGRAM
  50. // Required to compile gles 2.0 with standard SRP library
  51. #pragma prefer_hlslcc gles
  52. #pragma exclude_renderers d3d11_9x
  53. #pragma target 2.0
  54. // -------------------------------------
  55. // Material Keywords
  56. #define _SPECULAR_SETUP 1
  57. #define _ALPHATEST_ON 1
  58. #pragma shader_feature_local _ENABLEVFACE
  59. #pragma shader_feature_local_fragment _STRANDDIR_BITANGENT
  60. #pragma shader_feature_local_fragment _MASKMAP
  61. #pragma shader_feature_local_fragment _SECONDARYLOBE
  62. #pragma shader_feature_local _NORMALMAP
  63. #pragma shader_feature_local_fragment _RIMLIGHTING
  64. //#pragma shader_feature_local_fragment _SPECULARHIGHLIGHTS_OFF
  65. #pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF
  66. #pragma shader_feature_local _RECEIVE_SHADOWS_OFF
  67. // -------------------------------------
  68. // Universal Pipeline keywords
  69. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
  70. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
  71. #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  72. #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
  73. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  74. #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
  75. #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
  76. #pragma multi_compile _ SHADOWS_SHADOWMASK
  77. // -------------------------------------
  78. // Unity defined keywords
  79. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  80. #pragma multi_compile _ LIGHTMAP_ON
  81. #pragma multi_compile_fog
  82. //--------------------------------------
  83. // GPU Instancing
  84. #pragma multi_compile_instancing
  85. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  86. // Include base inputs and all other needed "base" includes
  87. #include "Includes/Lux URP Hair Inputs.hlsl"
  88. #include "Includes/Lux URP Hair Core.hlsl"
  89. #pragma vertex LitPassVertex
  90. #pragma fragment LitPassFragment
  91. ENDHLSL
  92. }
  93. Pass
  94. {
  95. Name "ShadowCaster"
  96. Tags{"LightMode" = "ShadowCaster"}
  97. ZWrite On
  98. ZTest LEqual
  99. ColorMask 0
  100. Cull [_ShadowCull]
  101. HLSLPROGRAM
  102. // Required to compile gles 2.0 with standard srp library
  103. #pragma prefer_hlslcc gles
  104. #pragma exclude_renderers d3d11_9x
  105. #pragma target 2.0
  106. // Material Keywords
  107. #define _ALPHATEST_ON 1
  108. // GPU Instancing
  109. #pragma multi_compile_instancing
  110. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  111. #pragma vertex ShadowPassVertex
  112. #pragma fragment ShadowPassFragment
  113. // Include base inputs and all other needed "base" includes
  114. #include "Includes/Lux URP Hair Inputs.hlsl"
  115. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
  116. // Shadow caster specific input
  117. float3 _LightDirection;
  118. VertexOutput ShadowPassVertex(VertexInput input)
  119. {
  120. VertexOutput output = (VertexOutput)0;
  121. UNITY_SETUP_INSTANCE_ID(input);
  122. UNITY_TRANSFER_INSTANCE_ID(input, output);
  123. float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
  124. float3 normalWS = TransformObjectToWorldDir(input.normalOS);
  125. output.uv = input.texcoord;
  126. output.positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, _LightDirection));
  127. #if UNITY_REVERSED_Z
  128. output.positionCS.z = min(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE);
  129. #else
  130. output.positionCS.z = max(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE);
  131. #endif
  132. return output;
  133. }
  134. half4 ShadowPassFragment(VertexOutput input) : SV_TARGET
  135. {
  136. UNITY_SETUP_INSTANCE_ID(input);
  137. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  138. half alpha = SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a;
  139. alpha *= _BaseColor.a;
  140. clip(alpha - _Cutoff);
  141. return 0;
  142. }
  143. ENDHLSL
  144. }
  145. Pass
  146. {
  147. Tags{"LightMode" = "DepthOnly"}
  148. ZWrite On
  149. ColorMask 0
  150. Cull [_Cull]
  151. HLSLPROGRAM
  152. // Required to compile gles 2.0 with standard srp library
  153. #pragma prefer_hlslcc gles
  154. #pragma exclude_renderers d3d11_9x
  155. #pragma target 2.0
  156. #define _ALPHATEST_ON 1
  157. #pragma vertex DepthOnlyVertex
  158. #pragma fragment DepthOnlyFragment
  159. // Material Keywords
  160. // GPU Instancing
  161. #pragma multi_compile_instancing
  162. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  163. #define DEPTHONLYPASS
  164. #include "Includes/Lux URP Hair Inputs.hlsl"
  165. VertexOutput DepthOnlyVertex(VertexInput input)
  166. {
  167. VertexOutput output = (VertexOutput)0;
  168. UNITY_SETUP_INSTANCE_ID(input);
  169. UNITY_TRANSFER_INSTANCE_ID(input, output);
  170. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  171. output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
  172. output.uv = input.texcoord;
  173. return output;
  174. }
  175. half4 DepthOnlyFragment(VertexOutput input) : SV_TARGET
  176. {
  177. UNITY_SETUP_INSTANCE_ID(input);
  178. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  179. half alpha = SampleAlbedoAlpha(input.uv.xy, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a;
  180. alpha *= _BaseColor.a;
  181. clip(alpha - _Cutoff);
  182. return 0;
  183. }
  184. ENDHLSL
  185. }
  186. // Depth Normal ---------------------------------------------
  187. // This pass is used when drawing to a _CameraNormalsTexture texture
  188. Pass
  189. {
  190. Name "DepthNormals"
  191. Tags{"LightMode" = "DepthNormals"}
  192. ZWrite On
  193. Cull[_Cull]
  194. HLSLPROGRAM
  195. // Required to compile gles 2.0 with standard SRP library
  196. #pragma prefer_hlslcc gles
  197. #pragma exclude_renderers d3d11_9x
  198. #pragma target 2.0
  199. #pragma vertex DepthNormalsVertex
  200. #pragma fragment DepthNormalsFragment
  201. // -------------------------------------
  202. // Material Keywords
  203. #pragma shader_feature_local _NORMALMAP
  204. #define _ALPHATEST_ON 1
  205. //--------------------------------------
  206. // GPU Instancing
  207. #pragma multi_compile_instancing
  208. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  209. //#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
  210. #include "Includes/Lux URP Hair Inputs.hlsl"
  211. #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthNormalsPass.hlsl"
  212. ENDHLSL
  213. }
  214. Pass
  215. {
  216. Tags{"LightMode" = "Meta"}
  217. Cull Off
  218. HLSLPROGRAM
  219. // Required to compile gles 2.0 with standard srp library
  220. #pragma prefer_hlslcc gles
  221. #pragma vertex UniversalVertexMeta
  222. #pragma fragment UniversalFragmentMeta
  223. #define _SPECULAR_SETUP
  224. // First include all our custom stuff
  225. #include "Includes/Lux URP Hair Inputs.hlsl"
  226. // Fragment shader and functions
  227. inline void InitializeStandardLitSurfaceData(float2 uv, out SurfaceData outSurfaceData)
  228. {
  229. half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
  230. outSurfaceData.alpha = 1;
  231. outSurfaceData.albedo = albedoAlpha.rgb;
  232. outSurfaceData.metallic = 0;
  233. outSurfaceData.specular = _SpecColor.rgb;
  234. outSurfaceData.smoothness = _Smoothness;
  235. outSurfaceData.normalTS = half3(0,0,1);
  236. outSurfaceData.occlusion = 1;
  237. outSurfaceData.emission = 0;
  238. outSurfaceData.clearCoatMask = 0;
  239. outSurfaceData.clearCoatSmoothness = 0;
  240. }
  241. // Finally include the meta pass related stuff
  242. #include "Packages/com.unity.render-pipelines.universal/Shaders/LitMetaPass.hlsl"
  243. ENDHLSL
  244. }
  245. }
  246. CustomEditor "LuxURPUniversalCustomShaderGUI"
  247. FallBack "Hidden/InternalErrorShader"
  248. }