• Stars
    star
    1,160
  • Rank 40,222 (Top 0.8 %)
  • Language
    C#
  • License
    MIT License
  • Created about 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Unity extension for lossless sprite texture compression

SpriteDicing

CodeFactor codecov

Sprite Dicing is used in Naninovel β€” visual novel engine. Check it out!

Sprite Dicing is an extension for Unity game engine allowing to split a set of sprite textures into dices, discard identical ones, bake unique dices into atlas textures and then seamlessly reconstruct the original sprites at runtime.

The solution significantly reduces build size when multiple textures with identical areas are used. Consider a visual novel type of game, where multiple textures per character are used, each portraying a different emotion; most of the texture space is occupied with identical data, while only a small area varies:

These original five textures have total size of 17.5MB. After dicing, the resulting atlas texture will contain only the unique areas of the original textures and consume just 2.4MB, effectively compressing the textures by 86.3%.

Installation

Use UPM to install the package via the following git URL: https://github.com/Elringus/SpriteDicing.git#package or download and import SpriteDicing.unitypackage manually.

Minimum supported Unity version: 2019.3

Usage

  1. Create a DicedSpriteAtlas asset using Assets -> Create -> Diced Sprite Atlas menu command, select it;
  2. Specify Input Folder β€” project directory, containing the source textures to process. You can drag-drop a folder from the project hierarchy window or select one with object picker;
  3. Click Build Atlas button and wait for the procedure to finish;
  4. Generated sprites will appear inside the atlas asset; drag and drop them on scene like regular sprites.

Atlas Generation Options

You can optionally configure atlas generation settings via the editor inspector window.

Option Description
Decouple Sprite Data Whether to save sprite assets in a separate folder instead of adding them as childs of the atlas asset.
Trim Transparent Improves compression ratio by discarding fully-transparent diced units, but may also change sprite dimensions. Disable to preserve original texture dimensions.
Default Pivot Relative pivot point position in 0 to 1 range, counting from the bottom-left corner. Can be changed after build for each sprite individually.
Keep Original Whether to preserve original sprites pivot (usable for animations).
Atlas Size Limit Maximum size of a single generated atlas texture; will generate multiple textures when the limit is reached.
Square The generated atlas textures will always be square. Less efficient, but required for PVRTC compression.
POT The generated atlas textures will always have width and height of power of two. Extremely inefficient, but may be required by some older GPUs.
Pixels Per Unit How many pixels in the sprite correspond to the unit in the world.
Dice Unit Size The size of a single diced unit.
Padding The size of a pixel border to add between adjacent diced units inside atlas. Increase to prevent texture bleeding artifacts (usually appear as thin gaps between diced units). Larger values will consume more texture space, but yield better anti-bleeding results. Minimum value of 2 is recommended in most cases. When 2 is not enough to prevent bleeding, consider adding a bit of UV Inset before increasing the padding.
UV Inset Relative inset of the diced units UV coordinates. Can be used in addition to (or instead of) Padding to prevent texture bleeding artifacts. Won't consume any texture space, but higher values could visually distort the final result.
Input Folder Asset folder with source sprite textures.
Include Subfolders Whether to recursively search for textures inside the input folder.
Prepend Names Whether to prepend sprite names with the subfolder name; eg: SubfolderName.SpriteName.

All the above descriptions are available as tooltips when hovering corresponding configuration options in the editor.

Compression Ratio

When inspecting atlas asset, notice Compression Ratio line; it shows the ratio between source textures size and generated data (atlas textures + sprite meshes).

When close to 1 or lower, the value will be in yellow/red color indicating the generated data size is close to or even larger then the source and you should either change atlas generation configuration (eg, increase dice unit size) or not use the solution at all.

UI

To use the diced sprites in UI (eg, Image component), enable Use Sprite Mesh. In case the option is not available, make sure to assign a source image.

Animation

