Lux URP Hair.shader 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. // Shader uses custom editor to set double sided GI
  2. // Needs _Culling to be set properly
  3. // See: http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2012/10/Scheuermann_HairSketchSlides.pdf
  4. Shader "Lux URP/Human/Hair"
  5. {
  6. Properties
  7. {
  8. [HeaderHelpLuxURP_URL(7a3r84ualf3h)]
  9. [Header(Surface Options)]
  10. [Space(8)]
  11. [Enum(UnityEngine.Rendering.CullMode)]
  12. _Cull ("Culling", Float) = 0
  13. [Toggle(_ENABLEVFACE)]
  14. _EnableVFACE (" Enable VFACE", Float) = 0
  15. [Enum(UnityEngine.Rendering.CullMode)]
  16. _ShadowCull ("Shadow Culling", Float) = 0
  17. [Enum(Off,0,On,1)]_Coverage ("Alpha To Coverage", Float) = 1
  18. [ToggleOff(_RECEIVE_SHADOWS_OFF)]
  19. _ReceiveShadows ("Receive Shadows", Float) = 1.0
  20. [Header(Surface Inputs)]
  21. [Space(5)]
  22. [MainColor]
  23. _BaseColor ("Base Color", Color) = (1,1,1,1)
  24. _SecondaryColor ("Secondary Color", Color) = (1,1,1,1)
  25. [NoScaleOffset] [MainTexture]
  26. _BaseMap ("Albedo (RGB) Alpha (A)", 2D) = "white" {}
  27. _Cutoff ("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
  28. [Space(5)]
  29. [Toggle(_NORMALMAP)]
  30. _ApplyNormal ("Enable Normal Map", Float) = 0.0
  31. [NoScaleOffset]
  32. _BumpMap (" Normal Map", 2D) = "bump" {}
  33. _BumpScale (" Normal Scale", Float) = 1.0
  34. [Space(5)]
  35. [Toggle(_MASKMAP)]
  36. _EnableMaskMap ("Enable Mask Map", Float) = 0
  37. [NoScaleOffset] _MaskMap (" Shift (B) Occlusion (G)", 2D) = "white" {}
  38. [Space(5)]
  39. _SpecColor ("Specular", Color) = (0.2, 0.2, 0.2)
  40. _Smoothness ("Smoothness", Range(0.0, 1.0)) = 1
  41. [Header(Hair Lighting)]
  42. [Space(8)]
  43. [KeywordEnum(Bitangent,Tangent)]
  44. _StrandDir ("Strand Direction", Float) = 0
  45. [Space(5)]
  46. _SpecularShift ("Primary Specular Shift", Range(-1.0, 1.0)) = 0.1
  47. [HDR] _SpecularTint ("Primary Specular Tint", Color) = (1, 1, 1, 1)
  48. _SpecularExponent ("Primary Smoothness", Range(0.0, 1)) = .85
  49. [Space(5)]
  50. [Toggle(_SECONDARYLOBE)]
  51. _SecondaryLobe ("Enable Secondary Highlight", Float) = 1
  52. [Space(5)]
  53. _SecondarySpecularShift ("Secondary Specular Shift", Range(-1.0, 1.0)) = 0.1
  54. [HDR] _SecondarySpecularTint("Secondary Specular Tint", Color) = (1, 1, 1, 1)
  55. _SecondarySpecularExponent ("Secondary Smoothness", Range(0.0, 1)) = .8
  56. [Space(5)]
  57. _RimTransmissionIntensity ("Rim Transmission Intensity", Range(0.0, 8.0)) = 0.5
  58. _AmbientReflection ("Ambient Reflection Strength", Range(0.0, 1.0)) = 1
  59. [Header(Rim Lighting)]
  60. [Space(8)]
  61. [Toggle(_RIMLIGHTING)]
  62. _Rim ("Enable Rim Lighting", Float) = 0
  63. [HDR] _RimColor ("Rim Color", Color) = (0.5,0.5,0.5,1)
  64. _RimPower ("Rim Power", Float) = 2
  65. _RimFrequency ("Rim Frequency", Float) = 0
  66. _RimMinPower (" Rim Min Power", Float) = 1
  67. _RimPerPositionFrequency (" Rim Per Position Frequency", Range(0.0, 1.0)) = 1
  68. [Header(Advanced)]
  69. [Space(8)]
  70. //[ToggleOff]
  71. //_SpecularHighlights ("Enable Specular Highlights", Float) = 1.0
  72. [ToggleOff]
  73. _EnvironmentReflections ("Environment Reflections", Float) = 1.0
  74. [Header(Stencil)]
  75. [Space(8)]
  76. [IntRange] _Stencil ("Stencil Reference", Range (0, 255)) = 2
  77. [IntRange] _ReadMask (" Read Mask", Range (0, 255)) = 255
  78. [IntRange] _WriteMask (" Write Mask", Range (0, 255)) = 255
  79. [Enum(UnityEngine.Rendering.CompareFunction)]
  80. _StencilComp ("Stencil Comparison", Int) = 8 // always
  81. [Enum(UnityEngine.Rendering.StencilOp)]
  82. _StencilOp ("Stencil Operation", Int) = 2 // 0 = keep, 2 = replace
  83. [Enum(UnityEngine.Rendering.StencilOp)]
  84. _StencilFail ("Stencil Fail Op", Int) = 0 // 0 = keep
  85. [Enum(UnityEngine.Rendering.StencilOp)]
  86. _StencilZFail ("Stencil ZFail Op", Int) = 0 // 0 = keep
  87. // Needed by the inspector
  88. [HideInInspector] _Culling ("Culling", Float) = 0.0
  89. // Lightmapper and outline selection shader need _MainTex, _Color and _Cutoff
  90. [HideInInspector] _MainTex ("Albedo", 2D) = "white" {}
  91. [HideInInspector] _Color ("Color", Color) = (1,1,1,1)
  92. // URP 10.1. needs this for the depthnormal pass
  93. [HideInInspector] _Surface("__surface", Float) = 0.0
  94. }
  95. SubShader
  96. {
  97. Tags
  98. {
  99. "RenderPipeline" = "UniversalPipeline"
  100. "RenderType" = "TransparentCutout"
  101. "Queue" = "AlphaTest"
  102. }
  103. Pass
  104. {
  105. Name "ForwardLit"
  106. Tags{"LightMode" = "UniversalForward"}
  107. Stencil {
  108. Ref [_Stencil]
  109. ReadMask [_ReadMask]
  110. WriteMask [_WriteMask]
  111. Comp [_StencilComp]
  112. Pass [_StencilOp]
  113. Fail [_StencilFail]
  114. ZFail [_StencilZFail]
  115. }
  116. ZWrite On
  117. Cull [_Cull]
  118. AlphaToMask [_Coverage]
  119. HLSLPROGRAM
  120. // Required to compile gles 2.0 with standard SRP library
  121. #pragma prefer_hlslcc gles
  122. #pragma exclude_renderers d3d11_9x
  123. #pragma target 2.0
  124. // -------------------------------------
  125. // Material Keywords
  126. #define _SPECULAR_SETUP 1
  127. #define _ALPHATEST_ON 1
  128. #pragma shader_feature_local _ENABLEVFACE
  129. #pragma shader_feature_local_fragment _STRANDDIR_BITANGENT
  130. #pragma shader_feature_local_fragment _MASKMAP
  131. #pragma shader_feature_local_fragment _SECONDARYLOBE
  132. #pragma shader_feature_local _NORMALMAP
  133. #pragma shader_feature_local_fragment _RIMLIGHTING
  134. //#pragma shader_feature_local_fragment _SPECULARHIGHLIGHTS_OFF
  135. #pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF
  136. #pragma shader_feature_local _RECEIVE_SHADOWS_OFF
  137. // -------------------------------------
  138. // Universal Pipeline keywords
  139. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
  140. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
  141. #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  142. #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
  143. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  144. #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
  145. #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
  146. #pragma multi_compile _ SHADOWS_SHADOWMASK
  147. // -------------------------------------
  148. // Unity defined keywords
  149. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  150. #pragma multi_compile _ LIGHTMAP_ON
  151. #pragma multi_compile_fog
  152. //--------------------------------------
  153. // GPU Instancing
  154. #pragma multi_compile_instancing
  155. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  156. // Include base inputs and all other needed "base" includes
  157. #include "Includes/Lux URP Hair Inputs.hlsl"
  158. #include "Includes/Lux URP Hair Core.hlsl"
  159. #pragma vertex LitPassVertex
  160. #pragma fragment LitPassFragment
  161. ENDHLSL
  162. }
  163. // Shadows -----------------------------------------------------
  164. Pass
  165. {
  166. Name "ShadowCaster"
  167. Tags{"LightMode" = "ShadowCaster"}
  168. ZWrite On
  169. ZTest LEqual
  170. ColorMask 0
  171. Cull [_ShadowCull]
  172. HLSLPROGRAM
  173. // Required to compile gles 2.0 with standard srp library
  174. #pragma prefer_hlslcc gles
  175. #pragma exclude_renderers d3d11_9x
  176. #pragma target 2.0
  177. // -------------------------------------
  178. // Material Keywords
  179. #define _ALPHATEST_ON 1
  180. //--------------------------------------
  181. // GPU Instancing
  182. #pragma multi_compile_instancing
  183. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  184. #pragma vertex ShadowPassVertex
  185. #pragma fragment ShadowPassFragment
  186. // Include base inputs and all other needed "base" includes
  187. #include "Includes/Lux URP Hair Inputs.hlsl"
  188. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
  189. // Shadow caster specific input
  190. float3 _LightDirection;
  191. VertexOutput ShadowPassVertex(VertexInput input)
  192. {
  193. VertexOutput output = (VertexOutput)0;
  194. UNITY_SETUP_INSTANCE_ID(input);
  195. UNITY_TRANSFER_INSTANCE_ID(input, output);
  196. float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
  197. float3 normalWS = TransformObjectToWorldDir(input.normalOS);
  198. output.uv = input.texcoord;
  199. output.positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, _LightDirection));
  200. #if UNITY_REVERSED_Z
  201. output.positionCS.z = min(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE);
  202. #else
  203. output.positionCS.z = max(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE);
  204. #endif
  205. return output;
  206. }
  207. half4 ShadowPassFragment(VertexOutput input) : SV_TARGET
  208. {
  209. UNITY_SETUP_INSTANCE_ID(input);
  210. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  211. half alpha = SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a;
  212. alpha *= _BaseColor.a;
  213. clip(alpha - _Cutoff);
  214. return 0;
  215. }
  216. ENDHLSL
  217. }
  218. // Depth -----------------------------------------------------
  219. Pass
  220. {
  221. Tags{"LightMode" = "DepthOnly"}
  222. ZWrite On
  223. ColorMask 0
  224. Cull [_Cull]
  225. HLSLPROGRAM
  226. // Required to compile gles 2.0 with standard srp library
  227. #pragma prefer_hlslcc gles
  228. #pragma exclude_renderers d3d11_9x
  229. #pragma target 2.0
  230. #define _ALPHATEST_ON 1
  231. #pragma vertex DepthOnlyVertex
  232. #pragma fragment DepthOnlyFragment
  233. // -------------------------------------
  234. // Material Keywords
  235. //--------------------------------------
  236. // GPU Instancing
  237. #pragma multi_compile_instancing
  238. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  239. #define DEPTHONLYPASS
  240. #include "Includes/Lux URP Hair Inputs.hlsl"
  241. VertexOutput DepthOnlyVertex(VertexInput input)
  242. {
  243. VertexOutput output = (VertexOutput)0;
  244. UNITY_SETUP_INSTANCE_ID(input);
  245. UNITY_TRANSFER_INSTANCE_ID(input, output);
  246. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  247. output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
  248. output.uv = input.texcoord;
  249. return output;
  250. }
  251. half4 DepthOnlyFragment(VertexOutput input) : SV_TARGET
  252. {
  253. UNITY_SETUP_INSTANCE_ID(input);
  254. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  255. half alpha = SampleAlbedoAlpha(input.uv.xy, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a;
  256. alpha *= _BaseColor.a;
  257. clip(alpha - _Cutoff);
  258. return 0;
  259. }
  260. ENDHLSL
  261. }
  262. // Depth Normal ---------------------------------------------
  263. // This pass is used when drawing to a _CameraNormalsTexture texture
  264. Pass
  265. {
  266. Name "DepthNormals"
  267. Tags{"LightMode" = "DepthNormals"}
  268. ZWrite On
  269. Cull[_Cull]
  270. HLSLPROGRAM
  271. // Required to compile gles 2.0 with standard SRP library
  272. #pragma prefer_hlslcc gles
  273. #pragma exclude_renderers d3d11_9x
  274. #pragma target 2.0
  275. #pragma vertex DepthNormalsVertex
  276. #pragma fragment DepthNormalsFragment
  277. // -------------------------------------
  278. // Material Keywords
  279. #pragma shader_feature_local _NORMALMAP
  280. #define _ALPHATEST_ON 1
  281. //--------------------------------------
  282. // GPU Instancing
  283. #pragma multi_compile_instancing
  284. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  285. //#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
  286. #include "Includes/Lux URP Hair Inputs.hlsl"
  287. #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthNormalsPass.hlsl"
  288. ENDHLSL
  289. }
  290. // Meta -----------------------------------------------------
  291. Pass
  292. {
  293. Tags{"LightMode" = "Meta"}
  294. Cull Off
  295. HLSLPROGRAM
  296. // Required to compile gles 2.0 with standard srp library
  297. #pragma prefer_hlslcc gles
  298. #pragma vertex UniversalVertexMeta
  299. #pragma fragment UniversalFragmentMeta
  300. #define _SPECULAR_SETUP
  301. // First include all our custom stuff
  302. #include "Includes/Lux URP Hair Inputs.hlsl"
  303. //--------------------------------------
  304. // Fragment shader and functions
  305. inline void InitializeStandardLitSurfaceData(float2 uv, out SurfaceData outSurfaceData)
  306. {
  307. half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
  308. outSurfaceData.alpha = 1;
  309. outSurfaceData.albedo = albedoAlpha.rgb;
  310. outSurfaceData.metallic = 0;
  311. outSurfaceData.specular = _SpecColor.rgb;
  312. outSurfaceData.smoothness = _Smoothness;
  313. outSurfaceData.normalTS = half3(0,0,1);
  314. outSurfaceData.occlusion = 1;
  315. outSurfaceData.emission = 0;
  316. outSurfaceData.clearCoatMask = 0;
  317. outSurfaceData.clearCoatSmoothness = 0;
  318. }
  319. // Finally include the meta pass related stuff
  320. #include "Packages/com.unity.render-pipelines.universal/Shaders/LitMetaPass.hlsl"
  321. ENDHLSL
  322. }
  323. // End Passes -----------------------------------------------------
  324. }
  325. CustomEditor "LuxURPUniversalCustomShaderGUI"
  326. FallBack "Hidden/InternalErrorShader"
  327. }