Lux URP Cloth.shader 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. // Shader uses custom editor to set double sided GI
  2. // Needs _Culling to be set properly
  3. // HDRP Cloth remaps smoothnes to 0-0.6 if cotton woll is enabled
  4. Shader "Lux URP/Cloth"
  5. {
  6. Properties
  7. {
  8. [HeaderHelpLuxURP_URL(kg40d8bgwewa)]
  9. [Header(Surface Options)]
  10. [Space(8)]
  11. [Enum(UnityEngine.Rendering.CullMode)]
  12. _Cull ("Culling", Float) = 2
  13. [Toggle(_ALPHATEST_ON)]
  14. _AlphaClip ("Alpha Clipping", Float) = 0.0
  15. [LuxURPHelpDrawer]
  16. _Help ("Enabling Alpha Clipping needs you to enable and assign the Mask Map as well.", Float) = 0.0
  17. _Cutoff (" Threshold", Range(0.0, 1.0)) = 0.5
  18. [ToggleOff(_RECEIVE_SHADOWS_OFF)]
  19. _ReceiveShadows ("Receive Shadows", Float) = 1.0
  20. _ShadowOffset ("Shadow Offset", Float) = 1.0
  21. [Header(Charlie Sheen Lighting)]
  22. [Space(8)]
  23. [Toggle(_COTTONWOOL)]
  24. _UseCottonWool ("Enable Charlie Sheen Lighting", Float) = 0.0
  25. //[NoScaleOffset]
  26. // Only needed for IBL – so we can skip it
  27. //_PreIntegratedLUT (" Preintegrated LUT", 2D) = "white" {}
  28. _SheenColor (" Sheen Color", Color) = (0.5, 0.5, 0.5)
  29. [Header(GGX anisotropic Lighting)]
  30. [Space(8)]
  31. _Anisotropy (" Anisotropy", Range(-1.0, 1.0)) = 0.0
  32. [Header(Transmission)]
  33. [Space(8)]
  34. [Toggle(_SCATTERING)]
  35. _UseScattering ("Enable Transmission", Float) = 0.0
  36. _TranslucencyPower (" Power", Range(0.0, 32.0)) = 7.0
  37. _TranslucencyStrength (" Strength", Range(0.0, 1.0)) = 1.0
  38. _ShadowStrength (" Shadow Strength", Range(0.0, 1.0)) = 0.7
  39. _Distortion (" Distortion", Range(0.0, 0.1)) = 0.01
  40. [Header(Surface Inputs)]
  41. [Space(8)]
  42. [MainColor]
  43. _BaseColor ("Color", Color) = (1,1,1,1)
  44. [MainTexture]
  45. _BaseMap ("Albedo (RGB) Smoothness (A)", 2D) = "white" {}
  46. [Space(5)]
  47. _Smoothness ("Smoothness", Range(0.0, 1.0)) = 0.5
  48. _SpecColor ("Specular", Color) = (0.2, 0.2, 0.2)
  49. [Space(5)]
  50. [Toggle(_NORMALMAP)]
  51. _ApplyNormal ("Enable Normal Map", Float) = 0.0
  52. [NoScaleOffset]
  53. _BumpMap (" Normal Map", 2D) = "bump" {}
  54. _BumpScale (" Normal Scale", Float) = 1.0
  55. [Space(5)]
  56. [Toggle(_MASKMAP)]
  57. _EnableMaskMap ("Enable Mask Map", Float) = 0.0
  58. _MaskMap (" Thickness (G) Occlusion (B) Alpha (A)", 2D) = "white" {}
  59. _OcclusionStrength (" Occlusion", Range(0.0, 1.0)) = 1
  60. [Header(Rim Lighting)]
  61. [Space(8)]
  62. [Toggle(_RIMLIGHTING)]
  63. _Rim ("Enable Rim Lighting", Float) = 0
  64. [HDR] _RimColor ("Rim Color", Color) = (0.5,0.5,0.5,1)
  65. _RimPower ("Rim Power", Float) = 2
  66. _RimFrequency ("Rim Frequency", Float) = 0
  67. _RimMinPower (" Rim Min Power", Float) = 1
  68. _RimPerPositionFrequency (" Rim Per Position Frequency", Range(0.0, 1.0)) = 1
  69. [Header(Stencil)]
  70. [Space(8)]
  71. [IntRange] _Stencil ("Stencil Reference", Range (0, 255)) = 0
  72. [IntRange] _ReadMask (" Read Mask", Range (0, 255)) = 255
  73. [IntRange] _WriteMask (" Write Mask", Range (0, 255)) = 255
  74. [Enum(UnityEngine.Rendering.CompareFunction)]
  75. _StencilComp ("Stencil Comparison", Int) = 8 // always – terrain should be the first thing being rendered anyway
  76. [Enum(UnityEngine.Rendering.StencilOp)]
  77. _StencilOp ("Stencil Operation", Int) = 0 // 0 = keep, 2 = replace
  78. [Enum(UnityEngine.Rendering.StencilOp)]
  79. _StencilFail ("Stencil Fail Op", Int) = 0 // 0 = keep
  80. [Enum(UnityEngine.Rendering.StencilOp)]
  81. _StencilZFail ("Stencil ZFail Op", Int) = 0 // 0 = keep
  82. [Header(Advanced)]
  83. [Space(8)]
  84. //[ToggleOff]
  85. //_SpecularHighlights ("Enable Specular Highlights", Float) = 1.0
  86. [ToggleOff]
  87. _EnvironmentReflections ("Environment Reflections", Float) = 1.0
  88. [Space(5)]
  89. [Toggle(_RECEIVE_SHADOWS_OFF)]
  90. _Shadows ("Disable Receive Shadows", Float) = 0.0
  91. [Header(Render Queue)]
  92. [Space(8)]
  93. [IntRange] _QueueOffset ("Queue Offset", Range(-50, 50)) = 0
  94. // Needed by the inspector
  95. [HideInInspector] _Culling ("Culling", Float) = 0.0
  96. [HideInInspector] _AlphaFromMaskMap ("AlphaFromMaskMap", Float) = 1.0
  97. // Lightmapper and outline selection shader need _MainTex, _Color and _Cutoff
  98. [HideInInspector] _MainTex ("Albedo", 2D) = "white" {}
  99. [HideInInspector] _Color ("Color", Color) = (1,1,1,1)
  100. }
  101. SubShader
  102. {
  103. Tags
  104. {
  105. "RenderPipeline" = "UniversalPipeline"
  106. "RenderType" = "Opaque"
  107. "Queue" = "Geometry"
  108. }
  109. LOD 100
  110. Pass
  111. {
  112. Name "ForwardLit"
  113. Tags{"LightMode" = "UniversalForward"}
  114. Stencil {
  115. Ref [_Stencil]
  116. ReadMask [_ReadMask]
  117. WriteMask [_WriteMask]
  118. Comp [_StencilComp]
  119. Pass [_StencilOp]
  120. Fail [_StencilFail]
  121. ZFail [_StencilZFail]
  122. }
  123. ZWrite On
  124. Cull [_Cull]
  125. HLSLPROGRAM
  126. // Required to compile gles 2.0 with standard SRP library
  127. #pragma prefer_hlslcc gles
  128. #pragma exclude_renderers d3d11_9x
  129. #pragma target 2.0
  130. // -------------------------------------
  131. // Material Keywords
  132. #define _SPECULAR_SETUP 1
  133. #pragma shader_feature_local _NORMALMAP
  134. #pragma shader_feature_local _ALPHATEST_ON // not per fragment!
  135. #pragma shader_feature_local _MASKMAP
  136. #pragma shader_feature_local_fragment _COTTONWOOL
  137. #pragma shader_feature_local_fragment _SCATTERING
  138. #pragma shader_feature_local_fragment _RIMLIGHTING
  139. //#pragma shader_feature _SPECULARHIGHLIGHTS_OFF // does not make sense here
  140. #pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF
  141. #pragma shader_feature_local _RECEIVE_SHADOWS_OFF
  142. // -------------------------------------
  143. // Universal Pipeline keywords
  144. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
  145. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
  146. #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  147. #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
  148. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  149. #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
  150. #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
  151. #pragma multi_compile _ SHADOWS_SHADOWMASK
  152. // -------------------------------------
  153. // Unity defined keywords
  154. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  155. #pragma multi_compile _ LIGHTMAP_ON
  156. #pragma multi_compile_fog
  157. //--------------------------------------
  158. // GPU Instancing
  159. #pragma multi_compile_instancing
  160. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  161. // Include base inputs and all other needed "base" includes
  162. #include "Includes/Lux URP Cloth Inputs.hlsl"
  163. #pragma vertex LitPassVertex
  164. #pragma fragment LitPassFragment
  165. //--------------------------------------
  166. // Vertex shader
  167. VertexOutput LitPassVertex(VertexInput input)
  168. {
  169. VertexOutput output = (VertexOutput)0;
  170. UNITY_SETUP_INSTANCE_ID(input);
  171. UNITY_TRANSFER_INSTANCE_ID(input, output);
  172. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  173. VertexPositionInputs vertexInput; //
  174. vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
  175. VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
  176. float3 viewDirWS = GetCameraPositionWS() - vertexInput.positionWS;
  177. half3 vertexLight = VertexLighting(vertexInput.positionWS, normalInput.normalWS);
  178. half fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
  179. output.uv.xy = TRANSFORM_TEX(input.texcoord, _BaseMap);
  180. #if defined(_MASKMAP)
  181. output.uv.zw = TRANSFORM_TEX(input.texcoord, _MaskMap);
  182. #endif
  183. // already normalized from normal transform to WS.
  184. output.normalWS = normalInput.normalWS;
  185. output.viewDirWS = viewDirWS;
  186. // GGX needs the tangent even if no normal is assigned!
  187. #if defined(_NORMALMAP) || !defined(_COTTONWOOL)
  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. output.shadowCoord = GetShadowCoord(vertexInput);
  199. #endif
  200. output.positionCS = vertexInput.positionCS;
  201. return output;
  202. }
  203. //--------------------------------------
  204. // Fragment shader and functions
  205. inline void InitializeSurfaceData(
  206. #if defined(_MASKMAP)
  207. float4 uv,
  208. #else
  209. float2 uv,
  210. #endif
  211. out SurfaceDescription outSurfaceData)
  212. {
  213. half4 albedoSmoothness = SampleAlbedoAlpha(uv.xy, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
  214. #if defined(_MASKMAP)
  215. half4 maskSample = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, uv.zw);
  216. outSurfaceData.translucency = maskSample.g;
  217. //outSurfaceData.skinMask = SSSAOSample.r;
  218. outSurfaceData.occlusion = lerp(1.0h, maskSample.b, _OcclusionStrength);
  219. #else
  220. outSurfaceData.translucency = 1;
  221. outSurfaceData.occlusion = 1;
  222. #endif
  223. #if defined(_ALPHATEST_ON) && defined(_MASKMAP)
  224. outSurfaceData.alpha = Alpha(maskSample.a, 1, _Cutoff);
  225. #else
  226. outSurfaceData.alpha = 1;
  227. #endif
  228. outSurfaceData.albedo = albedoSmoothness.rgb * _BaseColor.rgb;
  229. outSurfaceData.metallic = 0;
  230. outSurfaceData.specular = _SpecColor.rgb;
  231. outSurfaceData.smoothness = albedoSmoothness.a * _Smoothness;
  232. // Normal Map
  233. #if defined (_NORMALMAP)
  234. outSurfaceData.normalTS = SampleNormal(uv.xy, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap), _BumpScale);
  235. #else
  236. outSurfaceData.normalTS = half3(0,0,1);
  237. #endif
  238. outSurfaceData.emission = 0;
  239. }
  240. void InitializeInputData(VertexOutput input, half3 normalTS, half facing, out InputData inputData)
  241. {
  242. inputData = (InputData)0;
  243. #if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR)
  244. inputData.positionWS = input.positionWS;
  245. #endif
  246. half3 viewDirWS = SafeNormalize(input.viewDirWS);
  247. #if defined(_NORMALMAP) || !defined(_COTTONWOOL)
  248. normalTS.z *= facing;
  249. float sgn = input.tangentWS.w; // should be either +1 or -1
  250. float3 bitangent = sgn * cross(input.normalWS.xyz, input.tangentWS.xyz);
  251. inputData.normalWS = TransformTangentToWorld(normalTS, half3x3(input.tangentWS.xyz, bitangent, input.normalWS.xyz));
  252. #else
  253. inputData.normalWS = input.normalWS * facing;
  254. #endif
  255. inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
  256. viewDirWS = SafeNormalize(viewDirWS);
  257. inputData.viewDirectionWS = viewDirWS;
  258. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  259. inputData.shadowCoord = input.shadowCoord;
  260. #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  261. inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
  262. #else
  263. inputData.shadowCoord = float4(0, 0, 0, 0);
  264. #endif
  265. inputData.fogCoord = input.fogFactorAndVertexLight.x;
  266. inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
  267. inputData.bakedGI = SAMPLE_GI(input.lightmapUV, input.vertexSH, inputData.normalWS);
  268. //inputData.normalizedScreenSpaceUV = input.positionCS.xy;
  269. inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
  270. inputData.shadowMask = SAMPLE_SHADOWMASK(input.lightmapUV);
  271. }
  272. half4 LitPassFragment(VertexOutput input, half facing : VFACE) : SV_Target
  273. {
  274. UNITY_SETUP_INSTANCE_ID(input);
  275. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  276. // Get the surface description
  277. SurfaceDescription surfaceData;
  278. InitializeSurfaceData(input.uv, surfaceData);
  279. // Prepare surface data (like bring normal into world space and get missing inputs like gi)
  280. InputData inputData;
  281. InitializeInputData(input, surfaceData.normalTS, facing, inputData);
  282. #if defined(_RIMLIGHTING)
  283. half rim = saturate(1.0h - saturate( dot(inputData.normalWS, inputData.viewDirectionWS) ) );
  284. half power = _RimPower;
  285. UNITY_BRANCH if(_RimFrequency > 0 ) {
  286. half perPosition = lerp(0.0h, 1.0h, dot(1.0h, frac(UNITY_MATRIX_M._m03_m13_m23) * 2.0h - 1.0h ) * _RimPerPositionFrequency ) * 3.1416h;
  287. power = lerp(power, _RimMinPower, (1.0h + sin(_Time.y * _RimFrequency + perPosition) ) * 0.5h );
  288. }
  289. surfaceData.emission += pow(rim, power) * _RimColor.rgb * _RimColor.a;
  290. #endif
  291. #if !defined(_COTTONWOOL)
  292. float sgn = input.tangentWS.w; // should be either +1 or -1
  293. float3 bitangent = sgn * cross(input.normalWS.xyz, input.tangentWS.xyz);
  294. #endif
  295. // Apply lighting
  296. half4 color = LuxURPClothFragmentPBR(
  297. inputData,
  298. surfaceData.albedo,
  299. surfaceData.metallic,
  300. surfaceData.specular,
  301. surfaceData.smoothness,
  302. surfaceData.occlusion,
  303. surfaceData.emission,
  304. surfaceData.alpha,
  305. #if !defined(_COTTONWOOL)
  306. input.tangentWS.xyz,
  307. #else
  308. half3(0,0,0),
  309. #endif
  310. _Anisotropy,
  311. _SheenColor.rgb,
  312. #if defined(_SCATTERING)
  313. half4(surfaceData.translucency * _TranslucencyStrength, _TranslucencyPower, _ShadowStrength, _Distortion)
  314. #else
  315. half4(0,0,0,0)
  316. #endif
  317. );
  318. // Add fog
  319. color.rgb = MixFog(color.rgb, inputData.fogCoord);
  320. return color;
  321. }
  322. ENDHLSL
  323. }
  324. // Shadows -----------------------------------------------------
  325. Pass
  326. {
  327. Name "ShadowCaster"
  328. Tags{"LightMode" = "ShadowCaster"}
  329. ZWrite On
  330. ZTest LEqual
  331. ColorMask 0
  332. Cull[_Cull]
  333. HLSLPROGRAM
  334. // Required to compile gles 2.0 with standard srp library
  335. #pragma prefer_hlslcc gles
  336. #pragma exclude_renderers d3d11_9x
  337. #pragma target 2.0
  338. // -------------------------------------
  339. // Material Keywords
  340. #pragma shader_feature_local _ALPHATEST_ON // not per fragment!
  341. #pragma shader_feature_local _MASKMAP
  342. //--------------------------------------
  343. // GPU Instancing
  344. #pragma multi_compile_instancing
  345. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  346. #pragma vertex ShadowPassVertex
  347. #pragma fragment ShadowPassFragment
  348. // Include base inputs and all other needed "base" includes
  349. #include "Includes/Lux URP Cloth Inputs.hlsl"
  350. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
  351. // Shadow caster specific input
  352. float3 _LightDirection;
  353. VertexOutput ShadowPassVertex(VertexInput input)
  354. {
  355. VertexOutput output = (VertexOutput)0;
  356. UNITY_SETUP_INSTANCE_ID(input);
  357. UNITY_TRANSFER_INSTANCE_ID(input, output);
  358. #if defined(_ALPHATEST_ON) && defined(_MASKMAP)
  359. output.uv.xy = TRANSFORM_TEX(input.texcoord, _MaskMap);
  360. #endif
  361. float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
  362. float3 normalWS = TransformObjectToWorldDir(input.normalOS);
  363. output.positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS * _ShadowOffset, _LightDirection));
  364. #if UNITY_REVERSED_Z
  365. output.positionCS.z = min(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE);
  366. #else
  367. output.positionCS.z = max(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE);
  368. #endif
  369. return output;
  370. }
  371. half4 ShadowPassFragment(VertexOutput input) : SV_TARGET
  372. {
  373. UNITY_SETUP_INSTANCE_ID(input);
  374. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  375. #if defined(_ALPHATEST_ON) && defined(_MASKMAP)
  376. half mask = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, input.uv.xy).a;
  377. clip (mask - _Cutoff);
  378. #endif
  379. return 0;
  380. }
  381. ENDHLSL
  382. }
  383. // Depth -----------------------------------------------------
  384. Pass
  385. {
  386. Tags{"LightMode" = "DepthOnly"}
  387. ZWrite On
  388. ColorMask 0
  389. Cull Off
  390. HLSLPROGRAM
  391. // Required to compile gles 2.0 with standard srp library
  392. #pragma prefer_hlslcc gles
  393. #pragma exclude_renderers d3d11_9x
  394. #pragma target 2.0
  395. #pragma vertex DepthOnlyVertex
  396. #pragma fragment DepthOnlyFragment
  397. // -------------------------------------
  398. // Material Keywords
  399. #pragma shader_feature_local _ALPHATEST_ON // not per fragment!
  400. #pragma shader_feature_local _MASKMAP
  401. //--------------------------------------
  402. // GPU Instancing
  403. #pragma multi_compile_instancing
  404. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  405. #define DEPTHONLYPASS
  406. #include "Includes/Lux URP Cloth Inputs.hlsl"
  407. VertexOutput DepthOnlyVertex(VertexInput input)
  408. {
  409. VertexOutput output = (VertexOutput)0;
  410. UNITY_SETUP_INSTANCE_ID(input);
  411. UNITY_TRANSFER_INSTANCE_ID(input, output);
  412. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  413. #if defined(_ALPHATEST_ON) && defined(_MASKMAP)
  414. output.uv.xy = TRANSFORM_TEX(input.texcoord, _MaskMap);
  415. #endif
  416. output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
  417. return output;
  418. }
  419. half4 DepthOnlyFragment(VertexOutput input) : SV_TARGET
  420. {
  421. UNITY_SETUP_INSTANCE_ID(input);
  422. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  423. #if defined(_ALPHATEST_ON) && defined(_MASKMAP)
  424. half mask = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, input.uv.xy).a;
  425. clip (mask - _Cutoff);
  426. #endif
  427. return 0;
  428. }
  429. ENDHLSL
  430. }
  431. // Depth Normal ---------------------------------------------
  432. // This pass is used when drawing to a _CameraNormalsTexture texture
  433. Pass
  434. {
  435. Name "DepthNormals"
  436. Tags{"LightMode" = "DepthNormals"}
  437. ZWrite On
  438. Cull[_Cull]
  439. HLSLPROGRAM
  440. #pragma exclude_renderers d3d11_9x
  441. #pragma target 2.0
  442. #pragma vertex DepthNormalVertex
  443. #pragma fragment DepthNormalFragment
  444. // -------------------------------------
  445. // Material Keywords
  446. #pragma shader_feature_local _ALPHATEST_ON // not per fragment!
  447. #pragma shader_feature_local _MASKMAP
  448. //--------------------------------------
  449. // GPU Instancing
  450. #pragma multi_compile_instancing
  451. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  452. #define DEPTHNORMALPASS
  453. #include "Includes/Lux URP Cloth Inputs.hlsl"
  454. VertexOutput DepthNormalVertex(VertexInput input)
  455. {
  456. VertexOutput output = (VertexOutput)0;
  457. UNITY_SETUP_INSTANCE_ID(input);
  458. UNITY_TRANSFER_INSTANCE_ID(input, output);
  459. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  460. #if defined(_ALPHATEST_ON) && defined(_MASKMAP)
  461. output.uv.xy = TRANSFORM_TEX(input.texcoord, _MaskMap);
  462. #endif
  463. output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
  464. VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, float4(1,1,1,1)); //input.tangentOS);
  465. output.normalWS = NormalizeNormalPerVertex(normalInput.normalWS);
  466. return output;
  467. }
  468. half4 DepthNormalFragment(VertexOutput input) : SV_TARGET
  469. {
  470. UNITY_SETUP_INSTANCE_ID(input);
  471. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  472. #if defined(_ALPHATEST_ON) && defined(_MASKMAP)
  473. half mask = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, input.uv.xy).a;
  474. clip (mask - _Cutoff);
  475. #endif
  476. float3 normal = input.normalWS;
  477. return float4(PackNormalOctRectEncode(TransformWorldToViewDir(normal, true)), 0.0, 0.0);
  478. }
  479. ENDHLSL
  480. }
  481. // Meta -----------------------------------------------------
  482. Pass
  483. {
  484. Tags{"LightMode" = "Meta"}
  485. Cull Off
  486. HLSLPROGRAM
  487. // Required to compile gles 2.0 with standard srp library
  488. #pragma prefer_hlslcc gles
  489. #pragma vertex UniversalVertexMeta
  490. #pragma fragment UniversalFragmentMeta
  491. #define _SPECULAR_SETUP
  492. // First include all our custom stuff
  493. #include "Includes/Lux URP Cloth Inputs.hlsl"
  494. //--------------------------------------
  495. // Fragment shader and functions
  496. inline void InitializeStandardLitSurfaceData(float2 uv, out SurfaceData outSurfaceData)
  497. {
  498. half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
  499. outSurfaceData.alpha = 1;
  500. outSurfaceData.albedo = albedoAlpha.rgb * _BaseColor.rgb;
  501. outSurfaceData.metallic = 0;
  502. outSurfaceData.specular = _SpecColor.rgb;
  503. outSurfaceData.smoothness = _Smoothness;
  504. outSurfaceData.normalTS = half3(0,0,1);
  505. outSurfaceData.occlusion = 1;
  506. outSurfaceData.emission = 0;
  507. outSurfaceData.clearCoatMask = 0;
  508. outSurfaceData.clearCoatSmoothness = 0;
  509. }
  510. // Finally include the meta pass related stuff
  511. #include "Packages/com.unity.render-pipelines.universal/Shaders/LitMetaPass.hlsl"
  512. ENDHLSL
  513. }
  514. // End Passes -----------------------------------------------------
  515. }
  516. FallBack "Hidden/InternalErrorShader"
  517. CustomEditor "LuxURPUniversalCustomShaderGUI"
  518. }