Lux URP Toon.shader 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. // Shader uses custom editor to set double sided GI
  2. // Needs _Culling to be set properly
  3. Shader "Lux URP/Toon HLSL"
  4. {
  5. Properties
  6. {
  7. [HeaderHelpLuxURPToon_URL(6zvjnfuiskj1)]
  8. [Header(Surface Options)]
  9. [Space(8)]
  10. [Enum(Opaque,0,Transparent,1)]
  11. _LuxSurface ("Surface Type", Float) = 0.0
  12. [Enum(Alpha,0,Premultiply,1,Additive,2,Multiply,3)]
  13. _LuxBlend (" Blending", Float) = 0.0
  14. [HideInInspector]
  15. _SrcBlend ("SrcBlend", Float) = 1.0
  16. [HideInInspector]
  17. _DstBlend ("DstBlend", Float) = 0.0
  18. //[HideInInspector]
  19. [Enum(Off,0,On,1)]
  20. _ZWrite ("ZWrite", Float) = 1.0
  21. [Enum(UnityEngine.Rendering.CompareFunction)]
  22. _ZTest ("ZTest", Int) = 4
  23. [Enum(UnityEngine.Rendering.CullMode)]
  24. _Cull ("Culling", Float) = 2
  25. [Toggle(_ALPHATEST_ON)]
  26. _AlphaClip ("Alpha Clipping", Float) = 0.0
  27. [LuxURPHelpDrawer]
  28. _Help ("Enabling Alpha Clipping needs you to enable and assign the Albedo (RGB) Alpha (A) Map as well.", Float) = 0.0
  29. _Cutoff (" Threshold", Range(0.0, 1.0)) = 0.5
  30. [Enum(Off,0,On,1)]_Coverage (" Alpha To Coverage", Float) = 0
  31. [Space(5)]
  32. [Toggle(_SSAO_ENABLED)]
  33. _ReceiveSSAO ("Receive SSAO", Float) = 1.0
  34. [Header(Toon Lighting)]
  35. [Space(8)]
  36. [IntRange] _Steps ("Steps", Range(1, 8)) = 1
  37. _DiffuseFallOff ("Diffuse Falloff", Range(0, 1)) = 0.01
  38. _DiffuseStep ("Diffuse Step", Range(-1, 1)) = 0
  39. [Space(5)]
  40. [KeywordEnum(Off, SmoothSampling, PointSampling)] _Ramp ("Ramp Mode", Float) = 0
  41. [NoScaleOffset]
  42. _GradientMap (" Ramp", 2D) = "white" {}
  43. _OcclusionStrength ("Occlusion", Range(0.0, 1.0)) = 1
  44. [Header(Advanced Toon Lighting)]
  45. [Space(8)]
  46. //[Toggle(_COLORIZEMAIN)]
  47. _ColorizedShadowsMain ("Colorize Main Light", Range(0, 1)) = 0.0
  48. //[Toggle(_COLORIZEADD)]
  49. _ColorizedShadowsAdd ("Colorize Add Lights", Range(0, 1)) = 0.0
  50. _LightColorContribution ("Light Color Contribution", Range(0, 1)) = 1
  51. _AddLightFallOff ("Light Falloff", Range(0.0001, 1)) = 1
  52. [Header(Specular Toon Lighting)]
  53. [Space(8)]
  54. [ToggleOff]
  55. _SpecularHighlights ("Enable Specular Highlights", Float) = 1.0
  56. [Toggle(_ANISOTROPIC)]
  57. _Anisotropic (" Anisotropic Specular", Float) = 0.0
  58. _Anisotropy (" Anisotropy", Range(-1.0, 1.0)) = 0.0
  59. [Space(5)]
  60. [Toggle]
  61. _EnergyConservation (" EnergyConservation", Float) = 1
  62. [HDR] _SpecColor (" Specular", Color) = (0.2, 0.2, 0.2)
  63. [HDR] _SpecColor2nd (" Secondary Specular", Color) = (0.4, 0.4, 0.4)
  64. _Smoothness (" Smoothness", Range(0.0, 1.0)) = 0.5
  65. _SpecularStep (" Specular Step", Range(0.3, 0.5)) = 0.45
  66. _SpecularFallOff (" Specular Falloff", Range(0, 1)) = 0.01
  67. [Header(Toon Rim)]
  68. [Space(8)]
  69. [Toggle(_TOONRIM)]
  70. _EnableToonRim ("Enable Toon Rim", Float) = 0.0
  71. [HDR] _ToonRimColor (" Rim Color", Color) = (1, 1, 1, 1)
  72. _ToonRimPower (" Rim Power", Range(0, 1)) = 0.5
  73. _ToonRimFallOff (" Rim Falloff", Range(0, 1)) = 1
  74. _ToonRimAttenuation (" Rim Attenuation", Range(0, 1)) = 0
  75. [Header(Toon Shadows)]
  76. [Space(8)]
  77. [ToggleOff(_RECEIVE_SHADOWS_OFF)]
  78. _ReceiveShadows ("Receive Shadows", Float) = 1.0
  79. _ShadowOffset (" Shadow Offset", Float) = 1.0
  80. _ShadowFallOff (" Shadow Falloff", Range(0.5, 1)) = 0.75
  81. _ShadoBiasDirectional (" Shadow Bias Directional", Range(0, 1)) = 0
  82. _ShadowBiasAdditional (" Shadow Bias Additional", Range(0, 1)) = 0
  83. [Header(Surface Inputs)]
  84. [Space(8)]
  85. [MainColor]
  86. _BaseColor ("Color (RGB) Alpha (A)", Color) = (1,1,1,1)
  87. _ShadedBaseColor ("Shaded Color (RGB)", Color) = (0,0,0,1)
  88. [Space(5)]
  89. [KeywordEnum(Off, One, Two)] _TexMode ("TextureMode", Float) = 0
  90. [MainTexture]
  91. _BaseMap ("Albedo (RGB) Alpha (A)", 2D) = "white" {}
  92. [NoScaleOffset]
  93. _ShadedBaseMap ("Shaded Albedo (RGB)", 2D) = "white" {}
  94. [Space(5)]
  95. [Toggle(_MASKMAP)]
  96. _EnableMaskMap ("Enable Mask Map", Float) = 0.0
  97. [NoScaleOffset]
  98. _MaskMap (" Emission (R) Specular (G) Occlusion (B) Smoothness (A)", 2D) = "white" {}
  99. [HDR] _EmissionColor (" Emission Color", Color) = (0,0,0,0)
  100. [Space(5)]
  101. [Toggle(_NORMALMAP)]
  102. _ApplyNormal ("Enable Normal Map", Float) = 0.0
  103. [NoScaleOffset]
  104. _BumpMap (" Normal Map", 2D) = "bump" {}
  105. _BumpScale (" Normal Scale", Float) = 1.0
  106. // Lux URP standards
  107. [Header(Rim Lighting)]
  108. [Space(8)]
  109. [Toggle(_RIMLIGHTING)]
  110. _Rim ("Enable Rim Lighting", Float) = 0
  111. [HDR] _RimColor ("Rim Color", Color) = (0.5,0.5,0.5,1)
  112. _RimPower ("Rim Power", Float) = 2
  113. _RimFrequency ("Rim Frequency", Float) = 0
  114. _RimMinPower (" Rim Min Power", Float) = 1
  115. _RimPerPositionFrequency (" Rim Per Position Frequency", Range(0.0, 1.0)) = 1
  116. [Header(Stencil)]
  117. [Space(8)]
  118. [IntRange] _Stencil ("Stencil Reference", Range (0, 255)) = 0
  119. [IntRange] _ReadMask (" Read Mask", Range (0, 255)) = 255
  120. [IntRange] _WriteMask (" Write Mask", Range (0, 255)) = 255
  121. [Enum(UnityEngine.Rendering.CompareFunction)]
  122. _StencilComp ("Stencil Comparison", Int) = 8 // always – terrain should be the first thing being rendered anyway
  123. [Enum(UnityEngine.Rendering.StencilOp)]
  124. _StencilOp ("Stencil Operation", Int) = 0 // 0 = keep, 2 = replace
  125. [Enum(UnityEngine.Rendering.StencilOp)]
  126. _StencilFail ("Stencil Fail Op", Int) = 0 // 0 = keep
  127. [Enum(UnityEngine.Rendering.StencilOp)]
  128. _StencilZFail ("Stencil ZFail Op", Int) = 0 // 0 = keep
  129. [Header(Advanced)]
  130. [Space(8)]
  131. [ToggleOff]
  132. _EnvironmentReflections ("Environment Reflections", Float) = 0.0
  133. [Header(Render Queue)]
  134. [Space(8)]
  135. [IntRange] _QueueOffset ("Queue Offset", Range(-50, 50)) = 0
  136. // Needed by the inspector
  137. [HideInInspector] _Culling ("Culling", Float) = 0.0
  138. [HideInInspector] _AlphaFromMaskMap ("AlphaFromMaskMap", Float) = 1.0
  139. // Lightmapper and outline selection shader need _MainTex, _Color and _Cutoff
  140. [HideInInspector] _MainTex ("Albedo", 2D) = "white" {}
  141. [HideInInspector] _Color ("Color", Color) = (1,1,1,1)
  142. }
  143. SubShader
  144. {
  145. Tags
  146. {
  147. "RenderPipeline" = "UniversalPipeline"
  148. "RenderType" = "Opaque"
  149. "Queue" = "Geometry"
  150. }
  151. LOD 100
  152. // /////////////////////////////////////////////////////
  153. // Regular Passes
  154. Pass
  155. {
  156. Name "ForwardLit"
  157. Tags{"LightMode" = "UniversalForward"}
  158. Stencil {
  159. Ref [_Stencil]
  160. ReadMask [_ReadMask]
  161. WriteMask [_WriteMask]
  162. Comp [_StencilComp]
  163. Pass [_StencilOp]
  164. Fail [_StencilFail]
  165. ZFail [_StencilZFail]
  166. }
  167. Blend [_SrcBlend][_DstBlend]
  168. ZWrite [_ZWrite]
  169. ZTest [_ZTest]
  170. Cull [_Cull]
  171. AlphaToMask [_Coverage]
  172. HLSLPROGRAM
  173. // Required to compile gles 2.0 with standard SRP library
  174. #pragma prefer_hlslcc gles
  175. #pragma exclude_renderers d3d11_9x
  176. // Shader target needs to be 3.0 due to tex2Dlod in the vertex shader or VFACE
  177. #pragma target 3.0
  178. // -------------------------------------
  179. // Material Keywords
  180. #define _SPECULAR_SETUP 1
  181. #pragma shader_feature_local _ALPHATEST_ON
  182. #pragma shader_feature_local_fragment _COLORIZEMAIN
  183. #pragma shader_feature_local_fragment _COLORIZEADD
  184. #pragma shader_feature_local_fragment _TOONRIM
  185. //#pragma shader_feature_local GRADIENT_ON
  186. #pragma shader_feature_local _ _RAMP_SMOOTHSAMPLING _RAMP_POINTSAMPLING
  187. #pragma shader_feature_local _ _TEXMODE_ONE _TEXMODE_TWO
  188. #pragma shader_feature_local_fragment _SSAO_ENABLED
  189. #pragma shader_feature_local _MASKMAP
  190. #pragma shader_feature_local _NORMALMAP
  191. #pragma shader_feature_local_fragment _RIMLIGHTING
  192. #pragma shader_feature_local_fragment _SPECULARHIGHLIGHTS_OFF
  193. #pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF
  194. #pragma shader_feature_local _RECEIVE_SHADOWS_OFF
  195. #pragma shader_feature_local _ANISOTROPIC // Also affects vertex shader! (vertex input)
  196. // -------------------------------------
  197. // Universal Pipeline keywords
  198. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
  199. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
  200. #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  201. #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
  202. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  203. #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
  204. #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
  205. #pragma multi_compile _ SHADOWS_SHADOWMASK
  206. // -------------------------------------
  207. // Unity defined keywords
  208. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  209. #pragma multi_compile _ LIGHTMAP_ON
  210. #pragma multi_compile_fog
  211. //--------------------------------------
  212. // GPU Instancing
  213. #pragma multi_compile_instancing
  214. // Include base inputs and all other needed "base" includes
  215. #include "Includes/Lux URP Toon Inputs.hlsl"
  216. #pragma vertex LitPassVertex
  217. #pragma fragment LitPassFragment
  218. //--------------------------------------
  219. // Vertex shader
  220. VertexOutput LitPassVertex(VertexInput input)
  221. {
  222. VertexOutput output = (VertexOutput)0;
  223. UNITY_SETUP_INSTANCE_ID(input);
  224. UNITY_TRANSFER_INSTANCE_ID(input, output);
  225. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  226. VertexPositionInputs vertexInput; //
  227. vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
  228. #if defined(_NORMALMAP) || (defined(_ANISOTROPIC) && !defined(_SPECULARHIGHLIGHTS_OFF))
  229. VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
  230. #else
  231. VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, float4(0,0,0,0));
  232. #endif
  233. float3 viewDirWS = GetCameraPositionWS() - vertexInput.positionWS;
  234. half3 vertexLight = VertexLighting(vertexInput.positionWS, normalInput.normalWS);
  235. half fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
  236. #if defined(_TEXMODE_ONE) || defined(_TEXMODE_TWO) || defined(_TEXMODE_TWO) || defined(_NORMALMAP) || defined(_MASKMAP)
  237. output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);
  238. #endif
  239. output.normalWS = normalInput.normalWS;
  240. output.viewDirWS = viewDirWS;
  241. #if defined (_NORMALMAP) || (defined(_ANISOTROPIC) && !defined(_SPECULARHIGHLIGHTS_OFF))
  242. float sign = input.tangentOS.w * GetOddNegativeScale();
  243. output.tangentWS = float4(normalInput.tangentWS.xyz, sign);
  244. #endif
  245. OUTPUT_LIGHTMAP_UV(input.lightmapUV, unity_LightmapST, output.lightmapUV);
  246. OUTPUT_SH(output.normalWS.xyz, output.vertexSH);
  247. output.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
  248. #if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR)
  249. output.positionWS = vertexInput.positionWS;
  250. #endif
  251. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  252. output.shadowCoord = GetShadowCoord(vertexInput);
  253. #endif
  254. output.positionCS = vertexInput.positionCS;
  255. return output;
  256. }
  257. //--------------------------------------
  258. // Fragment shader and functions
  259. inline void InitializeSurfaceData(
  260. float2 uv,
  261. out SurfaceDescription outSurfaceData)
  262. {
  263. #if defined(_TEXMODE_ONE) || defined(_TEXMODE_TWO)
  264. half4 albedoAlpha = SampleAlbedoAlpha(uv.xy, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
  265. albedoAlpha *= _BaseColor;
  266. #else
  267. half4 albedoAlpha = _BaseColor;
  268. #endif
  269. #if defined(_ALPHATEST_ON) && (defined(_TEXMODE_ONE) || defined(_TEXMODE_TWO))
  270. outSurfaceData.alpha = Alpha(albedoAlpha.a, 1, _Cutoff);
  271. #else
  272. outSurfaceData.alpha = albedoAlpha.a;
  273. #endif
  274. #if defined(_TEXMODE_TWO)
  275. half3 albedoShaded = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_ShadedBaseMap, sampler_BaseMap)).rgb;
  276. #else
  277. #if defined(_TEXMODE_ONE)
  278. half3 albedoShaded = albedoAlpha.rgb;
  279. #else
  280. half3 albedoShaded = half3(1,1,1);
  281. #endif
  282. #endif
  283. #if defined(_MASKMAP)
  284. half4 maskSample = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, uv);
  285. outSurfaceData.occlusion = lerp(1.0h, maskSample.b, _OcclusionStrength);
  286. outSurfaceData.smoothness = maskSample.a * _Smoothness;
  287. outSurfaceData.specular = lerp(_SpecColor2nd, _SpecColor, maskSample.g);
  288. outSurfaceData.emission = maskSample.r * _EmissionColor;
  289. #else
  290. outSurfaceData.occlusion = _OcclusionStrength;
  291. outSurfaceData.smoothness = _Smoothness;
  292. outSurfaceData.specular = _SpecColor.rgb;
  293. outSurfaceData.emission = 0;
  294. #endif
  295. outSurfaceData.albedo = albedoAlpha.rgb;
  296. outSurfaceData.albedoShaded = albedoShaded * _ShadedBaseColor.rgb;
  297. outSurfaceData.metallic = 0;
  298. // Normal Map
  299. #if defined (_NORMALMAP)
  300. outSurfaceData.normalTS = SampleNormal(uv.xy, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap), _BumpScale);
  301. #else
  302. outSurfaceData.normalTS = half3(0,0,1);
  303. #endif
  304. }
  305. void InitializeInputData(VertexOutput input, half3 normalTS, half facing, out InputData inputData)
  306. {
  307. inputData = (InputData)0;
  308. #if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR)
  309. inputData.positionWS = input.positionWS;
  310. #endif
  311. half3 viewDirWS = SafeNormalize(input.viewDirWS);
  312. #if defined(_NORMALMAP)
  313. normalTS.z *= facing;
  314. float sgn = input.tangentWS.w; // should be either +1 or -1
  315. float3 bitangent = sgn * cross(input.normalWS.xyz, input.tangentWS.xyz);
  316. inputData.normalWS = TransformTangentToWorld(normalTS, half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz));
  317. #else
  318. inputData.normalWS = input.normalWS * facing;
  319. #endif
  320. // Not normalized normals cause uggly specular highlights on mobile. So we always normalize.
  321. #if !defined(_SPECULARHIGHLIGHTS_OFF)
  322. inputData.normalWS = normalize(inputData.normalWS);
  323. #else
  324. inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
  325. #endif
  326. inputData.viewDirectionWS = viewDirWS;
  327. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  328. inputData.shadowCoord = input.shadowCoord;
  329. #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  330. inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
  331. #else
  332. inputData.shadowCoord = float4(0, 0, 0, 0);
  333. #endif
  334. inputData.fogCoord = input.fogFactorAndVertexLight.x;
  335. inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
  336. inputData.bakedGI = SAMPLE_GI(input.lightmapUV, input.vertexSH, inputData.normalWS);
  337. //inputData.normalizedScreenSpaceUV = input.positionCS.xy;
  338. inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
  339. inputData.shadowMask = SAMPLE_SHADOWMASK(input.lightmapUV);
  340. }
  341. half4 LitPassFragment(VertexOutput input, half facing : VFACE) : SV_Target
  342. {
  343. UNITY_SETUP_INSTANCE_ID(input);
  344. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  345. // Get the surface description
  346. SurfaceDescription surfaceData;
  347. #if defined(_TEXMODE_ONE) || defined(_TEXMODE_TWO) || defined(_TEXMODE_TWO) || defined(_NORMALMAP) || defined(_MASKMAP)
  348. InitializeSurfaceData(input.uv, surfaceData);
  349. #else
  350. InitializeSurfaceData(float2(0,0), surfaceData);
  351. #endif
  352. // Prepare surface data (like bring normal into world space and get missing inputs like gi)
  353. InputData inputData;
  354. InitializeInputData(input, surfaceData.normalTS, facing, inputData);
  355. #if defined(_RIMLIGHTING)
  356. half rim = saturate(1.0h - saturate( dot(inputData.normalWS, inputData.viewDirectionWS) ) );
  357. half power = _RimPower;
  358. UNITY_BRANCH if(_RimFrequency > 0 ) {
  359. half perPosition = lerp(0.0h, 1.0h, dot(1.0h, frac(UNITY_MATRIX_M._m03_m13_m23) * 2.0h - 1.0h ) * _RimPerPositionFrequency ) * 3.1416h;
  360. power = lerp(power, _RimMinPower, (1.0h + sin(_Time.y * _RimFrequency + perPosition) ) * 0.5h );
  361. }
  362. surfaceData.emission += pow(rim, power) * _RimColor.rgb * _RimColor.a;
  363. #endif
  364. // Apply lighting
  365. half4 color = LuxURPToonFragmentPBR(
  366. inputData,
  367. #if defined(_ANISOTROPIC) && !defined(_SPECULARHIGHLIGHTS_OFF)
  368. input.tangentWS,
  369. _Anisotropy,
  370. #endif
  371. surfaceData.albedo,
  372. surfaceData.albedoShaded,
  373. surfaceData.metallic,
  374. surfaceData.specular,
  375. _Steps,
  376. _DiffuseStep,
  377. _DiffuseFallOff,
  378. _EnergyConservation,
  379. _SpecularStep,
  380. _SpecularFallOff,
  381. _ColorizedShadowsMain,
  382. _ColorizedShadowsAdd,
  383. _LightColorContribution,
  384. _AddLightFallOff,
  385. _ShadowFallOff,
  386. _ShadoBiasDirectional,
  387. _ShadowBiasAdditional,
  388. _ToonRimColor.rgb,
  389. _ToonRimPower,
  390. _ToonRimFallOff,
  391. _ToonRimAttenuation,
  392. surfaceData.smoothness,
  393. surfaceData.occlusion,
  394. surfaceData.emission,
  395. surfaceData.alpha
  396. );
  397. // Add fog
  398. color.rgb = MixFog(color.rgb, inputData.fogCoord);
  399. return color;
  400. }
  401. ENDHLSL
  402. }
  403. // Shadows -----------------------------------------------------
  404. Pass
  405. {
  406. Name "ShadowCaster"
  407. Tags{"LightMode" = "ShadowCaster"}
  408. ZWrite On
  409. ZTest LEqual
  410. Cull[_Cull]
  411. HLSLPROGRAM
  412. // Required to compile gles 2.0 with standard srp library
  413. #pragma prefer_hlslcc gles
  414. #pragma exclude_renderers d3d11_9x
  415. #pragma target 2.0
  416. // -------------------------------------
  417. // Material Keywords
  418. #pragma shader_feature_local _ALPHATEST_ON
  419. #pragma shader_feature_local _ _TEXMODE_ONE _TEXMODE_TWO
  420. //--------------------------------------
  421. // GPU Instancing
  422. #pragma multi_compile_instancing
  423. #pragma vertex ShadowPassVertex
  424. #pragma fragment ShadowPassFragment
  425. // Include base inputs and all other needed "base" includes
  426. #include "Includes/Lux URP Toon Inputs.hlsl"
  427. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
  428. // Shadow caster specific input
  429. float3 _LightDirection;
  430. VertexOutput ShadowPassVertex(VertexInput input)
  431. {
  432. VertexOutput output = (VertexOutput)0;
  433. UNITY_SETUP_INSTANCE_ID(input);
  434. UNITY_TRANSFER_INSTANCE_ID(input, output);
  435. #if defined(_ALPHATEST_ON) && (defined(_TEXMODE_ONE) || defined(_TEXMODE_TWO))
  436. output.uv.xy = TRANSFORM_TEX(input.texcoord, _BaseMap);
  437. #endif
  438. float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
  439. float3 normalWS = TransformObjectToWorldDir(input.normalOS);
  440. output.positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS * _ShadowOffset, _LightDirection));
  441. #if UNITY_REVERSED_Z
  442. output.positionCS.z = min(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE);
  443. #else
  444. output.positionCS.z = max(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE);
  445. #endif
  446. return output;
  447. }
  448. half4 ShadowPassFragment(VertexOutput input) : SV_TARGET
  449. {
  450. UNITY_SETUP_INSTANCE_ID(input);
  451. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  452. #if defined(_ALPHATEST_ON) && (defined(_TEXMODE_ONE) || defined(_TEXMODE_TWO))
  453. half mask = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv).a;
  454. clip (mask - _Cutoff);
  455. #endif
  456. return 0;
  457. }
  458. ENDHLSL
  459. }
  460. // Depth -----------------------------------------------------
  461. Pass
  462. {
  463. Tags{"LightMode" = "DepthOnly"}
  464. ZWrite On
  465. ColorMask 0
  466. Cull[_Cull]
  467. HLSLPROGRAM
  468. // Required to compile gles 2.0 with standard srp library
  469. #pragma prefer_hlslcc gles
  470. #pragma exclude_renderers d3d11_9x
  471. #pragma target 2.0
  472. #pragma vertex DepthOnlyVertex
  473. #pragma fragment DepthOnlyFragment
  474. // -------------------------------------
  475. // Material Keywords
  476. #pragma shader_feature_local _ALPHATEST_ON
  477. #pragma shader_feature_local _ _TEXMODE_ONE _TEXMODE_TWO
  478. //--------------------------------------
  479. // GPU Instancing
  480. #pragma multi_compile_instancing
  481. #define DEPTHONLYPASS
  482. #include "Includes/Lux URP Toon Inputs.hlsl"
  483. VertexOutput DepthOnlyVertex(VertexInput input)
  484. {
  485. VertexOutput output = (VertexOutput)0;
  486. UNITY_SETUP_INSTANCE_ID(input);
  487. UNITY_TRANSFER_INSTANCE_ID(input, output);
  488. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  489. #if defined(_ALPHATEST_ON) && (defined(_TEXMODE_ONE) || defined(_TEXMODE_TWO))
  490. output.uv.xy = TRANSFORM_TEX(input.texcoord, _BaseMap);
  491. #endif
  492. output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
  493. return output;
  494. }
  495. half4 DepthOnlyFragment(VertexOutput input) : SV_TARGET
  496. {
  497. UNITY_SETUP_INSTANCE_ID(input);
  498. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  499. #if defined(_ALPHATEST_ON) && (defined(_TEXMODE_ONE) || defined(_TEXMODE_TWO))
  500. half mask = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv.xy).a;
  501. clip (mask - _Cutoff);
  502. #endif
  503. return 0;
  504. }
  505. ENDHLSL
  506. }
  507. // Depth Normals -----------------------------------------------------
  508. Pass
  509. {
  510. Name "DepthNormals"
  511. Tags{"LightMode" = "DepthNormals"}
  512. ZWrite On
  513. Cull[_Cull]
  514. HLSLPROGRAM
  515. // Required to compile gles 2.0 with standard SRP library
  516. #pragma prefer_hlslcc gles
  517. #pragma exclude_renderers d3d11_9x
  518. #pragma target 2.0
  519. #pragma vertex DepthNormalsVertex
  520. #pragma fragment DepthNormalsFragment
  521. // -------------------------------------
  522. // Material Keywords
  523. #pragma shader_feature_local _NORMALMAP
  524. #pragma shader_feature_local _ALPHATEST_ON
  525. #pragma shader_feature_local _ _TEXMODE_ONE _TEXMODE_TWO
  526. //--------------------------------------
  527. // GPU Instancing
  528. #pragma multi_compile_instancing
  529. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  530. //#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
  531. #include "Includes/Lux URP Toon Inputs.hlsl"
  532. #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthNormalsPass.hlsl"
  533. ENDHLSL
  534. }
  535. // Meta -----------------------------------------------------
  536. Pass
  537. {
  538. Tags{"LightMode" = "Meta"}
  539. Cull Off
  540. HLSLPROGRAM
  541. // Required to compile gles 2.0 with standard srp library
  542. #pragma prefer_hlslcc gles
  543. #pragma vertex UniversalVertexMeta
  544. #pragma fragment UniversalFragmentMeta
  545. #define _SPECULAR_SETUP
  546. // First include all our custom stuff
  547. #include "Includes/Lux URP Toon Inputs.hlsl"
  548. //--------------------------------------
  549. // Fragment shader and functions
  550. inline void InitializeStandardLitSurfaceData(float2 uv, out SurfaceData outSurfaceData)
  551. {
  552. half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
  553. outSurfaceData.alpha = Alpha(albedoAlpha.a, half4(1.0h, 1.0h, 1.0h, 1.0h), _Cutoff);
  554. outSurfaceData.albedo = albedoAlpha.rgb * _BaseColor.rgb;
  555. outSurfaceData.metallic = 0;
  556. outSurfaceData.specular = _SpecColor.rgb;
  557. outSurfaceData.smoothness = _Smoothness;
  558. outSurfaceData.normalTS = half3(0,0,1);
  559. outSurfaceData.occlusion = 1;
  560. outSurfaceData.emission = 0;
  561. // UPR 10+
  562. //#if VERSION_GREATER_EQUAL(10, 0)
  563. outSurfaceData.clearCoatMask = 0;
  564. outSurfaceData.clearCoatSmoothness = 0;
  565. //#endif
  566. }
  567. // Finally include the meta pass related stuff
  568. #include "Packages/com.unity.render-pipelines.universal/Shaders/LitMetaPass.hlsl"
  569. ENDHLSL
  570. }
  571. // End Passes -----------------------------------------------------
  572. }
  573. FallBack "Hidden/InternalErrorShader"
  574. CustomEditor "LuxURPUniversalCustomShaderGUI"
  575. }