Lean Texture


DOCUMENTATION

What is Lean Texture?

Lean Texture allows you quickly modify textures in your project with a range of filters, pack them together into channels, and much more!



Required Package

NOTE  Lean Texture requires the Burst package made by Unity to be manually installed.

To install this package, first open the Package Manager window, and wait for the package list to finish downloading.

Click the dropdown, and select Unity Registry, so you can see all of Unity's official packages.

Once the list loads, scroll down to find the Burst package, and click Install.

You should now be able to enjoy the full Lean Texture experience!



How do I get started?


Install Burst

If you haven't already, make sure you install the Burst package made by Unity. Steps on how to install this are described HERE.



Create a Lean Texture

Go to the Project tab, right click on a texture asset, and select the Create / Lean / Texture option.

This will create a new LeanTexture asset alongside your texture. This asset will be pre-configured with your texture.



Add Filters

Click the Add Filter button, and select the kind of filter you want to apply to your texture.

After you add a filter, you can adjust its settings in the inspector.

At the bottom of the inspector you can see a preview of the texture with all the filters you have applied.

NOTE  You can add multiple filters.


Save Changes To Project

Once you're happy with your texture modifications, you can click the Save button. This will save the modified texture to your project alongside the LeanTexture asset, with the same filename.




How do I make a channel packed texture?


Create a Lean Texture

Go to the Project tab, select multiple texture assets, right click on one of them, and select the Create / Lean / Texture option.

This will create a new LeanTexture asset alongside your textures.



Adjust Channels

The Lean Texture asset that was created will be pre-configured with your textures based on your selection order, so the first selected texture will be packed into the red channel of the output texture based on that texture's RGB grayscale value, etc.

If you don't like these default settings then feel free to adjust them.



Save Changes To Project

Once you're happy with your texture modifications, you can click the Save button. This will save the packed texture to your project alongside the LeanTexture asset, with the same filename.




How do I use this from C# code?


Assembly Reference

NOTE  All Lean Texture code is inside the LeanTexture assembly (Lean/Texture/LeanTexture.asmdef).

If you cannot access this code, then you must:

Step 1  Create an assembly for your own code.
Step 2  Put your code alongside or in a child folder of this new assembly.
Step 3  Modify your assembly to reference the LeanTexture assembly.

You can read Unity's documentation about this feature HERE.



(Optional) Namespace

All Lean Texture code is inside the Lean.Texture namespace.

To reduce the amount of typing, you can add a using statement to the top of your source file.

using Lean.Texture



Create LeanTexture

Begin by creating a new LeanTexture instance, and store it in a variable.

// Create LeanTexture instance

var leanTexture = new LeanTexture();



Begin With

Next, specify how the texture should begin. All availible classes will start with the LeanCreate___ name.

NOTE  These class names are sligtly different from the names that appear in the inspector. See the class list at the bottom of this documentation to see which is which.

// Begin with texture

var createTexture = leanTexture.BeginWith<LeanCreateTexture>();

createTexture.Texture = SourceTexture;



Then

Next, add a filter. All availible classes will start with the LeanFilter___ name.

NOTE  These class names are sligtly different from the names that appear in the inspector. See the class list at the bottom of this documentation to see which is which.

// Then Modify Brightness

var filterBrightness = leanTexture.Then<LeanFilterBrightness>();

filterBrightness.Multiplier = 2.0f;

NOTE  This step can be repeated any number of times.


Generate Texture

Finally, you can generate the texture based on these settings.

// Generate texture

var generatedTexture = leanTexture.Generate();

// NOTE: You must manually destroy this texture once you've finished using it




How can I stop in-game texture generation from lagging?

The steps described above allow you to generate a texture from C# immediately. This means the code will pause until the texture generated has completed.

This is fine for mose scenarios, but if you have a high resolution texture with many filters, it can cause lag or stuttering.

To eliminate this, you can spread the texture generation over multiple frames. To do this, instead of calling the leanTexture.Generate() method, you can call the leanTexture.TrySchedule() method.

Instead of returning a texture, this will give you a LeanPendingTexture instance.

