Lux URP Hair Blend.shader 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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 Blend"
  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.CompareFunction)]
  16. _ZTest ("ZTest", Int) = 4
  17. [ToggleOff(_RECEIVE_SHADOWS_OFF)]
  18. _ReceiveShadows ("Receive Shadows", Float) = 1.0
  19. //[NoScaleOffset]
  20. //_Dither ("Blue Noise (A)", 2D) = "black" {}
  21. [Header(Surface Inputs)]
  22. [Space(8)]
  23. [MainColor]
  24. _BaseColor ("Base Color", Color) = (1,1,1,1)
  25. _SecondaryColor ("Secondary Color", Color) = (1,1,1,1)
  26. [NoScaleOffset] [MainTexture]
  27. _BaseMap ("Albedo (RGB) Alpha (A)", 2D) = "white" {}
  28. [HideInInspector] _Cutoff ("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
  29. [Space(5)]
  30. [Toggle(_NORMALMAP)]
  31. _ApplyNormal ("Enable Normal Map", Float) = 0.0
  32. [NoScaleOffset]
  33. _BumpMap (" Normal Map", 2D) = "bump" {}
  34. _BumpScale (" Normal Scale", Float) = 1.0
  35. [Space(5)]
  36. [Toggle(_MASKMAP)]
  37. _EnableMaskMap ("Enable Mask Map", Float) = 0
  38. [NoScaleOffset] _MaskMap (" Shift (B) Occlusion (G)", 2D) = "white" {}
  39. [Space(5)]
  40. _SpecColor ("Specular", Color) = (0.2, 0.2, 0.2)
  41. _Smoothness ("Smoothness", Range(0.0, 1.0)) = 1
  42. [Header(Hair Lighting)]
  43. [Space(8)]
  44. [KeywordEnum(Bitangent,Tangent)]
  45. _StrandDir ("Strand Direction", Float) = 0
  46. [Space(5)]
  47. _SpecularShift ("Primary Specular Shift", Range(-1.0, 1.0)) = 0.1
  48. [HDR] _SpecularTint ("Primary Specular Tint", Color) = (1, 1, 1, 1)
  49. _SpecularExponent ("Primary Smoothness", Range(0.0, 1)) = .85
  50. [Space(5)]
  51. [Toggle(_SECONDARYLOBE)]
  52. _SecondaryLobe ("Enable Secondary Highlight", Float) = 1
  53. [Space(5)]
  54. _SecondarySpecularShift ("Secondary Specular Shift", Range(-1.0, 1.0)) = 0.1
  55. [HDR] _SecondarySpecularTint("Secondary Specular Tint", Color) = (1, 1, 1, 1)
  56. _SecondarySpecularExponent ("Secondary Smoothness", Range(0.0, 1)) = .8
  57. [Space(5)]
  58. _RimTransmissionIntensity ("Rim Transmission Intensity", Range(0.0, 8.0)) = 0.5
  59. _AmbientReflection ("Ambient Reflection Strength", Range(0.0, 1.0)) = 1
  60. [Header(Rim Lighting)]
  61. [Space(8)]
  62. [Toggle(_RIMLIGHTING)]
  63. _Rim ("Enable Rim Lighting", Float) = 0
  64. [HDR] _RimColor ("Rim Color", Color) = (0.5,0.5,0.5,1)
  65. _RimPower ("Rim Power", Float) = 2
  66. _RimFrequency ("Rim Frequency", Float) = 0
  67. _RimMinPower (" Rim Min Power", Float) = 1
  68. _RimPerPositionFrequency (" Rim Per Position Frequency", Range(0.0, 1.0)) = 1
  69. [Header(Advanced)]
  70. [Space(8)]
  71. //[ToggleOff]
  72. //_SpecularHighlights ("Enable Specular Highlights", Float) = 1.0
  73. [ToggleOff]
  74. _EnvironmentReflections ("Environment Reflections", Float) = 1.0
  75. [Space(5)]
  76. [Toggle(_RECEIVE_SHADOWS_OFF)]
  77. _Shadows ("Disable Receive Shadows", Float) = 0.0
  78. [Header(Stencil)]
  79. [Space(8)]
  80. [IntRange] _Stencil ("Stencil Reference", Range (0, 255)) = 0
  81. [IntRange] _ReadMask (" Read Mask", Range (0, 255)) = 255
  82. [IntRange] _WriteMask (" Write Mask", Range (0, 255)) = 255
  83. [Enum(UnityEngine.Rendering.CompareFunction)]
  84. _StencilComp ("Stencil Comparison", Int) = 8 // always – terrain should be the first thing being rendered anyway
  85. [Enum(UnityEngine.Rendering.StencilOp)]
  86. _StencilOp ("Stencil Operation", Int) = 0 // 0 = keep, 2 = replace
  87. [Enum(UnityEngine.Rendering.StencilOp)]
  88. _StencilFail ("Stencil Fail Op", Int) = 0 // 0 = keep
  89. [Enum(UnityEngine.Rendering.StencilOp)]
  90. _StencilZFail ("Stencil ZFail Op", Int) = 0 // 0 = keep
  91. // Needed by the inspector
  92. [HideInInspector] _Culling ("Culling", Float) = 0.0
  93. // Lightmapper and outline selection shader need _MainTex, _Color and _Cutoff
  94. [HideInInspector] _MainTex ("Albedo", 2D) = "white" {}
  95. [HideInInspector] _Color ("Color", Color) = (1,1,1,1)
  96. // URP 10.1. needs this for the depthnormal pass
  97. [HideInInspector] _Surface("__surface", Float) = 0.0
  98. }
  99. SubShader
  100. {
  101. Tags
  102. {
  103. "RenderPipeline" = "UniversalPipeline"
  104. "RenderType" = "Transparent"
  105. "Queue" = "Transparent"
  106. }
  107. LOD 100
  108. Pass
  109. {
  110. Name "ForwardLit"
  111. Tags{"LightMode" = "UniversalForward"}
  112. Stencil {
  113. Ref [_Stencil]
  114. ReadMask [_ReadMask]
  115. WriteMask [_WriteMask]
  116. Comp [_StencilComp]
  117. Pass [_StencilOp]
  118. Fail [_StencilFail]
  119. ZFail [_StencilZFail]
  120. }
  121. Blend SrcAlpha OneMinusSrcAlpha
  122. ZWrite Off
  123. ZTest [_ZTest]
  124. Cull [_Cull]
  125. HLSLPROGRAM
  126. // Required to compile gles 2.0 with standard SRP library
  127. #pragma prefer_hlslcc gles
  128. #pragma exclude_renderers d3d11_9x
  129. // Shader target needs to be 3.0 due to tex2Dlod in the vertex shader and VFACE
  130. #pragma target 2.0
  131. // -------------------------------------
  132. // Material Keywords
  133. #define _SPECULAR_SETUP 1
  134. #pragma shader_feature_local _ENABLEVFACE
  135. #pragma shader_feature_local_fragment _STRANDDIR_BITANGENT
  136. #pragma shader_feature_local_fragment _MASKMAP
  137. #pragma shader_feature_local_fragment _SECONDARYLOBE
  138. #pragma shader_feature _NORMALMAP
  139. #pragma shader_feature_local_fragment _RIMLIGHTING
  140. //#pragma shader_feature _SPECULARHIGHLIGHTS_OFF
  141. #pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF
  142. #pragma shader_feature_local _RECEIVE_SHADOWS_OFF
  143. // -------------------------------------
  144. // Universal Pipeline keywords
  145. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
  146. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
  147. #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  148. #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
  149. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  150. #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
  151. #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
  152. #pragma multi_compile _ SHADOWS_SHADOWMASK
  153. // -------------------------------------
  154. // Unity defined keywords
  155. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  156. #pragma multi_compile _ LIGHTMAP_ON
  157. #pragma multi_compile_fog
  158. //--------------------------------------
  159. // GPU Instancing
  160. #pragma multi_compile_instancing
  161. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  162. // Include base inputs and all other needed "base" includes
  163. #include "Includes/Lux URP Hair Inputs.hlsl"
  164. #include "Includes/Lux URP Hair Core.hlsl"
  165. #pragma vertex LitPassVertex
  166. #pragma fragment LitPassFragment
  167. ENDHLSL
  168. }
  169. // Meta -----------------------------------------------------
  170. Pass
  171. {
  172. Tags{"LightMode" = "Meta"}
  173. Cull Off
  174. HLSLPROGRAM
  175. // Required to compile gles 2.0 with standard srp library
  176. #pragma prefer_hlslcc gles
  177. #pragma vertex UniversalVertexMeta
  178. #pragma fragment UniversalFragmentMeta
  179. #define _SPECULAR_SETUP
  180. // First include all our custom stuff
  181. #include "Includes/Lux URP Hair Inputs.hlsl"
  182. //--------------------------------------
  183. // Fragment shader and functions
  184. inline void InitializeStandardLitSurfaceData(float2 uv, out SurfaceData outSurfaceData)
  185. {
  186. half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
  187. outSurfaceData.alpha = 1;
  188. outSurfaceData.albedo = albedoAlpha.rgb;
  189. outSurfaceData.metallic = 0;
  190. outSurfaceData.specular = _SpecColor.rgb;
  191. outSurfaceData.smoothness = _Smoothness;
  192. outSurfaceData.normalTS = half3(0,0,1);
  193. outSurfaceData.occlusion = 1;
  194. outSurfaceData.emission = 0;
  195. outSurfaceData.clearCoatMask = 0;
  196. outSurfaceData.clearCoatSmoothness = 0;
  197. }
  198. // Finally include the meta pass related stuff
  199. #include "Packages/com.unity.render-pipelines.universal/Shaders/LitMetaPass.hlsl"
  200. ENDHLSL
  201. }
  202. // End Passes -----------------------------------------------------
  203. }
  204. CustomEditor "LuxURPUniversalCustomShaderGUI"
  205. FallBack "Hidden/InternalErrorShader"
  206. }