Lux URP Cloth STL.shader 24 KB

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