Lux URP Flat Shaded.shader 26 KB

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