It's possible to use diced sprites for animation. Make sure to enable Keep Original Pivot when generating the atlas to preserve relative positions of the generated sprites. An example on animating diced sprites is available in "Animation" scene.

More Repositories

1

SpriteGlow

A sprite glow effect for Unity game engine
ShaderLab
2,017
star
2

DotNetJS

Consume C# in JavaScript with comfort: single-file UMD library, auto-generated 2-way bindings and type definitions
JavaScript
592
star
3

grass-bending

A replacement for Unity's terrain grass shader with alpha blended rendering and touch bending effect
C#
515
star
4

UnityGoogleDrive

Google Drive SDK for Unity game engine
C#
362
star
5

UnityRawInput

Windows Raw Input wrapper for Unity game engine
C#
198
star
6

UnityConsole

Development console for Unity game engine
C#
79
star
7

BlendModeExample

Example project for "Blend Modes in Unity" article
ShaderLab
69
star
8

UnityCommon

A collection of common frameworks and tools for Unity-based projects
C#
68
star
9

iOSReviewRequest

Unity plugin to invoke a native iOS review request
C#
30
star
10

DarkMatterShader

VFX for Unity
ShaderLab
19
star
11

UnityStreamlabs

Streamlabs client for Unity game engine
C#
14
star
12

UnityDonationAlerts

DonationAlerts SDK for Unity game engine
C#
12
star
13

SagaGUI

GUI plugin for Unreal Engine 4
C++
11
star
14

haji-jam

A small stealth simulation game about social fobia
C#
3
star
15

WasmTest

An example on using .NET 6 Blazor without the ASP.NET web components overhead for JS interop
C#
3
star
16

UnityGoogleDriveAndroid

Used to build AppAuth-Android client library for UnityGoogleDrive project
Java
3
star
17

AddressableUnloadIssue

Repro project for Unity's addressable bug when Resources.UnloadUnusedAssets not unloading released assets
C#
3
star
18

excel-processor

Automate generation of simple pivot Excel spreadsheets
C#
3
star
19

ShadersStudy

Learning to write basic shaders
C
2
star
20

EnginesOfPlay

Interactive player motivation model
CSS
2
star
21

StarcorServer

Starcor project serverside
Python
1
star
22

UECursorBug

Bug with cursor widget being reset on level change
C#
1
star
23

Elringus

1
star
24

BlendModesTutorials

Tutorials project for the `BlendModes` plugin
ShaderLab
1
star
25

BlendModeLayered

GLSL
1
star
26

CDN

1
star
27

NightmareAcademy

HTML
1
star
28

ArabicFixerIssue

ShaderLab
1
star
29

PostProcessingStack

C#
1
star
30

Database

Generic database access layer
1
star
31

UnitySagaGUI

C#
1
star
32

TracesOfLight

A third person adventure game
C++
1
star
33

BiosorbEngine

Biosorb project server-side
1
star
34

StarcorPreAlpha

C#
1
star
35

WireStep

C#
1
star
36

QBubbles

Quantum bubbles game
C#
1
star
37

BreachedUnity

Old Unity-based version
C#
1
star
38

GaBug

A repro project for GA UE4 SDK packaging bug
C++
1
star
39

SagaNetwork

SAGA project backend
C#
1
star
40

ChatServer

Chat for the SAGA project
C#
1
star
41

PingBall

Ludum Dare 36 Warmup project
C#
1
star
42

CWalkerServer

Python
1
star
43

UnrealEngine

4.10.4 branch for Breached
C++
1
star
44

Unite

Logic puzzle game about numbers
C#
1
star
45

Saga

C
1
star
46

PrimeChainStalker

A console program for finding the longest increasing prime numbers chain in a bin file
C#
1
star
47

CWalker

Crazy walker game
C#
1
star
48

UeRtsCamera

A draft for generic RTS camera
C++
1
star
49

PostInitUMGBug

Repro project for the PostInitProperties bug in UE4
C++
1
star
50

DrawMaskIssue

A repro project for drawing sprite mask to render texture issue
C#
1
star