Lux URP Skin Custom.shader 32 KB

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