GxrStandard.shader 49 KB

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