You can store this instance somewhere, and then up to 3 frames later you can call its .Complete() method to get the generated texture.

NOTE  This technique is advanced, and requires good C# knowledge.






Assets

Here's a list of all my other assets, please check them out!

You can also view this list on my Asset Store page.

Lean Touch

Lean Touch

Rapidly develop your game with consistent input across desktop & mobile using Lean Touch. This lightweight asset comes with many modular components, allowing you to customize them to your exact project needs!


Lean Touch+

Lean Touch+

Lean Touch+ is an extension to the popular Lean Touch asset, adding many more example scenes.


Lean Localization

Lean Localization

Lean Localization is a localization library that's designed to be as simple to use as possible for both designers, and programmers.


Lean Pool

Lean Pool

Quickly optimize the performance of your games using Lean Pool. Within minutes you can use this lightweight asset to preload, recycle, and limit the spawning of your prefabs.


Lean Transition

Lean Transition

Quickly polish your games using Lean Transition. This asset allows you to easily tween or animate almost anything in your game, making it transition smoothly.


Lean GUI

Lean GUI

Lean GUI is a colllection of components that extend Unity's GUI system, allowing you to rapidly enhance the user experience (UX) of your game's UI.


Lean GUI Shapes

Lean GUI Shapes

Lean GUI Shapes allows you to quickly add lines, rounded boxes, polygons, and much more to your GUI!


Lean Texture

Lean Texture

Lean Texture allows you quickly modify textures in your project with a range of filters, pack them together into channels, and much more!


Lean Texture+

Lean Texture+

Lean Texture+ is an extension to Lean Texture, adding many new types of texture modification tools!


CW Spaceships - Build & Destroy

CW Spaceships

Build your dream spaceship, and then have fun destroying it!


CW Orbit - Modular Backgrounds

CW Orbit

Take your space game to the next level with this collection of 8K background planets. Just drag and drop them in, and enjoy orbiting around them.


CW Nebula - Modular Backgrounds

CW Nebula

Add stunning nebula backgrounds to your 3D space games with ease.


CW Gas Giant - Modular Backgrounds

CW Gas Giant

Add stunning gas giant backgrounds to your 3D space games with ease.


CW Galaxy - Modular Backgrounds

CW Galaxy

Add stunning galaxy backgrounds to your 3D space games with ease.


CW Silhouette - Modular Backgrounds

CW Silhouette

Add stunning silhouette backgrounds to your 3D space games with ease.


CW Cosmos - Modular Backgrounds

CW Cosmos

Add stunning nebula and galaxy backgrounds to your 3D space games with ease.


Paint in 3D

Paint in 3D

Paint all your objects using Paint in 3D - both in game, and in editor. All features are optimized with GPU accelerated texture painting, so you can enjoy consistent performance, even if you paint your objects one million times!


FLOW

FLOW

FLOW allows you to add large scale interactive fluids to your scene - all highly optimized using GPU acceleration.


Destructible 2D

Destructible 2D

Unlock the full potential of your 2D games using Destructible 2D, this asset allows you to quickly convert all your boring solid sprites into fully destructible ones!


Space Graphics Toolkit

Space Graphics Toolkit

Quickly make the space scene of your dreams using Space Graphics Toolkit. This huge collection of space effects can be customized and combined in any way you like, allowing you to quickly make realistic or fantasy worlds. Each feature has been heavily optimized to run on almost any device and platform.


Space Graphics Planets

Space Graphics Planets

Enhance your space scenes using this large pack of high detail volumetric planets. These planets are finished using the powerful planet features from Space Graphics Toolkit (not required).


Volumetric Audio

Volumetric Audio

Unity sounds only emanate from a single point source. This is great for explosions and footsteps, but quite often you need something more advanced. Volumetric Audio is an easy to use package that allows you to define boxes, spheres, capsules, paths, or meshes that sounds can emanate from.






Versions

2.0.2

Moved main build to Unity 2021.3.0f1.
Updated shaders to latest version.



2.0.1

Moved main build to Unity 2020.3.0f1.



2.0.0

NOTE  This is a massive update. To update you must first back up your project, delete the root Lean folder, then install the new version.

