|
| 1 | +# <img height="26" src="https://github.com/user-attachments/assets/89d75386-0fbb-43d7-81e8-df6e5339213a"/> UI Dynamic Sampler <!-- omit in toc --> |
| 2 | + |
| 3 | +[](https://openupm.com/packages/com.coffee.ui-dynamic-sampler/) |
| 4 | +[](https://github.com/mob-sakai/UIDynamicSampler/releases) |
| 5 | +[](https://github.com/mob-sakai/UIDynamicSampler/releases) |
| 6 | + |
| 7 | + |
| 8 | +[](https://github.com/mob-sakai/UIDynamicSampler/blob/main/LICENSE.md) |
| 9 | +[](http://makeapullrequest.com) |
| 10 | +[](https://github.com/mob-sakai/UIDynamicSampler/subscription) |
| 11 | +[](https://twitter.com/intent/follow?screen_name=mob_sakai) |
| 12 | + |
| 13 | +<< [📝 Description](#-description-) | [📌 Key Features](#-key-features) | [🎮 Demo](#-demo) | [⚙ Installation](#-installation) | [🚀 Usage](#-usage) | [🤝 Contributing](#-contributing) >> |
| 14 | + |
| 15 | +## 📝 Description <!-- omit in toc --> |
| 16 | + |
| 17 | +This package provides a component to reduce jaggies in UI elements. |
| 18 | + |
| 19 | +For example, when displaying a 2048x2048 texture at just 100x100 pixels, diagonal lines may appear jagged. |
| 20 | +This effect is particularly noticeable on low-DPI displays (such as standard non-Retina screens) where individual pixels are more visible. |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +In such cases, jaggies can be reduced by generating a thumbnail texture that matches the display size or by using mipmaps. |
| 25 | +However, these approaches increase asset size and complicate asset management. |
| 26 | +Moreover, depending on the UI element's size, these approaches may cause blurring or fail to sufficiently reduce jaggies. |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +The `UIDynamicSampler` component dynamically pre-samples textures based on the current UI element size, effectively reducing jaggies without increasing asset size. |
| 31 | +Additionally, it caches sampling results to maintain performance. |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +- [📌 Key Features](#-key-features) |
| 36 | +- [🎮 Demo](#-demo) |
| 37 | +- [⚙ Installation](#-installation) |
| 38 | + - [Install via OpenUPM](#install-via-openupm) |
| 39 | + - [Install via UPM (with Package Manager UI)](#install-via-upm-with-package-manager-ui) |
| 40 | + - [Install via UPM (Manually)](#install-via-upm-manually) |
| 41 | + - [Install as Embedded Package](#install-as-embedded-package) |
| 42 | +- [🚀 Usage](#-usage) |
| 43 | + - [Getting Started](#getting-started) |
| 44 | +- [🤝 Contributing](#-contributing) |
| 45 | + - [Issues](#issues) |
| 46 | + - [Pull Requests](#pull-requests) |
| 47 | + - [Support](#support) |
| 48 | +- [License](#license) |
| 49 | +- [Author](#author) |
| 50 | +- [See Also](#see-also) |
| 51 | + |
| 52 | +<br><br> |
| 53 | + |
| 54 | +## 📌 Key Features |
| 55 | + |
| 56 | +- **Real-time anti-jaggies for uGUI**: Dynamically samples textures based on UI element size to reduce jaggies. |
| 57 | +- **No Increase in Asset Size**: Performs sampling dynamically, eliminating the need for additional thumbnails or mipmaps, keeping asset management simple. |
| 58 | +- **High Performance with Caching**: Caches sampling results to reduce unnecessary computations. |
| 59 | +- **Improved Visibility on Low-DPI Displays**: Provides clearer rendering even on lower-resolution screens where jaggies are more noticeable. |
| 60 | +- **Easy to Use**: Simply add the `UIDynamicSampler` component to apply the effect. |
| 61 | + |
| 62 | +<br><br> |
| 63 | + |
| 64 | +## 🎮 Demo |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | +[WebGL Demo](https://mob-sakai.github.io/UIDynamicSampler/) |
| 69 | + |
| 70 | +<br><br> |
| 71 | + |
| 72 | +## ⚙ Installation |
| 73 | + |
| 74 | +_This package requires **Unity 2020.3 or later**._ |
| 75 | + |
| 76 | +### Install via OpenUPM |
| 77 | + |
| 78 | +- This package is available on [OpenUPM](https://openupm.com/packages/com.coffee.ui-dynamic-sampler/) package |
| 79 | + registry. |
| 80 | +- This is the preferred method of installation, as you can easily receive updates as they're released. |
| 81 | +- If you have [openupm-cli](https://github.com/openupm/openupm-cli) installed, then run the following command in your |
| 82 | + project's directory: |
| 83 | + ``` |
| 84 | + openupm add com.coffee.ui-dynamic-sampler |
| 85 | + ``` |
| 86 | +- To update the package, use Package Manager UI (`Window > Package Manager`) or run the following command with |
| 87 | + `@{version}`: |
| 88 | + ``` |
| 89 | + openupm add com.coffee.ui-dynamic-sampler@1.0.0 |
| 90 | + ``` |
| 91 | + |
| 92 | +### Install via UPM (with Package Manager UI) |
| 93 | + |
| 94 | +- Click `Window > Package Manager` to open Package Manager UI. |
| 95 | +- Click `+ > Add package from git URL...` and input the repository URL: |
| 96 | + `https://github.com/mob-sakai/UIDynamicSampler.git?path=Packages/src` |
| 97 | +  |
| 98 | +- To update the package, change suffix `#{version}` to the target version. |
| 99 | + - e.g. `https://github.com/mob-sakai/UIDynamicSampler.git?path=Packages/src#1.0.0` |
| 100 | + |
| 101 | +### Install via UPM (Manually) |
| 102 | + |
| 103 | +- Open the `Packages/manifest.json` file in your project. Then add this package somewhere in the `dependencies` block: |
| 104 | + ```json |
| 105 | + { |
| 106 | + "dependencies": { |
| 107 | + "com.coffee.ui-dynamic-sampler": "https://github.com/mob-sakai/UIDynamicSampler.git?path=Packages/src", |
| 108 | + ... |
| 109 | + } |
| 110 | + } |
| 111 | + ``` |
| 112 | + |
| 113 | +- To update the package, change suffix `#{version}` to the target version. |
| 114 | + - e.g. |
| 115 | + `"com.coffee.ui-dynamic-sampler": "https://github.com/mob-sakai/UIDynamicSampler.git?path=Packages/src#1.0.0",` |
| 116 | + |
| 117 | +### Install as Embedded Package |
| 118 | + |
| 119 | +1. Download the `Source code (zip)` file from [Releases](https://github.com/mob-sakai/UIDynamicSampler/releases) and |
| 120 | + extract it. |
| 121 | +2. Move the `<extracted_dir>/Packages/src` directory into your project's `Packages` directory. |
| 122 | +  |
| 123 | + - You can rename the `src` directory if needed. |
| 124 | + - If you intend to fix bugs or add features, installing it as an embedded package is recommended. |
| 125 | + - To update the package, re-download it and replace the existing contents. |
| 126 | + |
| 127 | +<br><br> |
| 128 | + |
| 129 | +## 🚀 Usage |
| 130 | + |
| 131 | +### Getting Started |
| 132 | + |
| 133 | +1. [Install the package](#-installation). |
| 134 | + |
| 135 | +2. Add a `UIDynamicSampler` component to a UI element (Image, RawImage) from the |
| 136 | + `Add Component` in the inspector or `Component > UI > UIDynamicSampler` menu. |
| 137 | +  |
| 138 | + |
| 139 | +3. Compare how jaggies appear in low DPI display environments. |
| 140 | +  |
| 141 | + |
| 142 | +4. Enjoy! |
| 143 | + |
| 144 | +<br><br> |
| 145 | + |
| 146 | +## 🤝 Contributing |
| 147 | + |
| 148 | +### Issues |
| 149 | + |
| 150 | +Issues are incredibly valuable to this project: |
| 151 | + |
| 152 | +- Ideas provide a valuable source of contributions that others can make. |
| 153 | +- Problems help identify areas where this project needs improvement. |
| 154 | +- Questions indicate where contributors can enhance the user experience. |
| 155 | + |
| 156 | +### Pull Requests |
| 157 | + |
| 158 | +Pull requests offer a fantastic way to contribute your ideas to this repository. |
| 159 | +Please refer to [CONTRIBUTING.md](https://github.com/mob-sakai/UIDynamicSampler/tree/develop/CONTRIBUTING.md) |
| 160 | +and [develop branch](https://github.com/mob-sakai/UIDynamicSampler/tree/develop). |
| 161 | + |
| 162 | +### Support |
| 163 | + |
| 164 | +This is an open-source project developed during my spare time. |
| 165 | +If you appreciate it, consider supporting me. |
| 166 | +Your support allows me to dedicate more time to development. 😊 |
| 167 | + |
| 168 | +[](https://github.com/users/mob-sakai/sponsorship) |
| 169 | +[](https://www.patreon.com/join/2343451?) |
| 170 | + |
| 171 | +<br><br> |
| 172 | + |
| 173 | +## License |
| 174 | + |
| 175 | +* MIT |
| 176 | + |
| 177 | +## Author |
| 178 | + |
| 179 | +*  [mob-sakai](https://github.com/mob-sakai) [](https://twitter.com/intent/follow?screen_name=mob_sakai)  |
| 180 | + |
| 181 | +## See Also |
| 182 | + |
| 183 | +* GitHub page : https://github.com/mob-sakai/UIDynamicSampler |
| 184 | +* Releases : https://github.com/mob-sakai/UIDynamicSampler/releases |
| 185 | +* Issue tracker : https://github.com/mob-sakai/UIDynamicSampler/issues |
| 186 | +* Change log : https://github.com/mob-sakai/UIDynamicSampler/blob/main/Packages/src/CHANGELOG.md |
0 commit comments