Lux URP Skin New.shader 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. // Shader uses custom editor to set double sided GI
  2. // Needs _Culling to be set properly
  3. Shader "Lux URP/Human/Skin_New"
  4. {
  5. Properties
  6. {
  7. [HeaderHelpLuxURP_URL(snoamqpqhtdl)]
  8. [Header(Surface Options)]
  9. [Space(8)]
  10. [ToggleOff(_RECEIVE_SHADOWS_OFF)]
  11. _ReceiveShadows ("Receive Shadows", Float) = 1.0
  12. _SkinShadowBias (" Shadow Caster Bias", Range(.1, 1.0)) = 1.0
  13. _SkinShadowSamplingBias (" Shadow Sampling Bias", Range(0, 0.05)) = 0
  14. [Header(Surface Inputs)]
  15. [Space(8)]
  16. [NoScaleOffset] [MainTexture]
  17. _BaseMap ("Albedo (RGB) Smoothness (A)", 2D) = "white" {}
  18. [MainColor]
  19. _BaseColor ("Color", Color) = (1,1,1,1)
  20. [HDR]_XRimColor("XRay Color", Color) = (1,1,1,1)
  21. [Space(5)]
  22. _Smoothness ("Smoothness", Range(0.0, 1.0)) = 0.5
  23. // For some reason android did not like _SpecColor!?
  24. _SpecularColor ("Specular", Color) = (0.2, 0.2, 0.2)
  25. [Space(5)]
  26. [Toggle(_NORMALMAP)]
  27. _ApplyNormal ("Enable Normal Map", Float) = 0.0
  28. [NoScaleOffset]
  29. _BumpMap (" Normal Map", 2D) = "bump" {}
  30. _BumpScale (" Normal Scale", Float) = 1.0
  31. [Toggle(_NORMALMAPDIFFUSE)]
  32. _ApplyNormalDiffuse (" Enable Diffuse Normal Sample", Float) = 0.0
  33. _Bias (" Bias", Range(0.0, 8.0)) = 3.0
  34. [Toggle]_VertexNormal (" Use Vertex Normal for Diffuse", Float) = 1
  35. [Header(Skin Lighting)]
  36. [Space(8)]
  37. [NoScaleOffset] _SSSAOMap ("Skin Mask (R) Thickness (G) Curvature (B) Occlusion (A)", 2D) = "white" {}
  38. _OcclusionStrength ("Occlusion Strength", Range(0.0, 1.0)) = 1.0
  39. [Toggle]
  40. _SampleCurvature ("Sample Curvature", Float) = 0
  41. _Curvature ("Curvature", Range(0.0, 1.0)) = 0.5
  42. _SubsurfaceColor ("Subsurface Color", Color) = (1.0, 0.4, 0.25, 1.0)
  43. _TranslucencyPower ("Transmission Power", Range(0.0, 10.0)) = 7.0
  44. _TranslucencyStrength ("Transmission Strength", Range(0.0, 1.0)) = 1.0
  45. _ShadowStrength ("Shadow Strength", Range(0.0, 1.0)) = 0.7
  46. _MaskByShadowStrength ("Mask by incoming Shadow Strength", Range(0.0, 1.0)) = 1.0
  47. _Distortion ("Transmission Distortion", Range(0.0, 0.1)) = 0.01
  48. [Space(5)]
  49. [Toggle(_BACKSCATTER)]
  50. _EnableBackscatter ("Enable Ambient Back Scattering", Float) = 0
  51. _Backscatter ("Ambient Back Scattering", Range(0.0, 8.0)) = 1
  52. [Space(5)]
  53. _AmbientReflectionStrength ("Ambient Reflection Strength", Range(0.0, 1)) = 1
  54. [Space(5)]
  55. [NoScaleOffset] _SkinLUT ("Skin LUT", 2D) = "white" {}
  56. [Header(Distance Fading)]
  57. [Space(8)]
  58. [Toggle(_DISTANCEFADE)]
  59. _EnableDistanceFade ("Enable Distance Fade", Float) = 0.0
  60. [LuxURPDistanceFadeDrawer]
  61. _DistanceFade ("Distance Fade Params", Vector) = (2500, 0.001, 0, 0)
  62. [Header(Rim Lighting)]
  63. [Space(8)]
  64. [Toggle(_RIMLIGHTING)]
  65. _Rim ("Enable Rim Lighting", Float) = 0
  66. [HDR] _RimColor ("Rim Color", Color) = (0.5,0.5,0.5,1)
  67. _RimPower ("Rim Power", Float) = 2
  68. _RimFrequency ("Rim Frequency", Float) = 0
  69. _RimMinPower (" Rim Min Power", Float) = 1
  70. _RimPerPositionFrequency (" Rim Per Position Frequency", Range(0.0, 1.0)) = 1
  71. [Header(Advanced)]
  72. [Space(8)]
  73. [ToggleOff]
  74. _SpecularHighlights ("Enable Specular Highlights", Float) = 1.0
  75. [ToggleOff]
  76. _EnvironmentReflections ("Environment Reflections", Float) = 1.0
  77. [Header(Stencil)]
  78. [Space(8)]
  79. [IntRange] _Stencil ("Stencil Reference", Range (0, 255)) = 2
  80. [IntRange] _ReadMask (" Read Mask", Range (0, 255)) = 255
  81. [IntRange] _WriteMask (" Write Mask", Range (0, 255)) = 255
  82. [Enum(UnityEngine.Rendering.CompareFunction)]
  83. _StencilComp ("Stencil Comparison", Int) = 8 // always
  84. [Enum(UnityEngine.Rendering.StencilOp)]
  85. _StencilOp ("Stencil Operation", Int) = 2 // 0 = keep, 2 = replace
  86. [Enum(UnityEngine.Rendering.StencilOp)]
  87. _StencilFail ("Stencil Fail Op", Int) = 0 // 0 = keep
  88. [Enum(UnityEngine.Rendering.StencilOp)]
  89. _StencilZFail ("Stencil ZFail Op", Int) = 0 // 0 = keep
  90. [Header(Mask)]
  91. _MakeUpMask1_RGB("MakeUpMask1_RGB", 2D) = "black" {}
  92. _MakeUpMask2_RGB("MakeUpMask2_RGB", 2D) = "black" {}
  93. _Mask1_Rchannel_TextureAmountA("Mask1_Rchannel_Texture-Amount(A)", 2D) = "black" {}
  94. _Mask1_Gchannel_TextureAmountA("Mask1_Gchannel_Texture-Amount(A)", 2D) = "black" {}
  95. _Mask1_Bchannel_TextureAmountA("Mask1_Bchannel_Texture-Amount(A)", 2D) = "black" {}
  96. _Mask2_Rchannel_TextureAmountA("Mask2_Rchannel_Texture-Amount(A)", 2D) = "black" {}
  97. _Mask2_Gchannel_TextureAmountA("Mask2_Gchannel_Texture-Amount(A)", 2D) = "black" {}
  98. _Mask2_Bchannel_TextureAmountA("Mask2_Bchannel_Texture-Amount(A)", 2D) = "black" {}
  99. _Mask1_Rchannel_ColorAmountA("Mask1_Rchannel_Color-Amount(A)", Color) = (0.7735849, 0.2006942, 0.3233189, 0.7843137)
  100. _Mask1_Gchannel_ColorAmountA("Mask1_Gchannel_Color-Amount(A)", Color) = (0.2, 0.772549, 0.4917381, 0.7843137)
  101. _Mask1_Bchannel_ColorAmountA("Mask1_Bchannel_Color-Amount(A)", Color) = (0.2, 0.406334, 0.772549, 0.7843137)
  102. _Mask2_Rchannel_ColorAmountA("Mask2_Rchannel_Color-Amount(A)", Color) = (0.2, 0.772549, 0.7071339, 0.7843137)
  103. _Mask2_Gchannel_ColorAmountA("Mask2_Gchannel_Color-Amount(A)", Color) = (0.772549, 0.2, 0.6776864, 0.7843137)
  104. _Mask2_Bchannel_ColorAmountA("Mask2_Bchannel_Color-Amount(A)", Color) = (0.772549, 0.7037676, 0.2, 0.7843137)
  105. // Needed by the inspector
  106. [HideInInspector] _Culling ("Culling", Float) = 0.0
  107. // Lightmapper and outline selection shader need _MainTex, _Color and _Cutoff
  108. [HideInInspector] _MainTex ("Albedo", 2D) = "white" {}
  109. [HideInInspector] _Color ("Color", Color) = (1,1,1,1)
  110. [HideInInspector] _Cutoff ("Alpha Cutoff", Range(0.0, 1.0)) = 0.0
  111. // URP 10.1. needs this for the depthnormal pass
  112. [HideInInspector] _Cutoff (" Threshold", Range(0.0, 1.0)) = 0.5
  113. [HideInInspector] _Surface("__surface", Float) = 0.0
  114. }
  115. SubShader
  116. {
  117. Tags
  118. {
  119. "RenderPipeline" = "UniversalPipeline"
  120. "RenderType" = "Opaque"
  121. "Queue" = "Geometry+100"
  122. }
  123. LOD 100
  124. // XRay --------------------------------------------
  125. Pass
  126. {
  127. //Tags { "RenderType" = "Opaque"}
  128. Name "XRayPass"
  129. Tags{"LightMode" = "XRayBodyLight"}
  130. Blend SrcAlpha One
  131. //ZWrite Off
  132. //ZTest Greater
  133. //Cull Back
  134. HLSLPROGRAM
  135. // Required to compile gles 2.0 with standard SRP library
  136. //#pragma prefer_hlslcc gles
  137. #pragma glsl
  138. #pragma exclude_renderers d3d11_9x
  139. #pragma target 2.0
  140. #pragma vertex vert
  141. #pragma fragment frag
  142. //#include "UnityCG.cginc"
  143. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  144. float4 _XRimColor;
  145. struct appdata
  146. {
  147. float4 vertex : POSITION;
  148. float3 normal : NORMAL;
  149. float3 viewDir: TEXCOORD0;
  150. };
  151. struct v2f
  152. {
  153. float4 pos : SV_POSITION;
  154. float3 normal : NORMAL;
  155. float3 viewDir: TEXCOORD0;
  156. };
  157. v2f vert(appdata v)
  158. {
  159. v2f o;
  160. o.pos = TransformObjectToHClip(v.vertex.xyz);
  161. o.viewDir = TransformWorldToObject(GetCameraPositionWS()) - v.vertex.xyz;
  162. o.normal = v.normal;
  163. return o;
  164. }
  165. float4 frag(v2f IN) : COLOR
  166. {
  167. float3 normal = normalize(IN.normal);
  168. float3 viewDir = normalize(IN.viewDir);
  169. float rim = 1 - dot(normal, viewDir);
  170. return _XRimColor * rim;
  171. }
  172. ENDHLSL
  173. }
  174. Pass
  175. {
  176. Name "ForwardLit"
  177. Tags{"LightMode" = "UniversalForward"}
  178. Stencil {
  179. Ref [_Stencil]
  180. ReadMask [_ReadMask]
  181. WriteMask [_WriteMask]
  182. Comp [_StencilComp]
  183. Pass [_StencilOp]
  184. Fail [_StencilFail]
  185. ZFail [_StencilZFail]
  186. }
  187. ZWrite On
  188. Cull Back
  189. HLSLPROGRAM
  190. // Required to compile gles 2.0 with standard SRP library
  191. #pragma prefer_hlslcc gles
  192. #pragma exclude_renderers d3d11_9x
  193. #pragma target 2.0
  194. // -------------------------------------
  195. // Material Keywords
  196. #define _SPECULAR_SETUP
  197. #pragma shader_feature_local _NORMALMAP
  198. #pragma shader_feature_local_fragment _NORMALMAPDIFFUSE
  199. #pragma shader_feature_local _DISTANCEFADE // not per fragment
  200. #pragma shader_feature_local_fragment _RIMLIGHTING
  201. #pragma shader_feature_local_fragment _BACKSCATTER
  202. #pragma shader_feature_local_fragment _SPECULARHIGHLIGHTS_OFF
  203. #pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF
  204. #pragma shader_feature_local _RECEIVE_SHADOWS_OFF
  205. // -------------------------------------
  206. // Universal Pipeline keywords
  207. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
  208. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
  209. #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  210. #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
  211. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  212. #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
  213. #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
  214. #pragma multi_compile _ SHADOWS_SHADOWMASK
  215. // -------------------------------------
  216. // Unity defined keywords
  217. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  218. #pragma multi_compile _ LIGHTMAP_ON
  219. #pragma multi_compile_fog
  220. //--------------------------------------
  221. // GPU Instancing
  222. #pragma multi_compile_instancing
  223. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  224. // Include base inputs and all other needed "base" includes
  225. #include "Includes/Lux URP Skin Inputs.hlsl"
  226. #pragma vertex LitPassVertex
  227. #pragma fragment LitPassFragment
  228. //CBUFFER_START(UnityPerMaterial)
  229. //float4 _MakeUpMask1_RGB_ST;
  230. //float4 _MakeUpMask2_RGB_ST;
  231. //float4 _Mask1_Rchannel_ColorAmountA;
  232. //float4 _Mask1_Gchannel_ColorAmountA;
  233. //float4 _Mask1_Bchannel_ColorAmountA;
  234. //float4 _Mask2_Rchannel_ColorAmountA;
  235. //float4 _Mask2_Gchannel_ColorAmountA;
  236. //float4 _Mask2_Bchannel_ColorAmountA;
  237. //float4 _Mask1_Rchannel_TextureAmountA_ST;
  238. //float4 _Mask1_Gchannel_TextureAmountA_ST;
  239. //float4 _Mask1_Bchannel_TextureAmountA_ST;
  240. //float4 _Mask2_Rchannel_TextureAmountA_ST;
  241. //float4 _Mask2_Gchannel_TextureAmountA_ST;
  242. //float4 _Mask2_Bchannel_TextureAmountA_ST;
  243. //CBUFFER_END
  244. float4 _MakeUpMask1_RGB_ST;
  245. float4 _MakeUpMask2_RGB_ST;
  246. float4 _Mask1_Rchannel_ColorAmountA;
  247. float4 _Mask1_Gchannel_ColorAmountA;
  248. float4 _Mask1_Bchannel_ColorAmountA;
  249. float4 _Mask2_Rchannel_ColorAmountA;
  250. float4 _Mask2_Gchannel_ColorAmountA;
  251. float4 _Mask2_Bchannel_ColorAmountA;
  252. float4 _Mask1_Rchannel_TextureAmountA_ST;
  253. float4 _Mask1_Gchannel_TextureAmountA_ST;
  254. float4 _Mask1_Bchannel_TextureAmountA_ST;
  255. float4 _Mask2_Rchannel_TextureAmountA_ST;
  256. float4 _Mask2_Gchannel_TextureAmountA_ST;
  257. float4 _Mask2_Bchannel_TextureAmountA_ST;
  258. sampler2D _MakeUpMask1_RGB;
  259. SAMPLER(sampler_MakeUpMask1_RGB);
  260. sampler2D _MakeUpMask2_RGB;
  261. SAMPLER(sampler_MakeUpMask2_RGB);
  262. sampler2D _Mask1_Rchannel_TextureAmountA;
  263. SAMPLER(sampler_Mask1_Rchannel_TextureAmountA);
  264. sampler2D _Mask1_Gchannel_TextureAmountA;
  265. SAMPLER(sampler_Mask1_Gchannel_TextureAmountA);
  266. sampler2D _Mask1_Bchannel_TextureAmountA;
  267. SAMPLER(sampler_Mask1_Bchannel_TextureAmountA);
  268. sampler2D _Mask2_Rchannel_TextureAmountA;
  269. SAMPLER(sampler_Mask2_Rchannel_TextureAmountA);
  270. sampler2D _Mask2_Gchannel_TextureAmountA;
  271. SAMPLER(sampler_Mask2_Gchannel_TextureAmountA);
  272. sampler2D _Mask2_Bchannel_TextureAmountA;
  273. SAMPLER(sampler_Mask2_Bchannel_TextureAmountA);
  274. //--------------------------------------
  275. // Vertex shader
  276. VertexOutput LitPassVertex(VertexInput input)
  277. {
  278. VertexOutput output = (VertexOutput)0;
  279. UNITY_SETUP_INSTANCE_ID(input);
  280. UNITY_TRANSFER_INSTANCE_ID(input, output);
  281. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  282. // Set distance fade value
  283. #if defined(_DISTANCEFADE)
  284. float3 worldInstancePos = UNITY_MATRIX_M._m03_m13_m23;
  285. float3 diff = (_WorldSpaceCameraPos - worldInstancePos);
  286. float dist = dot(diff, diff);
  287. output.fade = saturate( (_DistanceFade.x - dist) * _DistanceFade.y );
  288. #else
  289. output.fade = 1.0h;
  290. #endif
  291. VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
  292. VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
  293. float3 viewDirWS = GetCameraPositionWS() - vertexInput.positionWS;
  294. half3 vertexLight = VertexLighting(vertexInput.positionWS, normalInput.normalWS);
  295. half fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
  296. output.uv.xy = input.texcoord;
  297. output.normalWS = normalInput.normalWS; //NormalizeNormalPerVertex(normalInput.normalWS);
  298. output.viewDirWS = viewDirWS;
  299. #ifdef _NORMALMAP
  300. float sign = input.tangentOS.w * GetOddNegativeScale();
  301. output.tangentWS = float4(normalInput.tangentWS.xyz, sign);
  302. #endif
  303. OUTPUT_LIGHTMAP_UV(input.lightmapUV, unity_LightmapST, output.lightmapUV);
  304. OUTPUT_SH(output.normalWS.xyz, output.vertexSH);
  305. output.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
  306. #if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR)
  307. output.positionWS = vertexInput.positionWS;
  308. #endif
  309. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  310. // tweak the sampling position
  311. vertexInput.positionWS += output.normalWS.xyz * _SkinShadowSamplingBias;
  312. output.shadowCoord = GetShadowCoord(vertexInput);
  313. #endif
  314. output.positionCS = vertexInput.positionCS;
  315. return output;
  316. }
  317. //--------------------------------------
  318. // Fragment shader and functions
  319. inline void InitializeSkinLitSurfaceData(float2 uv, half fade, out SurfaceDescription outSurfaceData)
  320. {
  321. half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)) * _BaseColor;
  322. //--------------------------------------------------------
  323. float2 uv_MakeUpMask1_RGB = uv.xy * _MakeUpMask1_RGB_ST.xy + _MakeUpMask1_RGB_ST.zw;
  324. float4 tex2DNode143 = tex2D(_MakeUpMask1_RGB, uv_MakeUpMask1_RGB);
  325. float2 uv_Mask1_Rchannel_TextureAmountA = uv.xy * _Mask1_Rchannel_TextureAmountA_ST.xy + _Mask1_Rchannel_TextureAmountA_ST.zw;
  326. float4 tex2D_mask1_R = tex2D(_Mask1_Rchannel_TextureAmountA, uv_Mask1_Rchannel_TextureAmountA);
  327. float2 uv_Mask1_Gchannel_TextureAmountA = uv.xy * _Mask1_Gchannel_TextureAmountA_ST.xy + _Mask1_Gchannel_TextureAmountA_ST.zw;
  328. float4 tex2D_mask1_G = tex2D(_Mask1_Gchannel_TextureAmountA, uv_Mask1_Gchannel_TextureAmountA);
  329. float2 uv_Mask1_Bchannel_TextureAmountA = uv.xy * _Mask1_Bchannel_TextureAmountA_ST.xy + _Mask1_Bchannel_TextureAmountA_ST.zw;
  330. float4 tex2D_mask1_B = tex2D(_Mask1_Bchannel_TextureAmountA, uv_Mask1_Bchannel_TextureAmountA);
  331. float2 uv_Mask2_Rchannel_TextureAmountA = uv.xy * _Mask2_Rchannel_TextureAmountA_ST.xy + _Mask2_Rchannel_TextureAmountA_ST.zw;
  332. float4 tex2D_mask2_R = tex2D(_Mask2_Rchannel_TextureAmountA, uv_Mask2_Rchannel_TextureAmountA);
  333. float2 uv_Mask2_Gchannel_TextureAmountA = uv.xy * _Mask2_Gchannel_TextureAmountA_ST.xy + _Mask2_Gchannel_TextureAmountA_ST.zw;
  334. float4 tex2D_mask2_G = tex2D(_Mask2_Gchannel_TextureAmountA, uv_Mask2_Gchannel_TextureAmountA);
  335. float2 uv_Mask2_Bchannel_TextureAmountA = uv.xy * _Mask2_Bchannel_TextureAmountA_ST.xy + _Mask2_Bchannel_TextureAmountA_ST.zw;
  336. float4 tex2D_mask2_B = tex2D(_Mask2_Bchannel_TextureAmountA, uv_Mask2_Bchannel_TextureAmountA);
  337. float clampResult295 = clamp((tex2DNode143.r * tex2D_mask1_R.a * _Mask1_Rchannel_ColorAmountA.a), 0.0, 1.0);
  338. float4 _Mask1_R_Color = tex2D_mask1_R * _Mask1_Rchannel_ColorAmountA;
  339. float4 lerpResult145 = lerp(albedoAlpha, _Mask1_R_Color, clampResult295);
  340. float clampResult296 = clamp((tex2DNode143.g * tex2D_mask1_G.a * _Mask1_Gchannel_ColorAmountA.a), 0.0, 1.0);
  341. float4 _Mask1_G_Color = tex2D_mask1_G * _Mask1_Gchannel_ColorAmountA;
  342. float4 lerpResult160 = lerp(lerpResult145, _Mask1_G_Color, clampResult296);
  343. float clampResult297 = clamp((tex2DNode143.b * tex2D_mask1_B.a * _Mask1_Bchannel_ColorAmountA.a), 0.0, 1.0);
  344. float4 _Mask1_B_Color = tex2D_mask1_B * _Mask1_Bchannel_ColorAmountA;
  345. float4 lerpResult161 = lerp(lerpResult160, _Mask1_B_Color, clampResult297);
  346. //mask2
  347. float2 uv_MakeUpMask2_RGB = uv.xy * _MakeUpMask2_RGB_ST.xy + _MakeUpMask2_RGB_ST.zw;
  348. float4 tex2DNode144 = tex2D(_MakeUpMask2_RGB, uv_MakeUpMask2_RGB);
  349. float clampResult298 = clamp((tex2DNode144.r * tex2D_mask2_R.a * _Mask2_Rchannel_ColorAmountA.a), 0.0, 1.0);
  350. float4 _Mask2_R_Color = tex2D_mask2_R * _Mask2_Rchannel_ColorAmountA;
  351. float4 lerpResult162 = lerp(lerpResult161, _Mask2_Rchannel_ColorAmountA, clampResult298);
  352. float clampResult299 = clamp((tex2DNode144.g * tex2D_mask2_G.a * _Mask2_Gchannel_ColorAmountA.a), 0.0, 1.0);
  353. float4 _Mask2_G_Color = tex2D_mask2_G * _Mask2_Gchannel_ColorAmountA;
  354. float4 lerpResult163 = lerp(lerpResult162, _Mask2_Gchannel_ColorAmountA, clampResult299);
  355. float clampResult300 = clamp((tex2DNode144.b * tex2D_mask2_B.a * _Mask2_Bchannel_ColorAmountA.a), 0.0, 1.0);
  356. float4 _Mask2_B_Color = tex2D_mask2_B * _Mask2_Bchannel_ColorAmountA;
  357. float4 lerpResult164 = lerp(lerpResult163, _Mask2_Bchannel_ColorAmountA, clampResult300);
  358. albedoAlpha.rgb = half3(lerpResult164.r, lerpResult164.g, lerpResult164.b);
  359. //--------------------------------
  360. outSurfaceData.alpha = 1;
  361. outSurfaceData.albedo = albedoAlpha.rgb;
  362. outSurfaceData.metallic = 0;
  363. outSurfaceData.specular = _SpecularColor.rgb;
  364. // Normal Map
  365. #if defined (_NORMALMAP)
  366. outSurfaceData.normalTS = SampleNormal(uv, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap), _BumpScale);
  367. #if defined(_NORMALMAPDIFFUSE)
  368. half4 sampleNormalDiffuse = SAMPLE_TEXTURE2D_BIAS(_BumpMap, sampler_BumpMap, uv, _Bias);
  369. // Do not manually unpack the normal map as it might use RGB.
  370. outSurfaceData.diffuseNormalTS = UnpackNormal(sampleNormalDiffuse);
  371. #else
  372. outSurfaceData.diffuseNormalTS = half3(0,0,1);
  373. #endif
  374. #else
  375. outSurfaceData.normalTS = half3(0,0,1);
  376. outSurfaceData.diffuseNormalTS = half3(0,0,1);
  377. #endif
  378. half4 SSSAOSample = SAMPLE_TEXTURE2D(_SSSAOMap, sampler_SSSAOMap, uv);
  379. outSurfaceData.translucency = SSSAOSample.g;
  380. outSurfaceData.skinMask = SSSAOSample.r;
  381. outSurfaceData.occlusion = lerp(1.0h, SSSAOSample.a, _OcclusionStrength);
  382. outSurfaceData.curvature = SSSAOSample.b;
  383. outSurfaceData.smoothness = albedoAlpha.a * _Smoothness;
  384. outSurfaceData.emission = 0;
  385. }
  386. void InitializeInputData(VertexOutput input, half3 normalTS, half3 diffuseNormalTS, out InputData inputData
  387. #ifdef _NORMALMAP
  388. , inout float3 bitangent
  389. #endif
  390. , inout half3 diffuseNormalWS
  391. )
  392. {
  393. inputData = (InputData)0;
  394. #if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR)
  395. inputData.positionWS = input.positionWS;
  396. #endif
  397. half3 viewDirWS = SafeNormalize(input.viewDirWS);
  398. #ifdef _NORMALMAP
  399. float sgn = input.tangentWS.w; // should be either +1 or -1
  400. bitangent = sgn * cross(input.normalWS.xyz, input.tangentWS.xyz);
  401. half3x3 ToW = half3x3(input.tangentWS.xyz, bitangent, input.normalWS.xyz);
  402. inputData.normalWS = TransformTangentToWorld(normalTS, ToW);
  403. inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
  404. #ifdef _NORMALMAPDIFFUSE
  405. diffuseNormalWS = TransformTangentToWorld(diffuseNormalTS, ToW);
  406. diffuseNormalWS = NormalizeNormalPerPixel(diffuseNormalWS);
  407. #else
  408. // Here we let the user decide to use the per vertex or the specular normal.
  409. diffuseNormalWS = (_VertexNormal) ? NormalizeNormalPerPixel(input.normalWS.xyz) : inputData.normalWS;
  410. #endif
  411. #else
  412. inputData.normalWS = NormalizeNormalPerPixel(input.normalWS);
  413. diffuseNormalWS = inputData.normalWS;
  414. #endif
  415. inputData.viewDirectionWS = viewDirWS;
  416. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  417. inputData.shadowCoord = input.shadowCoord;
  418. #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  419. inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS + input.normalWS * _SkinShadowSamplingBias);
  420. #else
  421. inputData.shadowCoord = float4(0, 0, 0, 0);
  422. #endif
  423. inputData.fogCoord = input.fogFactorAndVertexLight.x;
  424. inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
  425. inputData.bakedGI = SAMPLE_GI(input.lightmapUV, input.vertexSH, diffuseNormalWS); //inputData.normalWS);
  426. //inputData.normalizedScreenSpaceUV = input.positionCS.xy;
  427. inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
  428. }
  429. half4 LitPassFragment(VertexOutput input) : SV_Target
  430. {
  431. UNITY_SETUP_INSTANCE_ID(input);
  432. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  433. // Get the surface description
  434. SurfaceDescription surfaceData;
  435. InitializeSkinLitSurfaceData(input.uv.xy, input.fade, surfaceData);
  436. // Prepare surface data (like bring normal into world space and get missing inputs like gi
  437. half3 diffuseNormalWS;
  438. InputData inputData;
  439. #ifdef _NORMALMAP
  440. float3 bitangent;
  441. #endif
  442. InitializeInputData(input, surfaceData.normalTS, surfaceData.diffuseNormalTS, inputData
  443. #ifdef _NORMALMAP
  444. , bitangent
  445. #endif
  446. , diffuseNormalWS
  447. );
  448. #if defined(_RIMLIGHTING)
  449. half rim = saturate(1.0h - saturate( dot(inputData.normalWS, inputData.viewDirectionWS) ) );
  450. half power = _RimPower;
  451. UNITY_BRANCH if(_RimFrequency > 0 ) {
  452. half perPosition = lerp(0.0h, 1.0h, dot(1.0h, frac(UNITY_MATRIX_M._m03_m13_m23) * 2.0h - 1.0h ) * _RimPerPositionFrequency ) * 3.1416h;
  453. power = lerp(power, _RimMinPower, (1.0h + sin(_Time.y * _RimFrequency + perPosition) ) * 0.5h );
  454. }
  455. surfaceData.emission += pow(rim, power) * _RimColor.rgb * _RimColor.a;
  456. #endif
  457. // Apply lighting
  458. half4 color = LuxLWRPSkinFragmentPBR(
  459. inputData,
  460. surfaceData.albedo,
  461. surfaceData.metallic,
  462. surfaceData.specular,
  463. surfaceData.smoothness,
  464. surfaceData.occlusion,
  465. surfaceData.emission,
  466. surfaceData.alpha,
  467. // Subsurface Scattering
  468. half4(_TranslucencyStrength * surfaceData.translucency, _TranslucencyPower, _ShadowStrength, _Distortion),
  469. // AmbientReflection Strength
  470. _AmbientReflectionStrength,
  471. // Diffuse Normal
  472. // #if defined(_NORMALMAP) && defined(_NORMALMAPDIFFUSE)
  473. // NormalizeNormalPerPixel( TransformTangentToWorld(surfaceData.diffuseNormalTS, half3x3(input.tangentWS.xyz, bitangent, input.normalWS.xyz)) )
  474. // #else
  475. // input.normalWS
  476. // #endif
  477. diffuseNormalWS,
  478. _SubsurfaceColor.rgb,
  479. (_SampleCurvature) ? surfaceData.curvature * _Curvature : lerp(surfaceData.translucency, 1, _Curvature),
  480. // Lerp lighting towards standard according the distance fade
  481. surfaceData.skinMask * input.fade,
  482. _MaskByShadowStrength,
  483. _Backscatter
  484. );
  485. // Add fog
  486. color.rgb = MixFog(color.rgb, inputData.fogCoord);
  487. return color;
  488. }
  489. ENDHLSL
  490. }
  491. // Shadows -----------------------------------------------------
  492. Pass
  493. {
  494. Name "ShadowCaster"
  495. Tags{"LightMode" = "ShadowCaster"}
  496. ZWrite On
  497. ZTest LEqual
  498. ColorMask 0
  499. Cull Back
  500. HLSLPROGRAM
  501. // Required to compile gles 2.0 with standard srp library
  502. #pragma prefer_hlslcc gles
  503. #pragma exclude_renderers d3d11_9x
  504. #pragma target 2.0
  505. // -------------------------------------
  506. // Material Keywords
  507. //--------------------------------------
  508. // GPU Instancing
  509. #pragma multi_compile_instancing
  510. #pragma vertex ShadowPassVertex
  511. #pragma fragment ShadowPassFragment
  512. // Include base inputs and all other needed "base" includes
  513. #include "Includes/Lux URP Skin Inputs.hlsl"
  514. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
  515. // Shadow caster specific input
  516. float3 _LightDirection;
  517. VertexOutput ShadowPassVertex(VertexInput input)
  518. {
  519. VertexOutput output = (VertexOutput)0;
  520. UNITY_SETUP_INSTANCE_ID(input);
  521. UNITY_TRANSFER_INSTANCE_ID(input, output);
  522. float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
  523. float3 normalWS = TransformObjectToWorldDir(input.normalOS);
  524. output.positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS * _SkinShadowBias, _LightDirection));
  525. #if UNITY_REVERSED_Z
  526. output.positionCS.z = min(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE);
  527. #else
  528. output.positionCS.z = max(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE);
  529. #endif
  530. return output;
  531. }
  532. half4 ShadowPassFragment(VertexOutput input) : SV_TARGET
  533. {
  534. UNITY_SETUP_INSTANCE_ID(input);
  535. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  536. return 0;
  537. }
  538. ENDHLSL
  539. }
  540. // Depth -----------------------------------------------------
  541. Pass
  542. {
  543. Tags{"LightMode" = "DepthOnly"}
  544. ZWrite On
  545. ColorMask 0
  546. Cull Back
  547. HLSLPROGRAM
  548. // Required to compile gles 2.0 with standard srp library
  549. #pragma prefer_hlslcc gles
  550. #pragma exclude_renderers d3d11_9x
  551. #pragma target 2.0
  552. #pragma vertex DepthOnlyVertex
  553. #pragma fragment DepthOnlyFragment
  554. // -------------------------------------
  555. // Material Keywords
  556. //--------------------------------------
  557. // GPU Instancing
  558. #pragma multi_compile_instancing
  559. #define DEPTHONLYPASS
  560. #include "Includes/Lux URP Skin Inputs.hlsl"
  561. VertexOutput DepthOnlyVertex(VertexInput input)
  562. {
  563. VertexOutput output = (VertexOutput)0;
  564. UNITY_SETUP_INSTANCE_ID(input);
  565. UNITY_TRANSFER_INSTANCE_ID(input, output);
  566. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  567. output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
  568. return output;
  569. }
  570. half4 DepthOnlyFragment(VertexOutput input) : SV_TARGET
  571. {
  572. UNITY_SETUP_INSTANCE_ID(input);
  573. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  574. return 0;
  575. }
  576. ENDHLSL
  577. }
  578. // Depth Normals --------------------------------------------
  579. Pass
  580. {
  581. Name "DepthNormals"
  582. Tags{"LightMode" = "DepthNormals"}
  583. ZWrite On
  584. Cull Back
  585. HLSLPROGRAM
  586. // Required to compile gles 2.0 with standard SRP library
  587. #pragma prefer_hlslcc gles
  588. #pragma exclude_renderers d3d11_9x
  589. #pragma target 2.0
  590. #pragma vertex DepthNormalsVertex
  591. #pragma fragment DepthNormalsFragment
  592. // -------------------------------------
  593. // Material Keywords
  594. #pragma shader_feature_local _NORMALMAP
  595. //--------------------------------------
  596. // GPU Instancing
  597. #pragma multi_compile_instancing
  598. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  599. //#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
  600. #include "Includes/Lux URP Skin Inputs.hlsl"
  601. #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthNormalsPass.hlsl"
  602. ENDHLSL
  603. }
  604. // Meta -----------------------------------------------------
  605. Pass
  606. {
  607. Tags{"LightMode" = "Meta"}
  608. Cull Off
  609. HLSLPROGRAM
  610. // Required to compile gles 2.0 with standard srp library
  611. #pragma prefer_hlslcc gles
  612. #pragma vertex UniversalVertexMeta
  613. #pragma fragment UniversalFragmentMeta
  614. #define _SPECULAR_SETUP
  615. // First include all our custom stuff
  616. #include "Includes/Lux URP Skin Inputs.hlsl"
  617. //--------------------------------------
  618. // Fragment shader and functions
  619. inline void InitializeStandardLitSurfaceData(float2 uv, out SurfaceData outSurfaceData)
  620. {
  621. half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
  622. outSurfaceData.alpha = 1;
  623. outSurfaceData.albedo = albedoAlpha.rgb;
  624. outSurfaceData.metallic = 0;
  625. outSurfaceData.specular = _SpecularColor.rgb;
  626. outSurfaceData.smoothness = _Smoothness;
  627. outSurfaceData.normalTS = half3(0,0,1);
  628. outSurfaceData.occlusion = 1;
  629. outSurfaceData.emission = 0;
  630. outSurfaceData.clearCoatMask = 0;
  631. outSurfaceData.clearCoatSmoothness = 0;
  632. }
  633. // Finally include the meta pass related stuff
  634. #include "Packages/com.unity.render-pipelines.universal/Shaders/LitMetaPass.hlsl"
  635. ENDHLSL
  636. }
  637. // End Passes -----------------------------------------------------
  638. }
  639. CustomEditor "LuxURPCustomSkinShaderGUI"
  640. FallBack "Hidden/InternalErrorShader"
  641. }