Changed folder structure to be inside Plugins/CW/LeanTexture.
Updated inspector code to support third party assets that implement nested inspectors.



1.0.4

Fixed png export when in linear color space.



1.0.3

Updated common library code.



1.0.2

Fixed in-editor error when loaded texture and source texture have different sizes due to NPOT scaling.



1.0.1

Fixed preview RGB isolation not working for Preset = ColorPlusTransparency.
Fixed preview RGB isolation not working for Preset = LineColorPlusTransparency.
Fixed color shift in linear color space.
Fixed half pixel offset from texture sampling.
Fixed compression settings not being copied to exported texture.
Centered preview texture.
Textures loaded in-editor are now directly loaded from file in an uncompressed form if they're originally .png or .jpg.



1.0.0

Initial release.







Components

LeanCreate

This is the base class for all texture creation methods.



LeanCreateColor

This lets you create a texture where all pixels have the same color value.


int2
Size

The size of the created texture.



Color
Color

The color of the created texture.




LeanCreateGradient

This lets you create a texture based on a color gradient.


int2
Size

The size of the created texture.



Color
ColorA

The first color of the gradient.



Color
ColorB

The second color of the gradient.



CoordinateType
Coordinate

The coordinate space of the points, where 0 is the bottom left.



float2
PointA

The first point of the gradient.



float2
PointB

The second point of the gradient.




LeanCreateTexture

This lets you load a texture so you can then modify it with various filters.


UnityEngine.Texture
Texture

The texture that will be used to create the texture.



int2
OverrideSize

The size of the created texture.

-1 = Use existing texture size.




LeanCreateTextureCombined

This lets you create a texture from up to 4 other textures. A single value is extracted from each of the textures using the channel(s) you specify, and this is stored in each of the final texture's channels.


UnityEngine.Texture
RedTexture

The texture that will be stored in the Red channel of the created texture.



ChannelType
RedChannel

The channel from the RedTexture that will be stored in the created texture's Red channel.



UnityEngine.Texture
GreenTexture

The texture that will be stored in the Green channel of the created texture.



ChannelType
GreenChannel

The channel from the GreenTexture that will be stored in the created texture's Green channel.



UnityEngine.Texture
BlueTexture

The texture that will be stored in the Blue channel of the created texture.



ChannelType
BlueChannel

The channel from the BlueTexture that will be stored in the created texture's Blue channel.



UnityEngine.Texture
AlphaTexture

The texture that will be stored in the Alpha channel of the created texture.



ChannelType
AlphaChannel

The channel from the alphaTexture that will be stored in the created texture's alpha channel.



int2
OverrideSize

By default the created texture will be given the largest width and largest height of the input textures, but this setting allows you to override this.

-1 = Do not override size.




LeanEnumAttribute

Enums don't seem to render properly with SerializeReference if they appear after the inspector has opened (at least in 2019.4.12f1), so we use this to work around it.



LeanFilter

This is the base class for all texture filter types.



LeanFilterBrightness

This allows you to modify the brightness of all pixels in the current texture.


float
Multiplier

The brightness of all pixels will be multiplied by this value.




LeanFilterGrayscale

This will convert the texture's RGB values into a single grayscale value, and write it to the specified channels.


float
Strength

The strength of the grayscale effect.

0 = No change.

1 = Fully grayscale.



OutputType
OutputTo

This allows you to specify the channels the grayscale value will be written to.




LeanFilterHue

This allows you to modify the hue of all pixels in the current texture.


float
Offset

The hue of all pixels will be offset by this value.




LeanFilterMultiply

This allows you to multiply all pixels in the current texture by the specified value, either to all RGBA channels, or individually.


ChannelType
Channels

How should the texture channels should be modified?



float
Multiplier

All channels will be multiplied by this value.



float
MultiplierR

This channel value will be multiplied by this value.



float
MultiplierG

This channel value will be multiplied by this value.



float
MultiplierB

This channel value will be multiplied by this value.



float
MultiplierA

This channel value will be multiplied by this value.




LeanFilterSaturation

This allows you to modify the saturation of all pixels in the current texture.


float
Multiplier

