Lux URP Skin Custom.shader 32 KB

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