Lux URP Hair.shader 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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. LOD 100
  104. Pass
  105. {
  106. Name "ForwardLit"
  107. Tags{"LightMode" = "UniversalForward"}
  108. Stencil {
  109. Ref [_Stencil]
  110. ReadMask [_ReadMask]
  111. WriteMask [_WriteMask]
  112. Comp [_StencilComp]
  113. Pass [_StencilOp]
  114. Fail [_StencilFail]
  115. ZFail [_StencilZFail]
  116. }
  117. ZWrite On
  118. Cull [_Cull]
  119. AlphaToMask [_Coverage]
  120. HLSLPROGRAM
  121. // Required to compile gles 2.0 with standard SRP library
  122. #pragma prefer_hlslcc gles
  123. #pragma exclude_renderers d3d11_9x
  124. #pragma target 2.0
  125. // -------------------------------------
  126. // Material Keywords
  127. #define _SPECULAR_SETUP 1
  128. #define _ALPHATEST_ON 1
  129. #pragma shader_feature_local _ENABLEVFACE
  130. #pragma shader_feature_local_fragment _STRANDDIR_BITANGENT
  131. #pragma shader_feature_local_fragment _MASKMAP
  132. #pragma shader_feature_local_fragment _SECONDARYLOBE
  133. #pragma shader_feature_local _NORMALMAP
  134. #pragma shader_feature_local_fragment _RIMLIGHTING
  135. //#pragma shader_feature_local_fragment _SPECULARHIGHLIGHTS_OFF
  136. #pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF
  137. #pragma shader_feature_local _RECEIVE_SHADOWS_OFF
  138. // -------------------------------------
  139. // Universal Pipeline keywords
  140. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
  141. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
  142. #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  143. #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
  144. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  145. #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
  146. #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
  147. #pragma multi_compile _ SHADOWS_SHADOWMASK
  148. // -------------------------------------
  149. // Unity defined keywords
  150. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  151. #pragma multi_compile _ LIGHTMAP_ON
  152. #pragma multi_compile_fog
  153. //--------------------------------------
  154. // GPU Instancing
  155. #pragma multi_compile_instancing
  156. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  157. // Include base inputs and all other needed "base" includes
  158. #include "Includes/Lux URP Hair Inputs.hlsl"
  159. #include "Includes/Lux URP Hair Core.hlsl"
  160. #pragma vertex LitPassVertex
  161. #pragma fragment LitPassFragment
  162. ENDHLSL
  163. }
  164. // Shadows -----------------------------------------------------
  165. Pass
  166. {
  167. Name "ShadowCaster"
  168. Tags{"LightMode" = "ShadowCaster"}
  169. ZWrite On
  170. ZTest LEqual
  171. ColorMask 0
  172. Cull [_ShadowCull]
  173. HLSLPROGRAM
  174. // Required to compile gles 2.0 with standard srp library
  175. #pragma prefer_hlslcc gles
  176. #pragma exclude_renderers d3d11_9x
  177. #pragma target 2.0
  178. // -------------------------------------
  179. // Material Keywords
  180. #define _ALPHATEST_ON 1
  181. //--------------------------------------
  182. // GPU Instancing
  183. #pragma multi_compile_instancing
  184. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  185. #pragma vertex ShadowPassVertex
  186. #pragma fragment ShadowPassFragment
  187. // Include base inputs and all other needed "base" includes
  188. #include "Includes/Lux URP Hair Inputs.hlsl"
  189. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
  190. // Shadow caster specific input
  191. float3 _LightDirection;
  192. VertexOutput ShadowPassVertex(VertexInput input)
  193. {
  194. VertexOutput output = (VertexOutput)0;
  195. UNITY_SETUP_INSTANCE_ID(input);
  196. UNITY_TRANSFER_INSTANCE_ID(input, output);
  197. float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
  198. float3 normalWS = TransformObjectToWorldDir(input.normalOS);
  199. output.uv = input.texcoord;
  200. output.positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, _LightDirection));
  201. #if UNITY_REVERSED_Z
  202. output.positionCS.z = min(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE);
  203. #else
  204. output.positionCS.z = max(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE);
  205. #endif
  206. return output;
  207. }
  208. half4 ShadowPassFragment(VertexOutput input) : SV_TARGET
  209. {
  210. UNITY_SETUP_INSTANCE_ID(input);
  211. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  212. half alpha = SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a;
  213. alpha *= _BaseColor.a;
  214. clip(alpha - _Cutoff);
  215. return 0;
  216. }
  217. ENDHLSL
  218. }
  219. // Depth -----------------------------------------------------
  220. Pass
  221. {
  222. Tags{"LightMode" = "DepthOnly"}
  223. ZWrite On
  224. ColorMask 0
  225. Cull [_Cull]
  226. HLSLPROGRAM
  227. // Required to compile gles 2.0 with standard srp library
  228. #pragma prefer_hlslcc gles
  229. #pragma exclude_renderers d3d11_9x
  230. #pragma target 2.0
  231. #define _ALPHATEST_ON 1
  232. #pragma vertex DepthOnlyVertex
  233. #pragma fragment DepthOnlyFragment
  234. // -------------------------------------
  235. // Material Keywords
  236. //--------------------------------------
  237. // GPU Instancing
  238. #pragma multi_compile_instancing
  239. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  240. #define DEPTHONLYPASS
  241. #include "Includes/Lux URP Hair Inputs.hlsl"
  242. VertexOutput DepthOnlyVertex(VertexInput input)
  243. {
  244. VertexOutput output = (VertexOutput)0;
  245. UNITY_SETUP_INSTANCE_ID(input);
  246. UNITY_TRANSFER_INSTANCE_ID(input, output);
  247. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  248. output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
  249. output.uv = input.texcoord;
  250. return output;
  251. }
  252. half4 DepthOnlyFragment(VertexOutput input) : SV_TARGET
  253. {
  254. UNITY_SETUP_INSTANCE_ID(input);
  255. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  256. half alpha = SampleAlbedoAlpha(input.uv.xy, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a;
  257. alpha *= _BaseColor.a;
  258. clip(alpha - _Cutoff);
  259. return 0;
  260. }
  261. ENDHLSL
  262. }
  263. // Depth Normal ---------------------------------------------
  264. // This pass is used when drawing to a _CameraNormalsTexture texture
  265. Pass
  266. {
  267. Name "DepthNormals"
  268. Tags{"LightMode" = "DepthNormals"}
  269. ZWrite On
  270. Cull[_Cull]
  271. HLSLPROGRAM
  272. // Required to compile gles 2.0 with standard SRP library
  273. #pragma prefer_hlslcc gles
  274. #pragma exclude_renderers d3d11_9x
  275. #pragma target 2.0
  276. #pragma vertex DepthNormalsVertex
  277. #pragma fragment DepthNormalsFragment
  278. // -------------------------------------
  279. // Material Keywords
  280. #pragma shader_feature_local _NORMALMAP
  281. #define _ALPHATEST_ON 1
  282. //--------------------------------------
  283. // GPU Instancing
  284. #pragma multi_compile_instancing
  285. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  286. //#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
  287. #include "Includes/Lux URP Hair Inputs.hlsl"
  288. #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthNormalsPass.hlsl"
  289. ENDHLSL
  290. }
  291. // Meta -----------------------------------------------------
  292. Pass
  293. {
  294. Tags{"LightMode" = "Meta"}
  295. Cull Off
  296. HLSLPROGRAM
  297. // Required to compile gles 2.0 with standard srp library
  298. #pragma prefer_hlslcc gles
  299. #pragma vertex UniversalVertexMeta
  300. #pragma fragment UniversalFragmentMeta
  301. #define _SPECULAR_SETUP
  302. // First include all our custom stuff
  303. #include "Includes/Lux URP Hair Inputs.hlsl"
  304. //--------------------------------------
  305. // Fragment shader and functions
  306. inline void InitializeStandardLitSurfaceData(float2 uv, out SurfaceData outSurfaceData)
  307. {
  308. half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
  309. outSurfaceData.alpha = 1;
  310. outSurfaceData.albedo = albedoAlpha.rgb;
  311. outSurfaceData.metallic = 0;
  312. outSurfaceData.specular = _SpecColor.rgb;
  313. outSurfaceData.smoothness = _Smoothness;
  314. outSurfaceData.normalTS = half3(0,0,1);
  315. outSurfaceData.occlusion = 1;
  316. outSurfaceData.emission = 0;
  317. outSurfaceData.clearCoatMask = 0;
  318. outSurfaceData.clearCoatSmoothness = 0;
  319. }
  320. // Finally include the meta pass related stuff
  321. #include "Packages/com.unity.render-pipelines.universal/Shaders/LitMetaPass.hlsl"
  322. ENDHLSL
  323. }
  324. // End Passes -----------------------------------------------------
  325. }
  326. CustomEditor "LuxURPUniversalCustomShaderGUI"
  327. FallBack "Hidden/InternalErrorShader"
  328. }