The saturation of all pixels will be multiplied by this value.




LeanFilterTint

This allows you to multiply all pixels in the current texture by the specified color.


Color
Color

All pixels in the texture will be multiplied by this color.




LeanPendingTexture

This class stores information about a texture that is currently being generated.

NOTE  After getting an instance of this class from the LeanTexture.TrySchedule method, you must manually call its Complete method within 3 frames.

Texture2D
Complete

This method will convert this pending texture into the final Texture2D, and then clean up & pool itself.

NOTE  After scheduling a texture to be generated, you must manually call this method within 3 frames.



LeanSample

This class contains useful methods used for sampling texture data.



LeanTexture

This class can generate a texture based on the specified Create technique, which is then modified by the specified Filters.

The texture can be immediately generated using the Generate method, or it can be generated asynchronously with the TrySchedule method.


PresetType
Preset

This allows you to specify what kind of texture is being generated. This changes the output texture format, preview behavior, and warnings in the filter inspectors.

NOTE  The Color presets are for gamma/sRGB textures, and the LinearColor presets are for linear color space textures.
NOTE  The PlusAlpha and PlusTransparency presets change how the preview is rendered. If your alpha channel stores non-transparency data (e.g. smoothness, height) then you should use the PlusAlpha presets.


Texture2D
SettingsFrom

When generating the texture, some settings like the WrapMode will be copied from the texture you specify here.



TextureWrapMode
WrapModeU

If SettingsFrom is set to None/null, then this allows you to specify the wrap mode of the generated texture.



TextureWrapMode
WrapModeV

If SettingsFrom is set to None/null, then this allows you to specify the wrap mode of the generated texture.



bool
MipmapEnabled

If SettingsFrom is set to None/null, then this allows you to specify the mip map creation of the generated texture.



LeanCreate
Create

The texture will begin with this creation method.



List<LeanFilter>
Filters

The texture will then be modified by these filters.



bool
HasWrapping

Does this texture have horizontal or vertical wrapping?



T
BeginWith<T>

This method allows you to change how this texture is initially created.



T
Then<T>

This method allows you to add a filter to the current texture.



Texture2D
Generate
Texture2D existingTexture = null, bool destroyExistingIfIncompatible = true, PreviewType preview = PreviewType.None, bool previewTile = false

This method will immediately perform the specified texture operations and return the modified texture.



LeanPendingTexture
TrySchedule
Texture2D existingTexture = null, bool destroyExistingIfIncompatible = true, PreviewType preview = PreviewType.None, bool previewTile = false, bool convertToGamma = false

This method will try and create a job to modify a texture using the current settings applied to this LeanTexture instance.




LeanTextureContainer

This scriptable object wraps LeanTexture, so it can be used as an asset.



FilterFromCode

This component shows you how to use LeanTexture from code.


UnityEngine.Texture
SourceTexture

The texture that will be modified.



RawImage
OutputImage

The UI element the modified texture will be displayed using.




Index

What is Lean Texture?

Required Package

How do I get started?

How do I make a channel packed texture?

How do I use this from C# code?

How can I stop in-game texture generation from lagging?



Assets

Lean Touch

Lean Touch+

Lean Localization

Lean Pool

Lean Transition

Lean GUI

Lean GUI Shapes

Lean Texture

Lean Texture+

CW Spaceships

CW Orbit

CW Nebula

CW Gas Giant

CW Galaxy

CW Silhouette

CW Cosmos

Paint in 3D

FLOW

Destructible 2D

Space Graphics Toolkit

Space Graphics Planets

Volumetric Audio



Versions

2.0.2

2.0.1

2.0.0

1.0.4

1.0.3

1.0.2

1.0.1

1.0.0



Components

LeanCreate

LeanCreateColor

LeanCreateGradient

LeanCreateTexture

LeanCreateTextureCombined

LeanEnumAttribute

LeanFilter

LeanFilterBrightness

LeanFilterGrayscale

LeanFilterHue

LeanFilterMultiply

LeanFilterSaturation

LeanFilterTint

LeanPendingTexture

LeanSample

LeanTexture

LeanTextureContainer

FilterFromCode