Lux URP Skin.shader 25 KB

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