Art Tools.shader 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Licensed under the MIT License.
  3. Shader "Art Tools/Standard"
  4. {
  5. Properties
  6. {
  7. // Main maps.
  8. _Color("Color", Color) = (1.0, 1.0, 1.0, 1.0)
  9. _MainTex("Albedo", 2D) = "white" {}
  10. [Enum(AlbedoAlphaMode)] _AlbedoAlphaMode("Albedo Alpha Mode", Float) = 0 // "Transparency"
  11. [Toggle] _AlbedoAssignedAtRuntime("Albedo Assigned at Runtime", Float) = 0.0
  12. _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
  13. _Metallic("Metallic", Range(0.0, 1.0)) = 0.0
  14. _Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5
  15. [Toggle(_CHANNEL_MAP)] _EnableChannelMap("Enable Channel Map", Float) = 0.0
  16. [NoScaleOffset] _ChannelMap("Channel Map", 2D) = "white" {}
  17. [Toggle(_NORMAL_MAP)] _EnableNormalMap("Enable Normal Map", Float) = 0.0
  18. [NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {}
  19. _NormalMapScale("Scale", Float) = 1.0
  20. [Toggle(_EMISSION)] _EnableEmission("Enable Emission", Float) = 0.0
  21. [HDR]_EmissiveColor("Emissive Color", Color) = (0.0, 0.0, 0.0, 1.0)
  22. [Toggle(_TRIPLANAR_MAPPING)] _EnableTriplanarMapping("Triplanar Mapping", Float) = 0.0
  23. [Toggle(_LOCAL_SPACE_TRIPLANAR_MAPPING)] _EnableLocalSpaceTriplanarMapping("Local Space", Float) = 0.0
  24. _TriplanarMappingBlendSharpness("Blend Sharpness", Range(1.0, 16.0)) = 4.0
  25. // Rendering options.
  26. [Toggle(_DIRECTIONAL_LIGHT)] _DirectionalLight("Directional Light", Float) = 1.0
  27. [Toggle(_SPECULAR_HIGHLIGHTS)] _SpecularHighlights("Specular Highlights", Float) = 1.0
  28. [Toggle(_SPHERICAL_HARMONICS)] _SphericalHarmonics("Spherical Harmonics", Float) = 0.0
  29. [Toggle(_REFLECTIONS)] _Reflections("Reflections", Float) = 0.0
  30. [Toggle(_REFRACTION)] _Refraction("Refraction", Float) = 0.0
  31. _RefractiveIndex("Refractive Index", Range(0.0, 3.0)) = 0.0
  32. [Toggle(_RIM_LIGHT)] _RimLight("Rim Light", Float) = 0.0
  33. _RimColor("Rim Color", Color) = (0.5, 0.5, 0.5, 1.0)
  34. _RimPower("Rim Power", Range(0.0, 8.0)) = 0.25
  35. [Toggle(_VERTEX_COLORS)] _VertexColors("Vertex Colors", Float) = 0.0
  36. [Toggle(_VERTEX_EXTRUSION)] _VertexExtrusion("Vertex Extrusion", Float) = 0.0
  37. _VertexExtrusionValue("Vertex Extrusion Value", Float) = 0.0
  38. _BlendedClippingWidth("Blended Clipping With", Range(0.0, 10.0)) = 1.0
  39. [Toggle(_CLIPPING_BORDER)] _ClippingBorder("Clipping Border", Float) = 0.0
  40. _ClippingBorderWidth("Clipping Border Width", Range(0.0, 1.0)) = 0.025
  41. _ClippingBorderColor("Clipping Border Color", Color) = (1.0, 0.2, 0.0, 1.0)
  42. [Toggle(_NEAR_PLANE_FADE)] _NearPlaneFade("Near Plane Fade", Float) = 0.0
  43. [Toggle(_NEAR_LIGHT_FADE)] _NearLightFade("Near Light Fade", Float) = 0.0
  44. _FadeBeginDistance("Fade Begin Distance", Range(0.0, 10.0)) = 0.85
  45. _FadeCompleteDistance("Fade Complete Distance", Range(0.0, 10.0)) = 0.5
  46. _FadeMinValue("Fade Min Value", Range(0.0, 1.0)) = 0.0
  47. // Fluent options.
  48. [Toggle(_HOVER_LIGHT)] _HoverLight("Hover Light", Float) = 1.0
  49. [Toggle(_HOVER_COLOR_OVERRIDE)] _EnableHoverColorOverride("Hover Color Override", Float) = 0.0
  50. _HoverColorOverride("Hover Color Override", Color) = (1.0, 1.0, 1.0, 1.0)
  51. [Toggle(_PROXIMITY_LIGHT)] _ProximityLight("Proximity Light", Float) = 0.0
  52. [Toggle(_PROXIMITY_LIGHT_COLOR_OVERRIDE)] _EnableProximityLightColorOverride("Proximity Light Color Override", Float) = 0.0
  53. [HDR]_ProximityLightCenterColorOverride("Proximity Light Center Color Override", Color) = (1.0, 0.0, 0.0, 0.0)
  54. [HDR]_ProximityLightMiddleColorOverride("Proximity Light Middle Color Override", Color) = (0.0, 1.0, 0.0, 0.5)
  55. [HDR]_ProximityLightOuterColorOverride("Proximity Light Outer Color Override", Color) = (0.0, 0.0, 1.0, 1.0)
  56. [Toggle(_PROXIMITY_LIGHT_SUBTRACTIVE)] _ProximityLightSubtractive("Proximity Light Subtractive", Float) = 0.0
  57. [Toggle(_PROXIMITY_LIGHT_TWO_SIDED)] _ProximityLightTwoSided("Proximity Light Two Sided", Float) = 0.0
  58. _FluentLightIntensity("Fluent Light Intensity", Range(0.0, 1.0)) = 1.0
  59. [Toggle(_ROUND_CORNERS)] _RoundCorners("Round Corners", Float) = 0.0
  60. _RoundCornerRadius("Round Corner Radius", Range(0.0, 0.5)) = 0.25
  61. _RoundCornerMargin("Round Corner Margin", Range(0.0, 0.5)) = 0.01
  62. [Toggle(_BORDER_LIGHT)] _BorderLight("Border Light", Float) = 0.0
  63. [Toggle(_BORDER_LIGHT_USES_HOVER_COLOR)] _BorderLightUsesHoverColor("Border Light Uses Hover Color", Float) = 0.0
  64. [Toggle(_BORDER_LIGHT_REPLACES_ALBEDO)] _BorderLightReplacesAlbedo("Border Light Replaces Albedo", Float) = 0.0
  65. [Toggle(_BORDER_LIGHT_OPAQUE)] _BorderLightOpaque("Border Light Opaque", Float) = 0.0
  66. _BorderWidth("Border Width", Range(0.0, 1.0)) = 0.1
  67. _BorderMinValue("Border Min Value", Range(0.0, 1.0)) = 0.1
  68. _EdgeSmoothingValue("Edge Smoothing Value", Range(0.0, 0.2)) = 0.002
  69. _BorderLightOpaqueAlpha("Border Light Opaque Alpha", Range(0.0, 1.0)) = 1.0
  70. [Toggle(_INNER_GLOW)] _InnerGlow("Inner Glow", Float) = 0.0
  71. _InnerGlowColor("Inner Glow Color (RGB) and Intensity (A)", Color) = (1.0, 1.0, 1.0, 0.75)
  72. _InnerGlowPower("Inner Glow Power", Range(2.0, 32.0)) = 4.0
  73. [Toggle(_IRIDESCENCE)] _Iridescence("Iridescence", Float) = 0.0
  74. [NoScaleOffset] _IridescentSpectrumMap("Iridescent Spectrum Map", 2D) = "white" {}
  75. _IridescenceIntensity("Iridescence Intensity", Range(0.0, 1.0)) = 0.5
  76. _IridescenceThreshold("Iridescence Threshold", Range(0.0, 1.0)) = 0.05
  77. _IridescenceAngle("Iridescence Angle", Range(-0.78, 0.78)) = -0.78
  78. [Toggle(_ENVIRONMENT_COLORING)] _EnvironmentColoring("Environment Coloring", Float) = 0.0
  79. _EnvironmentColorThreshold("Environment Color Threshold", Range(0.0, 3.0)) = 1.5
  80. _EnvironmentColorIntensity("Environment Color Intensity", Range(0.0, 1.0)) = 0.5
  81. _EnvironmentColorX("Environment Color X (RGB)", Color) = (1.0, 0.0, 0.0, 1.0)
  82. _EnvironmentColorY("Environment Color Y (RGB)", Color) = (0.0, 1.0, 0.0, 1.0)
  83. _EnvironmentColorZ("Environment Color Z (RGB)", Color) = (0.0, 0.0, 1.0, 1.0)
  84. // Advanced options.
  85. [Enum(RenderingMode)] _Mode("Rendering Mode", Float) = 0 // "Opaque"
  86. [Enum(CustomRenderingMode)] _CustomMode("Mode", Float) = 0 // "Opaque"
  87. [Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend("Source Blend", Float) = 1 // "One"
  88. [Enum(UnityEngine.Rendering.BlendMode)] _DstBlend("Destination Blend", Float) = 0 // "Zero"
  89. [Enum(UnityEngine.Rendering.BlendOp)] _BlendOp("Blend Operation", Float) = 0 // "Add"
  90. [Enum(UnityEngine.Rendering.CompareFunction)] _ZTest("Depth Test", Float) = 4 // "LessEqual"
  91. [Enum(DepthWrite)] _ZWrite("Depth Write", Float) = 1 // "On"
  92. _ZOffsetFactor("Depth Offset Factor", Float) = 0 // "Zero"
  93. _ZOffsetUnits("Depth Offset Units", Float) = 0 // "Zero"
  94. [Enum(UnityEngine.Rendering.ColorWriteMask)] _ColorWriteMask("Color Write Mask", Float) = 15 // "All"
  95. [Enum(UnityEngine.Rendering.CullMode)] _CullMode("Cull Mode", Float) = 2 // "Back"
  96. _RenderQueueOverride("Render Queue Override", Range(-1.0, 5000)) = -1
  97. [Toggle(_INSTANCED_COLOR)] _InstancedColor("Instanced Color", Float) = 0.0
  98. [Toggle(_IGNORE_Z_SCALE)] _IgnoreZScale("Ignore Z Scale", Float) = 0.0
  99. [Toggle(_STENCIL)] _Stencil("Enable Stencil Testing", Float) = 0.0
  100. _StencilReference("Stencil Reference", Range(0, 255)) = 0
  101. [Enum(UnityEngine.Rendering.CompareFunction)]_StencilComparison("Stencil Comparison", Int) = 0
  102. [Enum(UnityEngine.Rendering.StencilOp)]_StencilOperation("Stencil Operation", Int) = 0
  103. }
  104. SubShader
  105. {
  106. // Extracts information for lightmapping, GI (emission, albedo, ...)
  107. // This pass it not used during regular rendering.
  108. Pass
  109. {
  110. Name "Meta"
  111. Tags { "LightMode" = "Meta" }
  112. CGPROGRAM
  113. #pragma vertex vert
  114. #pragma fragment frag
  115. #pragma shader_feature _EMISSION
  116. #pragma shader_feature _CHANNEL_MAP
  117. #include "UnityCG.cginc"
  118. #include "UnityMetaPass.cginc"
  119. // This define will get commented in by the UpgradeShaderForLightweightRenderPipeline method.
  120. //#define _LIGHTWEIGHT_RENDER_PIPELINE
  121. struct v2f
  122. {
  123. float4 vertex : SV_POSITION;
  124. float2 uv : TEXCOORD0;
  125. };
  126. float4 _MainTex_ST;
  127. v2f vert(appdata_full v)
  128. {
  129. v2f o;
  130. o.vertex = UnityMetaVertexPosition(v.vertex, v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST);
  131. o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  132. return o;
  133. }
  134. sampler2D _MainTex;
  135. sampler2D _ChannelMap;
  136. fixed4 _Color;
  137. fixed4 _EmissiveColor;
  138. #if defined(_LIGHTWEIGHT_RENDER_PIPELINE)
  139. CBUFFER_START(_LightBuffer)
  140. float4 _MainLightPosition;
  141. half4 _MainLightColor;
  142. CBUFFER_END
  143. #else
  144. fixed4 _LightColor0;
  145. #endif
  146. half4 frag(v2f i) : SV_Target
  147. {
  148. UnityMetaInput output;
  149. UNITY_INITIALIZE_OUTPUT(UnityMetaInput, output);
  150. output.Albedo = tex2D(_MainTex, i.uv) * _Color;
  151. #if defined(_EMISSION)
  152. #if defined(_CHANNEL_MAP)
  153. output.Emission += tex2D(_ChannelMap, i.uv).b * _EmissiveColor;
  154. #else
  155. output.Emission += _EmissiveColor;
  156. #endif
  157. #endif
  158. #if defined(_LIGHTWEIGHT_RENDER_PIPELINE)
  159. output.SpecularColor = _MainLightColor.rgb;
  160. #else
  161. output.SpecularColor = _LightColor0.rgb;
  162. #endif
  163. return UnityMetaFragment(output);
  164. }
  165. ENDCG
  166. }
  167. Pass
  168. {
  169. Name "Main"
  170. Tags{ "RenderType" = "Opaque" "LightMode" = "ForwardBase" }
  171. LOD 100
  172. Blend[_SrcBlend][_DstBlend]
  173. BlendOp[_BlendOp]
  174. ZTest[_ZTest]
  175. ZWrite[_ZWrite]
  176. Cull[_CullMode]
  177. Offset[_ZOffsetFactor],[_ZOffsetUnits]
  178. ColorMask[_ColorWriteMask]
  179. Stencil
  180. {
  181. Ref[_StencilReference]
  182. Comp[_StencilComparison]
  183. Pass[_StencilOperation]
  184. }
  185. CGPROGRAM
  186. #if defined(SHADER_API_D3D11)
  187. #pragma target 5.0
  188. #endif
  189. #pragma vertex vert
  190. #pragma fragment frag
  191. #pragma multi_compile_instancing
  192. #pragma multi_compile _ LIGHTMAP_ON
  193. #pragma multi_compile _ _MULTI_HOVER_LIGHT
  194. #pragma multi_compile _ _CLIPPING_PLANE
  195. #pragma multi_compile _ _CLIPPING_SPHERE
  196. #pragma multi_compile _ _CLIPPING_BOX
  197. #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON
  198. #pragma shader_feature _DISABLE_ALBEDO_MAP
  199. #pragma shader_feature _ _METALLIC_TEXTURE_ALBEDO_CHANNEL_A _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
  200. #pragma shader_feature _CHANNEL_MAP
  201. #pragma shader_feature _NORMAL_MAP
  202. #pragma shader_feature _EMISSION
  203. #pragma shader_feature _TRIPLANAR_MAPPING
  204. #pragma shader_feature _LOCAL_SPACE_TRIPLANAR_MAPPING
  205. #pragma shader_feature _DIRECTIONAL_LIGHT
  206. #pragma shader_feature _SPECULAR_HIGHLIGHTS
  207. #pragma shader_feature _SPHERICAL_HARMONICS
  208. #pragma shader_feature _REFLECTIONS
  209. #pragma shader_feature _REFRACTION
  210. #pragma shader_feature _RIM_LIGHT
  211. #pragma shader_feature _VERTEX_COLORS
  212. #pragma shader_feature _VERTEX_EXTRUSION
  213. #pragma shader_feature _CLIPPING_BORDER
  214. #pragma shader_feature _NEAR_PLANE_FADE
  215. #pragma shader_feature _NEAR_LIGHT_FADE
  216. #pragma shader_feature _HOVER_LIGHT
  217. #pragma shader_feature _HOVER_COLOR_OVERRIDE
  218. #pragma shader_feature _PROXIMITY_LIGHT
  219. #pragma shader_feature _PROXIMITY_LIGHT_COLOR_OVERRIDE
  220. #pragma shader_feature _PROXIMITY_LIGHT_SUBTRACTIVE
  221. #pragma shader_feature _PROXIMITY_LIGHT_TWO_SIDED
  222. #pragma shader_feature _ROUND_CORNERS
  223. #pragma shader_feature _BORDER_LIGHT
  224. #pragma shader_feature _BORDER_LIGHT_USES_HOVER_COLOR
  225. #pragma shader_feature _BORDER_LIGHT_REPLACES_ALBEDO
  226. #pragma shader_feature _BORDER_LIGHT_OPAQUE
  227. #pragma shader_feature _INNER_GLOW
  228. #pragma shader_feature _IRIDESCENCE
  229. #pragma shader_feature _ENVIRONMENT_COLORING
  230. #pragma shader_feature _INSTANCED_COLOR
  231. #pragma shader_feature _IGNORE_Z_SCALE
  232. #define IF(a, b, c) lerp(b, c, step((fixed) (a), 0.0));
  233. #include "UnityCG.cginc"
  234. #include "UnityStandardConfig.cginc"
  235. #include "UnityStandardUtils.cginc"
  236. // This define will get commented in by the UpgradeShaderForLightweightRenderPipeline method.
  237. //#define _LIGHTWEIGHT_RENDER_PIPELINE
  238. #if defined(_TRIPLANAR_MAPPING) || defined(_DIRECTIONAL_LIGHT) || defined(_SPHERICAL_HARMONICS) || defined(_REFLECTIONS) || defined(_RIM_LIGHT) || defined(_PROXIMITY_LIGHT) || defined(_ENVIRONMENT_COLORING)
  239. #define _NORMAL
  240. #else
  241. #undef _NORMAL
  242. #endif
  243. #if defined(_CLIPPING_PLANE) || defined(_CLIPPING_SPHERE) || defined(_CLIPPING_BOX)
  244. #define _CLIPPING_PRIMITIVE
  245. #else
  246. #undef _CLIPPING_PRIMITIVE
  247. #endif
  248. #if defined(_NORMAL) || defined(_CLIPPING_PRIMITIVE) || defined(_NEAR_PLANE_FADE) || defined(_HOVER_LIGHT) || defined(_PROXIMITY_LIGHT)
  249. #define _WORLD_POSITION
  250. #else
  251. #undef _WORLD_POSITION
  252. #endif
  253. #if defined(_ALPHATEST_ON) || defined(_CLIPPING_PRIMITIVE) || defined(_ROUND_CORNERS)
  254. #define _ALPHA_CLIP
  255. #else
  256. #undef _ALPHA_CLIP
  257. #endif
  258. #if defined(_ALPHABLEND_ON)
  259. #define _TRANSPARENT
  260. #undef _ALPHA_CLIP
  261. #else
  262. #undef _TRANSPARENT
  263. #endif
  264. #if defined(_ROUND_CORNERS) || defined(_BORDER_LIGHT)
  265. #define _SCALE
  266. #else
  267. #undef _SCALE
  268. #endif
  269. #if defined(_DIRECTIONAL_LIGHT) || defined(_RIM_LIGHT)
  270. #define _FRESNEL
  271. #else
  272. #undef _FRESNEL
  273. #endif
  274. #if defined(_ROUND_CORNERS) || defined(_BORDER_LIGHT) || defined(_INNER_GLOW)
  275. #define _DISTANCE_TO_EDGE
  276. #else
  277. #undef _DISTANCE_TO_EDGE
  278. #endif
  279. #if !defined(_DISABLE_ALBEDO_MAP) || defined(_TRIPLANAR_MAPPING) || defined(_CHANNEL_MAP) || defined(_NORMAL_MAP) || defined(_DISTANCE_TO_EDGE) || defined(_IRIDESCENCE)
  280. #define _UV
  281. #else
  282. #undef _UV
  283. #endif
  284. struct appdata_t
  285. {
  286. float4 vertex : POSITION;
  287. float2 uv : TEXCOORD0;
  288. #if defined(LIGHTMAP_ON)
  289. float2 lightMapUV : TEXCOORD1;
  290. #endif
  291. #if defined(_VERTEX_COLORS)
  292. fixed4 color : COLOR0;
  293. #endif
  294. fixed3 normal : NORMAL;
  295. #if defined(_NORMAL_MAP)
  296. fixed4 tangent : TANGENT;
  297. #endif
  298. UNITY_VERTEX_INPUT_INSTANCE_ID
  299. };
  300. struct v2f
  301. {
  302. float4 position : SV_POSITION;
  303. #if defined(_BORDER_LIGHT)
  304. float4 uv : TEXCOORD0;
  305. #elif defined(_UV)
  306. float2 uv : TEXCOORD0;
  307. #endif
  308. #if defined(LIGHTMAP_ON)
  309. float2 lightMapUV : TEXCOORD1;
  310. #endif
  311. #if defined(_VERTEX_COLORS)
  312. fixed4 color : COLOR0;
  313. #endif
  314. #if defined(_SPHERICAL_HARMONICS)
  315. fixed3 ambient : COLOR1;
  316. #endif
  317. #if defined(_IRIDESCENCE)
  318. fixed3 iridescentColor : COLOR2;
  319. #endif
  320. #if defined(_WORLD_POSITION)
  321. #if defined(_NEAR_PLANE_FADE)
  322. float4 worldPosition : TEXCOORD2;
  323. #else
  324. float3 worldPosition : TEXCOORD2;
  325. #endif
  326. #endif
  327. #if defined(_SCALE)
  328. float3 scale : TEXCOORD3;
  329. #endif
  330. #if defined(_NORMAL)
  331. #if defined(_TRIPLANAR_MAPPING)
  332. fixed3 worldNormal : COLOR3;
  333. fixed3 triplanarNormal : COLOR4;
  334. float3 triplanarPosition : TEXCOORD6;
  335. #elif defined(_NORMAL_MAP)
  336. fixed3 tangentX : COLOR3;
  337. fixed3 tangentY : COLOR4;
  338. fixed3 tangentZ : COLOR5;
  339. #else
  340. fixed3 worldNormal : COLOR3;
  341. #endif
  342. #endif
  343. UNITY_VERTEX_OUTPUT_STEREO
  344. #if defined(_INSTANCED_COLOR)
  345. UNITY_VERTEX_INPUT_INSTANCE_ID
  346. #endif
  347. };
  348. #if defined(_INSTANCED_COLOR)
  349. UNITY_INSTANCING_BUFFER_START(Props)
  350. UNITY_DEFINE_INSTANCED_PROP(float4, _Color)
  351. UNITY_INSTANCING_BUFFER_END(Props)
  352. #else
  353. fixed4 _Color;
  354. #endif
  355. sampler2D _MainTex;
  356. fixed4 _MainTex_ST;
  357. #if defined(_ALPHA_CLIP)
  358. fixed _Cutoff;
  359. #endif
  360. fixed _Metallic;
  361. fixed _Smoothness;
  362. #if defined(_CHANNEL_MAP)
  363. sampler2D _ChannelMap;
  364. #endif
  365. #if defined(_NORMAL_MAP)
  366. sampler2D _NormalMap;
  367. float _NormalMapScale;
  368. #endif
  369. #if defined(_EMISSION)
  370. fixed4 _EmissiveColor;
  371. #endif
  372. #if defined(_TRIPLANAR_MAPPING)
  373. float _TriplanarMappingBlendSharpness;
  374. #endif
  375. #if defined(_DIRECTIONAL_LIGHT)
  376. #if defined(_LIGHTWEIGHT_RENDER_PIPELINE)
  377. CBUFFER_START(_LightBuffer)
  378. float4 _MainLightPosition;
  379. half4 _MainLightColor;
  380. CBUFFER_END
  381. #else
  382. fixed4 _LightColor0;
  383. #endif
  384. #endif
  385. #if defined(_REFRACTION)
  386. fixed _RefractiveIndex;
  387. #endif
  388. #if defined(_RIM_LIGHT)
  389. fixed3 _RimColor;
  390. fixed _RimPower;
  391. #endif
  392. #if defined(_VERTEX_EXTRUSION)
  393. float _VertexExtrusionValue;
  394. #endif
  395. #if defined(_CLIPPING_PLANE)
  396. fixed _ClipPlaneSide;
  397. float4 _ClipPlane;
  398. #endif
  399. #if defined(_CLIPPING_SPHERE)
  400. fixed _ClipSphereSide;
  401. float4 _ClipSphere;
  402. #endif
  403. #if defined(_CLIPPING_BOX)
  404. fixed _ClipBoxSide;
  405. float4 _ClipBoxSize;
  406. float4x4 _ClipBoxInverseTransform;
  407. #endif
  408. #if defined(_CLIPPING_PRIMITIVE)
  409. float _BlendedClippingWidth;
  410. #endif
  411. #if defined(_CLIPPING_BORDER)
  412. fixed _ClippingBorderWidth;
  413. fixed3 _ClippingBorderColor;
  414. #endif
  415. #if defined(_NEAR_PLANE_FADE)
  416. float _FadeBeginDistance;
  417. float _FadeCompleteDistance;
  418. fixed _FadeMinValue;
  419. #endif
  420. #if defined(_HOVER_LIGHT) || defined(_NEAR_LIGHT_FADE)
  421. #if defined(_MULTI_HOVER_LIGHT)
  422. #define HOVER_LIGHT_COUNT 3
  423. #else
  424. #define HOVER_LIGHT_COUNT 1
  425. #endif
  426. #define HOVER_LIGHT_DATA_SIZE 2
  427. float4 _HoverLightData[HOVER_LIGHT_COUNT * HOVER_LIGHT_DATA_SIZE];
  428. #if defined(_HOVER_COLOR_OVERRIDE)
  429. fixed3 _HoverColorOverride;
  430. #endif
  431. #endif
  432. #if defined(_PROXIMITY_LIGHT) || defined(_NEAR_LIGHT_FADE)
  433. #define PROXIMITY_LIGHT_COUNT 2
  434. #define PROXIMITY_LIGHT_DATA_SIZE 6
  435. float4 _ProximityLightData[PROXIMITY_LIGHT_COUNT * PROXIMITY_LIGHT_DATA_SIZE];
  436. #if defined(_PROXIMITY_LIGHT_COLOR_OVERRIDE)
  437. float4 _ProximityLightCenterColorOverride;
  438. float4 _ProximityLightMiddleColorOverride;
  439. float4 _ProximityLightOuterColorOverride;
  440. #endif
  441. #endif
  442. #if defined(_HOVER_LIGHT) || defined(_PROXIMITY_LIGHT) || defined(_BORDER_LIGHT)
  443. fixed _FluentLightIntensity;
  444. #endif
  445. #if defined(_ROUND_CORNERS)
  446. fixed _RoundCornerRadius;
  447. fixed _RoundCornerMargin;
  448. #endif
  449. #if defined(_BORDER_LIGHT)
  450. fixed _BorderWidth;
  451. fixed _BorderMinValue;
  452. #endif
  453. #if defined(_BORDER_LIGHT_OPAQUE)
  454. fixed _BorderLightOpaqueAlpha;
  455. #endif
  456. #if defined(_ROUND_CORNERS) || defined(_BORDER_LIGHT)
  457. fixed _EdgeSmoothingValue;
  458. #endif
  459. #if defined(_INNER_GLOW)
  460. fixed4 _InnerGlowColor;
  461. fixed _InnerGlowPower;
  462. #endif
  463. #if defined(_IRIDESCENCE)
  464. sampler2D _IridescentSpectrumMap;
  465. fixed _IridescenceIntensity;
  466. fixed _IridescenceThreshold;
  467. fixed _IridescenceAngle;
  468. #endif
  469. #if defined(_ENVIRONMENT_COLORING)
  470. fixed _EnvironmentColorThreshold;
  471. fixed _EnvironmentColorIntensity;
  472. fixed3 _EnvironmentColorX;
  473. fixed3 _EnvironmentColorY;
  474. fixed3 _EnvironmentColorZ;
  475. #endif
  476. #if defined(_DIRECTIONAL_LIGHT)
  477. static const fixed _MinMetallicLightContribution = 0.7;
  478. static const fixed _IblContribution = 0.1;
  479. #endif
  480. #if defined(_SPECULAR_HIGHLIGHTS)
  481. static const float _Shininess = 800.0;
  482. #endif
  483. #if defined(_FRESNEL)
  484. static const float _FresnelPower = 8.0;
  485. #endif
  486. #if defined(_NEAR_LIGHT_FADE)
  487. static const float _MaxNearLightDistance = 10.0;
  488. inline float NearLightDistance(float4 light, float3 worldPosition)
  489. {
  490. return distance(worldPosition, light.xyz) + ((1.0 - light.w) * _MaxNearLightDistance);
  491. }
  492. #endif
  493. #if defined(_HOVER_LIGHT)
  494. inline float HoverLight(float4 hoverLight, float inverseRadius, float3 worldPosition)
  495. {
  496. return (1.0 - saturate(length(hoverLight.xyz - worldPosition) * inverseRadius)) * hoverLight.w;
  497. }
  498. #endif
  499. #if defined(_PROXIMITY_LIGHT)
  500. inline float ProximityLight(float4 proximityLight, float4 proximityLightParams, float4 proximityLightPulseParams, float3 worldPosition, float3 worldNormal, out fixed colorValue)
  501. {
  502. float proximityLightDistance = dot(proximityLight.xyz - worldPosition, worldNormal);
  503. #if defined(_PROXIMITY_LIGHT_TWO_SIDED)
  504. worldNormal = IF(proximityLightDistance < 0.0, -worldNormal, worldNormal);
  505. proximityLightDistance = abs(proximityLightDistance);
  506. #endif
  507. float normalizedProximityLightDistance = saturate(proximityLightDistance * proximityLightParams.y);
  508. float3 projectedProximityLight = proximityLight.xyz - (worldNormal * abs(proximityLightDistance));
  509. float projectedProximityLightDistance = length(projectedProximityLight - worldPosition);
  510. float attenuation = (1.0 - normalizedProximityLightDistance) * proximityLight.w;
  511. colorValue = saturate(projectedProximityLightDistance * proximityLightParams.z);
  512. float pulse = step(proximityLightPulseParams.x, projectedProximityLightDistance) * proximityLightPulseParams.y;
  513. return smoothstep(1.0, 0.0, projectedProximityLightDistance / (proximityLightParams.x * max(pow(normalizedProximityLightDistance, 0.25), proximityLightParams.w))) * pulse * attenuation;
  514. }
  515. inline fixed3 MixProximityLightColor(fixed4 centerColor, fixed4 middleColor, fixed4 outerColor, fixed t)
  516. {
  517. fixed3 color = lerp(centerColor.rgb, middleColor.rgb, smoothstep(centerColor.a, middleColor.a, t));
  518. return lerp(color, outerColor, smoothstep(middleColor.a, outerColor.a, t));
  519. }
  520. #endif
  521. #if defined(_CLIPPING_PLANE)
  522. inline float PointVsPlane(float3 worldPosition, float4 plane)
  523. {
  524. float3 planePosition = plane.xyz * plane.w;
  525. return dot(worldPosition - planePosition, plane.xyz);
  526. }
  527. #endif
  528. #if defined(_CLIPPING_SPHERE)
  529. inline float PointVsSphere(float3 worldPosition, float4 sphere)
  530. {
  531. return distance(worldPosition, sphere.xyz) - sphere.w;
  532. }
  533. #endif
  534. #if defined(_CLIPPING_BOX)
  535. inline float PointVsBox(float3 worldPosition, float3 boxSize, float4x4 boxInverseTransform)
  536. {
  537. float3 distance = abs(mul(boxInverseTransform, float4(worldPosition, 1.0))) - boxSize;
  538. return length(max(distance, 0.0)) + min(max(distance.x, max(distance.y, distance.z)), 0.0);
  539. }
  540. #endif
  541. #if defined(_ROUND_CORNERS)
  542. inline float PointVsRoundedBox(float2 position, float2 cornerCircleDistance, float cornerCircleRadius)
  543. {
  544. return length(max(abs(position) - cornerCircleDistance, 0.0)) - cornerCircleRadius;
  545. }
  546. inline fixed RoundCornersSmooth(float2 position, float2 cornerCircleDistance, float cornerCircleRadius)
  547. {
  548. return smoothstep(1.0, 0.0, PointVsRoundedBox(position, cornerCircleDistance, cornerCircleRadius) / _EdgeSmoothingValue);
  549. }
  550. inline fixed RoundCorners(float2 position, float2 cornerCircleDistance, float cornerCircleRadius)
  551. {
  552. #if defined(_TRANSPARENT)
  553. return RoundCornersSmooth(position, cornerCircleDistance, cornerCircleRadius);
  554. #else
  555. return (PointVsRoundedBox(position, cornerCircleDistance, cornerCircleRadius) < 0.0);
  556. #endif
  557. }
  558. #endif
  559. #if defined(_IRIDESCENCE)
  560. fixed3 Iridescence(float tangentDotIncident, sampler2D spectrumMap, float threshold, float2 uv, float angle, float intensity)
  561. {
  562. float k = tangentDotIncident * 0.5 + 0.5;
  563. float4 left = tex2D(spectrumMap, float2(lerp(0.0, 1.0 - threshold, k), 0.5), float2(0.0, 0.0), float2(0.0, 0.0));
  564. float4 right = tex2D(spectrumMap, float2(lerp(threshold, 1.0, k), 0.5), float2(0.0, 0.0), float2(0.0, 0.0));
  565. float2 XY = uv - float2(0.5, 0.5);
  566. float s = (cos(angle) * XY.x - sin(angle) * XY.y) / cos(angle);
  567. return (left.rgb + s * (right.rgb - left.rgb)) * intensity;
  568. }
  569. #endif
  570. v2f vert(appdata_t v)
  571. {
  572. v2f o;
  573. UNITY_SETUP_INSTANCE_ID(v);
  574. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  575. #if defined(_INSTANCED_COLOR)
  576. UNITY_TRANSFER_INSTANCE_ID(v, o);
  577. #endif
  578. float4 vertexPosition = v.vertex;
  579. #if defined(_WORLD_POSITION) || defined(_VERTEX_EXTRUSION)
  580. float3 worldVertexPosition = mul(unity_ObjectToWorld, vertexPosition).xyz;
  581. #endif
  582. #if defined(_NORMAL) || defined(_VERTEX_EXTRUSION)
  583. fixed3 worldNormal = UnityObjectToWorldNormal(v.normal);
  584. #endif
  585. #if defined(_VERTEX_EXTRUSION)
  586. worldVertexPosition += worldNormal * _VertexExtrusionValue;
  587. vertexPosition = mul(unity_WorldToObject, float4(worldVertexPosition, 1.0));
  588. #endif
  589. o.position = UnityObjectToClipPos(vertexPosition);
  590. #if defined(_WORLD_POSITION)
  591. o.worldPosition.xyz = worldVertexPosition;
  592. #endif
  593. #if defined(_NEAR_PLANE_FADE)
  594. float rangeInverse = 1.0 / (_FadeBeginDistance - _FadeCompleteDistance);
  595. #if defined(_NEAR_LIGHT_FADE)
  596. float fadeDistance = _MaxNearLightDistance;
  597. [unroll]
  598. for (int hoverLightIndex = 0; hoverLightIndex < HOVER_LIGHT_COUNT; ++hoverLightIndex)
  599. {
  600. int dataIndex = hoverLightIndex * HOVER_LIGHT_DATA_SIZE;
  601. fadeDistance = min(fadeDistance, NearLightDistance(_HoverLightData[dataIndex], o.worldPosition));
  602. }
  603. [unroll]
  604. for (int proximityLightIndex = 0; proximityLightIndex < PROXIMITY_LIGHT_COUNT; ++proximityLightIndex)
  605. {
  606. int dataIndex = proximityLightIndex * PROXIMITY_LIGHT_DATA_SIZE;
  607. fadeDistance = min(fadeDistance, NearLightDistance(_ProximityLightData[dataIndex], o.worldPosition));
  608. }
  609. #else
  610. float fadeDistance = -UnityObjectToViewPos(vertexPosition).z;
  611. #endif
  612. o.worldPosition.w = max(saturate(mad(fadeDistance, rangeInverse, -_FadeCompleteDistance * rangeInverse)), _FadeMinValue);
  613. #endif
  614. #if defined(_SCALE)
  615. o.scale.x = length(mul(unity_ObjectToWorld, float4(1.0, 0.0, 0.0, 0.0)));
  616. o.scale.y = length(mul(unity_ObjectToWorld, float4(0.0, 1.0, 0.0, 0.0)));
  617. #if defined(_IGNORE_Z_SCALE)
  618. o.scale.z = o.scale.x;
  619. #else
  620. o.scale.z = length(mul(unity_ObjectToWorld, float4(0.0, 0.0, 1.0, 0.0)));
  621. #endif
  622. #endif
  623. #if defined(_BORDER_LIGHT) || defined(_ROUND_CORNERS)
  624. o.uv.xy = TRANSFORM_TEX(v.uv, _MainTex);
  625. float minScale = min(min(o.scale.x, o.scale.y), o.scale.z);
  626. #if defined(_BORDER_LIGHT)
  627. float maxScale = max(max(o.scale.x, o.scale.y), o.scale.z);
  628. float minOverMiddleScale = minScale / (o.scale.x + o.scale.y + o.scale.z - minScale - maxScale);
  629. float areaYZ = o.scale.y * o.scale.z;
  630. float areaXZ = o.scale.z * o.scale.x;
  631. float areaXY = o.scale.x * o.scale.y;
  632. float borderWidth = _BorderWidth;
  633. #endif
  634. if (abs(v.normal.x) == 1.0) // Y,Z plane.
  635. {
  636. o.scale.x = o.scale.z;
  637. o.scale.y = o.scale.y;
  638. #if defined(_BORDER_LIGHT)
  639. if (areaYZ > areaXZ && areaYZ > areaXY)
  640. {
  641. borderWidth *= minOverMiddleScale;
  642. }
  643. #endif
  644. }
  645. else if (abs(v.normal.y) == 1.0) // X,Z plane.
  646. {
  647. o.scale.x = o.scale.x;
  648. o.scale.y = o.scale.z;
  649. #if defined(_BORDER_LIGHT)
  650. if (areaXZ > areaXY && areaXZ > areaYZ)
  651. {
  652. borderWidth *= minOverMiddleScale;
  653. }
  654. #endif
  655. }
  656. else // X,Y plane.
  657. {
  658. o.scale.x = o.scale.x;
  659. o.scale.y = o.scale.y;
  660. #if defined(_BORDER_LIGHT)
  661. if (areaXY > areaYZ && areaXY > areaXZ)
  662. {
  663. borderWidth *= minOverMiddleScale;
  664. }
  665. #endif
  666. }
  667. o.scale.z = minScale;
  668. #if defined(_BORDER_LIGHT)
  669. float scaleRatio = min(o.scale.x, o.scale.y) / max(o.scale.x, o.scale.y);
  670. o.uv.z = IF(o.scale.x > o.scale.y, 1.0 - (borderWidth * scaleRatio), 1.0 - borderWidth);
  671. o.uv.w = IF(o.scale.x > o.scale.y, 1.0 - borderWidth, 1.0 - (borderWidth * scaleRatio));
  672. #endif
  673. #elif defined(_UV)
  674. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  675. #endif
  676. #if defined(LIGHTMAP_ON)
  677. o.lightMapUV.xy = v.lightMapUV.xy * unity_LightmapST.xy + unity_LightmapST.zw;
  678. #endif
  679. #if defined(_VERTEX_COLORS)
  680. o.color = v.color;
  681. #endif
  682. #if defined(_SPHERICAL_HARMONICS)
  683. o.ambient = ShadeSH9(float4(worldNormal, 1.0));
  684. #endif
  685. #if defined(_IRIDESCENCE)
  686. float3 rightTangent = normalize(mul((float3x3)unity_ObjectToWorld, float3(1.0, 0.0, 0.0)));
  687. float3 incidentWithCenter = normalize(mul(unity_ObjectToWorld, float4(0.0, 0.0, 0.0, 1.0)) - _WorldSpaceCameraPos);
  688. float tangentDotIncident = dot(rightTangent, incidentWithCenter);
  689. o.iridescentColor = Iridescence(tangentDotIncident, _IridescentSpectrumMap, _IridescenceThreshold, v.uv, _IridescenceAngle, _IridescenceIntensity);
  690. #endif
  691. #if defined(_NORMAL)
  692. #if defined(_TRIPLANAR_MAPPING)
  693. o.worldNormal = worldNormal;
  694. #if defined(_LOCAL_SPACE_TRIPLANAR_MAPPING)
  695. o.triplanarNormal = v.normal;
  696. o.triplanarPosition = vertexPosition;
  697. #else
  698. o.triplanarNormal = worldNormal;
  699. o.triplanarPosition = o.worldPosition;
  700. #endif
  701. #elif defined(_NORMAL_MAP)
  702. fixed3 worldTangent = UnityObjectToWorldDir(v.tangent.xyz);
  703. fixed tangentSign = v.tangent.w * unity_WorldTransformParams.w;
  704. fixed3 worldBitangent = cross(worldNormal, worldTangent) * tangentSign;
  705. o.tangentX = fixed3(worldTangent.x, worldBitangent.x, worldNormal.x);
  706. o.tangentY = fixed3(worldTangent.y, worldBitangent.y, worldNormal.y);
  707. o.tangentZ = fixed3(worldTangent.z, worldBitangent.z, worldNormal.z);
  708. #else
  709. o.worldNormal = worldNormal;
  710. #endif
  711. #endif
  712. return o;
  713. }
  714. #if defined(SHADER_API_D3D11) && !defined(_ALPHA_CLIP) && !defined(_TRANSPARENT)
  715. [earlydepthstencil]
  716. #endif
  717. fixed4 frag(v2f i, fixed facing : VFACE) : SV_Target
  718. {
  719. #if defined(_INSTANCED_COLOR)
  720. UNITY_SETUP_INSTANCE_ID(i);
  721. #endif
  722. #if defined(_TRIPLANAR_MAPPING)
  723. // Calculate triplanar uvs and apply texture scale and offset values like TRANSFORM_TEX.
  724. fixed3 triplanarBlend = pow(abs(i.triplanarNormal), _TriplanarMappingBlendSharpness);
  725. triplanarBlend /= dot(triplanarBlend, fixed3(1.0, 1.0, 1.0));
  726. float2 uvX = i.triplanarPosition.zy * _MainTex_ST.xy + _MainTex_ST.zw;
  727. float2 uvY = i.triplanarPosition.xz * _MainTex_ST.xy + _MainTex_ST.zw;
  728. float2 uvZ = i.triplanarPosition.xy * _MainTex_ST.xy + _MainTex_ST.zw;
  729. // Ternary operator is 2 instructions faster than sign() when we don't care about zero returning a zero sign.
  730. float3 axisSign = i.triplanarNormal < 0 ? -1 : 1;
  731. uvX.x *= axisSign.x;
  732. uvY.x *= axisSign.y;
  733. uvZ.x *= -axisSign.z;
  734. #endif
  735. // Texturing.
  736. #if defined(_DISABLE_ALBEDO_MAP)
  737. fixed4 albedo = fixed4(1.0, 1.0, 1.0, 1.0);
  738. #else
  739. #if defined(_TRIPLANAR_MAPPING)
  740. fixed4 albedo = tex2D(_MainTex, uvX) * triplanarBlend.x +
  741. tex2D(_MainTex, uvY) * triplanarBlend.y +
  742. tex2D(_MainTex, uvZ) * triplanarBlend.z;
  743. #else
  744. fixed4 albedo = tex2D(_MainTex, i.uv);
  745. #endif
  746. #endif
  747. #ifdef LIGHTMAP_ON
  748. albedo.rgb *= DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.lightMapUV));
  749. #endif
  750. #if defined(_CHANNEL_MAP)
  751. fixed4 channel = tex2D(_ChannelMap, i.uv);
  752. _Metallic = channel.r;
  753. albedo.rgb *= channel.g;
  754. _Smoothness = channel.a;
  755. #else
  756. #if defined(_METALLIC_TEXTURE_ALBEDO_CHANNEL_A)
  757. _Metallic = albedo.a;
  758. albedo.a = 1.0;
  759. #elif defined(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A)
  760. _Smoothness = albedo.a;
  761. albedo.a = 1.0;
  762. #endif
  763. #endif
  764. // Primitive clipping.
  765. #if defined(_CLIPPING_PRIMITIVE)
  766. float primitiveDistance = 1.0;
  767. #if defined(_CLIPPING_PLANE)
  768. primitiveDistance = min(primitiveDistance, PointVsPlane(i.worldPosition.xyz, _ClipPlane) * _ClipPlaneSide);
  769. #endif
  770. #if defined(_CLIPPING_SPHERE)
  771. primitiveDistance = min(primitiveDistance, PointVsSphere(i.worldPosition.xyz, _ClipSphere) * _ClipSphereSide);
  772. #endif
  773. #if defined(_CLIPPING_BOX)
  774. primitiveDistance = min(primitiveDistance, PointVsBox(i.worldPosition.xyz, _ClipBoxSize.xyz, _ClipBoxInverseTransform) * _ClipBoxSide);
  775. #endif
  776. #if defined(_CLIPPING_BORDER)
  777. fixed3 primitiveBorderColor = lerp(_ClippingBorderColor, fixed3(0.0, 0.0, 0.0), primitiveDistance / _ClippingBorderWidth);
  778. albedo.rgb += primitiveBorderColor * IF((primitiveDistance < _ClippingBorderWidth), 1.0, 0.0);
  779. #endif
  780. #endif
  781. #if defined(_DISTANCE_TO_EDGE)
  782. fixed2 distanceToEdge;
  783. distanceToEdge.x = abs(i.uv.x - 0.5) * 2.0;
  784. distanceToEdge.y = abs(i.uv.y - 0.5) * 2.0;
  785. #endif
  786. // Rounded corner clipping.
  787. #if defined(_ROUND_CORNERS)
  788. float2 halfScale = i.scale.xy * 0.5;
  789. float2 roundCornerPosition = distanceToEdge * halfScale;
  790. float cornerCircleRadius = saturate(max(_RoundCornerRadius - _RoundCornerMargin, 0.01)) * i.scale.z;
  791. float2 cornerCircleDistance = halfScale - (_RoundCornerMargin * i.scale.z) - cornerCircleRadius;
  792. float roundCornerClip = RoundCorners(roundCornerPosition, cornerCircleDistance, cornerCircleRadius);
  793. #endif
  794. #if defined(_INSTANCED_COLOR)
  795. albedo *= UNITY_ACCESS_INSTANCED_PROP(Props, _Color);
  796. #else
  797. albedo *= _Color;
  798. #endif
  799. #if defined(_VERTEX_COLORS)
  800. albedo *= i.color;
  801. #endif
  802. #if defined(_IRIDESCENCE)
  803. albedo.rgb += i.iridescentColor;
  804. #endif
  805. // Normal calculation.
  806. #if defined(_NORMAL)
  807. fixed3 worldViewDir = normalize(UnityWorldSpaceViewDir(i.worldPosition.xyz));
  808. #if defined(_REFLECTIONS) || defined(_ENVIRONMENT_COLORING)
  809. fixed3 incident = -worldViewDir;
  810. #endif
  811. fixed3 worldNormal;
  812. #if defined(_NORMAL_MAP)
  813. #if defined(_TRIPLANAR_MAPPING)
  814. fixed3 tangentNormalX = UnpackScaleNormal(tex2D(_NormalMap, uvX), _NormalMapScale);
  815. fixed3 tangentNormalY = UnpackScaleNormal(tex2D(_NormalMap, uvY), _NormalMapScale);
  816. fixed3 tangentNormalZ = UnpackScaleNormal(tex2D(_NormalMap, uvZ), _NormalMapScale);
  817. tangentNormalX.x *= axisSign.x;
  818. tangentNormalY.x *= axisSign.y;
  819. tangentNormalZ.x *= -axisSign.z;
  820. // Swizzle world normals to match tangent space and apply Whiteout normal blend.
  821. tangentNormalX = fixed3(tangentNormalX.xy + i.worldNormal.zy, tangentNormalX.z * i.worldNormal.x);
  822. tangentNormalY = fixed3(tangentNormalY.xy + i.worldNormal.xz, tangentNormalY.z * i.worldNormal.y);
  823. tangentNormalZ = fixed3(tangentNormalZ.xy + i.worldNormal.xy, tangentNormalZ.z * i.worldNormal.z);
  824. // Swizzle tangent normals to match world normal and blend together.
  825. worldNormal = normalize(tangentNormalX.zyx * triplanarBlend.x +
  826. tangentNormalY.xzy * triplanarBlend.y +
  827. tangentNormalZ.xyz * triplanarBlend.z);
  828. #else
  829. fixed3 tangentNormal = UnpackScaleNormal(tex2D(_NormalMap, i.uv), _NormalMapScale);
  830. worldNormal.x = dot(i.tangentX, tangentNormal);
  831. worldNormal.y = dot(i.tangentY, tangentNormal);
  832. worldNormal.z = dot(i.tangentZ, tangentNormal);
  833. worldNormal = normalize(worldNormal) * facing;
  834. #endif
  835. #else
  836. worldNormal = normalize(i.worldNormal) * facing;
  837. #endif
  838. #endif
  839. fixed pointToLight = 1.0;
  840. fixed3 fluentLightColor = fixed3(0.0, 0.0, 0.0);
  841. // Hover light.
  842. #if defined(_HOVER_LIGHT)
  843. pointToLight = 0.0;
  844. [unroll]
  845. for (int hoverLightIndex = 0; hoverLightIndex < HOVER_LIGHT_COUNT; ++hoverLightIndex)
  846. {
  847. int dataIndex = hoverLightIndex * HOVER_LIGHT_DATA_SIZE;
  848. fixed hoverValue = HoverLight(_HoverLightData[dataIndex], _HoverLightData[dataIndex + 1].w, i.worldPosition.xyz);
  849. pointToLight += hoverValue;
  850. #if !defined(_HOVER_COLOR_OVERRIDE)
  851. fluentLightColor += lerp(fixed3(0.0, 0.0, 0.0), _HoverLightData[dataIndex + 1].rgb, hoverValue);
  852. #endif
  853. }
  854. #if defined(_HOVER_COLOR_OVERRIDE)
  855. fluentLightColor = _HoverColorOverride.rgb * pointToLight;
  856. #endif
  857. #endif
  858. // Proximity light.
  859. #if defined(_PROXIMITY_LIGHT)
  860. #if !defined(_HOVER_LIGHT)
  861. pointToLight = 0.0;
  862. #endif
  863. [unroll]
  864. for (int proximityLightIndex = 0; proximityLightIndex < PROXIMITY_LIGHT_COUNT; ++proximityLightIndex)
  865. {
  866. int dataIndex = proximityLightIndex * PROXIMITY_LIGHT_DATA_SIZE;
  867. fixed colorValue;
  868. fixed proximityValue = ProximityLight(_ProximityLightData[dataIndex], _ProximityLightData[dataIndex + 1], _ProximityLightData[dataIndex + 2], i.worldPosition.xyz, worldNormal, colorValue);
  869. pointToLight += proximityValue;
  870. #if defined(_PROXIMITY_LIGHT_COLOR_OVERRIDE)
  871. fixed3 proximityColor = MixProximityLightColor(_ProximityLightCenterColorOverride, _ProximityLightMiddleColorOverride, _ProximityLightOuterColorOverride, colorValue);
  872. #else
  873. fixed3 proximityColor = MixProximityLightColor(_ProximityLightData[dataIndex + 3], _ProximityLightData[dataIndex + 4], _ProximityLightData[dataIndex + 5], colorValue);
  874. #endif
  875. #if defined(_PROXIMITY_LIGHT_SUBTRACTIVE)
  876. fluentLightColor -= lerp(fixed3(0.0, 0.0, 0.0), proximityColor, proximityValue);
  877. #else
  878. fluentLightColor += lerp(fixed3(0.0, 0.0, 0.0), proximityColor, proximityValue);
  879. #endif
  880. }
  881. #endif
  882. // Border light.
  883. #if defined(_BORDER_LIGHT)
  884. fixed borderValue;
  885. #if defined(_ROUND_CORNERS)
  886. fixed borderMargin = _RoundCornerMargin + _BorderWidth * 0.5;
  887. cornerCircleRadius = saturate(max(_RoundCornerRadius - borderMargin, 0.01)) * i.scale.z;
  888. cornerCircleDistance = halfScale - (borderMargin * i.scale.z) - cornerCircleRadius;
  889. borderValue = 1.0 - RoundCornersSmooth(roundCornerPosition, cornerCircleDistance, cornerCircleRadius);
  890. #else
  891. borderValue = max(smoothstep(i.uv.z - _EdgeSmoothingValue, i.uv.z + _EdgeSmoothingValue, distanceToEdge.x),
  892. smoothstep(i.uv.w - _EdgeSmoothingValue, i.uv.w + _EdgeSmoothingValue, distanceToEdge.y));
  893. #endif
  894. #if defined(_HOVER_LIGHT) && defined(_BORDER_LIGHT_USES_HOVER_COLOR) && defined(_HOVER_COLOR_OVERRIDE)
  895. fixed3 borderColor = _HoverColorOverride.rgb;
  896. #else
  897. fixed3 borderColor = fixed3(1.0, 1.0, 1.0);
  898. #endif
  899. fixed3 borderContribution = borderColor * borderValue * _BorderMinValue * _FluentLightIntensity;
  900. #if defined(_BORDER_LIGHT_REPLACES_ALBEDO)
  901. albedo.rgb = lerp(albedo.rgb, borderContribution, borderValue);
  902. #else
  903. albedo.rgb += borderContribution;
  904. #endif
  905. #if defined(_HOVER_LIGHT) || defined(_PROXIMITY_LIGHT)
  906. albedo.rgb += (fluentLightColor * borderValue * pointToLight * _FluentLightIntensity) * 2.0;
  907. #endif
  908. #if defined(_BORDER_LIGHT_OPAQUE)
  909. albedo.a = max(albedo.a, borderValue * _BorderLightOpaqueAlpha);
  910. #endif
  911. #endif
  912. #if defined(_ROUND_CORNERS)
  913. albedo *= roundCornerClip;
  914. pointToLight *= roundCornerClip;
  915. #endif
  916. #if defined(_ALPHA_CLIP)
  917. #if !defined(_ALPHATEST_ON)
  918. _Cutoff = 0.5;
  919. #endif
  920. #if defined(_CLIPPING_PRIMITIVE)
  921. albedo *= (primitiveDistance > 0.0);
  922. #endif
  923. clip(albedo.a - _Cutoff);
  924. albedo.a = 1.0;
  925. #endif
  926. // Blinn phong lighting.
  927. #if defined(_DIRECTIONAL_LIGHT)
  928. #if defined(_LIGHTWEIGHT_RENDER_PIPELINE)
  929. float4 directionalLightDirection = _MainLightPosition;
  930. #else
  931. float4 directionalLightDirection = _WorldSpaceLightPos0;
  932. #endif
  933. fixed diffuse = max(0.0, dot(worldNormal, directionalLightDirection));
  934. #if defined(_SPECULAR_HIGHLIGHTS)
  935. fixed halfVector = max(0.0, dot(worldNormal, normalize(directionalLightDirection + worldViewDir)));
  936. fixed specular = saturate(pow(halfVector, _Shininess * pow(_Smoothness, 4.0)) * _Smoothness * 0.5);
  937. #else
  938. fixed specular = 0.0;
  939. #endif
  940. #endif
  941. // Image based lighting (attempt to mimic the Standard shader).
  942. #if defined(_REFLECTIONS)
  943. fixed3 worldReflection = reflect(incident, worldNormal);
  944. fixed4 iblData = UNITY_SAMPLE_TEXCUBE_LOD(unity_SpecCube0, worldReflection, (1.0 - _Smoothness) * UNITY_SPECCUBE_LOD_STEPS);
  945. fixed3 ibl = DecodeHDR(iblData, unity_SpecCube0_HDR);
  946. #if defined(_REFRACTION)
  947. fixed4 refractColor = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, refract(incident, worldNormal, _RefractiveIndex));
  948. ibl *= DecodeHDR(refractColor, unity_SpecCube0_HDR);
  949. #endif
  950. #else
  951. fixed3 ibl = unity_IndirectSpecColor.rgb;
  952. #endif
  953. // Fresnel lighting.
  954. #if defined(_FRESNEL)
  955. fixed fresnel = 1.0 - saturate(abs(dot(worldViewDir, worldNormal)));
  956. #if defined(_RIM_LIGHT)
  957. fixed3 fresnelColor = _RimColor * pow(fresnel, _RimPower);
  958. #else
  959. fixed3 fresnelColor = unity_IndirectSpecColor.rgb * (pow(fresnel, _FresnelPower) * max(_Smoothness, 0.5));
  960. #endif
  961. #endif
  962. // Final lighting mix.
  963. fixed4 output = albedo;
  964. #if defined(_SPHERICAL_HARMONICS)
  965. fixed3 ambient = i.ambient;
  966. #else
  967. fixed3 ambient = glstate_lightmodel_ambient + fixed3(0.25, 0.25, 0.25);
  968. #endif
  969. fixed minProperty = min(_Smoothness, _Metallic);
  970. #if defined(_DIRECTIONAL_LIGHT)
  971. fixed oneMinusMetallic = (1.0 - _Metallic);
  972. output.rgb = lerp(output.rgb, ibl, minProperty);
  973. #if defined(_LIGHTWEIGHT_RENDER_PIPELINE)
  974. fixed3 directionalLightColor = _MainLightColor.rgb;
  975. #else
  976. fixed3 directionalLightColor = _LightColor0.rgb;
  977. #endif
  978. output.rgb *= lerp((ambient + directionalLightColor * diffuse + directionalLightColor * specular) * max(oneMinusMetallic, _MinMetallicLightContribution), albedo, minProperty);
  979. output.rgb += (directionalLightColor * albedo * specular) + (directionalLightColor * specular * _Smoothness);
  980. output.rgb += ibl * oneMinusMetallic * _IblContribution;
  981. #elif defined(_REFLECTIONS)
  982. output.rgb = lerp(output.rgb, ibl, minProperty);
  983. output.rgb *= lerp(ambient, albedo, minProperty);
  984. #elif defined(_SPHERICAL_HARMONICS)
  985. output.rgb *= ambient;
  986. #endif
  987. #if defined(_FRESNEL)
  988. #if defined(_RIM_LIGHT) || !defined(_REFLECTIONS)
  989. output.rgb += fresnelColor;
  990. #else
  991. output.rgb += fresnelColor * (1.0 - minProperty);
  992. #endif
  993. #endif
  994. #if defined(_EMISSION)
  995. #if defined(_CHANNEL_MAP)
  996. output.rgb += _EmissiveColor * channel.b;
  997. #else
  998. output.rgb += _EmissiveColor;
  999. #endif
  1000. #endif
  1001. // Inner glow.
  1002. #if defined(_INNER_GLOW)
  1003. fixed2 uvGlow = pow(distanceToEdge * _InnerGlowColor.a, _InnerGlowPower);
  1004. output.rgb += lerp(fixed3(0.0, 0.0, 0.0), _InnerGlowColor.rgb, uvGlow.x + uvGlow.y);
  1005. #endif
  1006. // Environment coloring.
  1007. #if defined(_ENVIRONMENT_COLORING)
  1008. fixed3 environmentColor = incident.x * incident.x * _EnvironmentColorX +
  1009. incident.y * incident.y * _EnvironmentColorY +
  1010. incident.z * incident.z * _EnvironmentColorZ;
  1011. output.rgb += environmentColor * max(0.0, dot(incident, worldNormal) + _EnvironmentColorThreshold) * _EnvironmentColorIntensity;
  1012. #endif
  1013. #if defined(_NEAR_PLANE_FADE)
  1014. output *= i.worldPosition.w;
  1015. #endif
  1016. // Hover and proximity lighting should occur after near plane fading.
  1017. #if defined(_HOVER_LIGHT) || defined(_PROXIMITY_LIGHT)
  1018. output.rgb += fluentLightColor * _FluentLightIntensity * pointToLight;
  1019. #endif
  1020. // Perform non-alpha clipped primitive clipping on the final output.
  1021. #if defined(_CLIPPING_PRIMITIVE) && !defined(_ALPHA_CLIP)
  1022. output *= saturate(primitiveDistance * (1.0f / _BlendedClippingWidth));
  1023. #endif
  1024. return output;
  1025. }
  1026. ENDCG
  1027. }
  1028. }
  1029. Fallback "Hidden/InternalErrorShader"
  1030. CustomEditor "Microsoft.MixedReality.Toolkit.Editor.MixedRealityStandardShaderGUI"
  1031. }