Skip to content

TextureUtilities

Description

Unity Editor Only

Various helper functions for modifying textures


ResizeTexture

Declaration

public static Texture2D ResizeTexture(Texture2D texture, int newWidth, int newHeight, FilterMode filterMode = FilterMode.Bilinear)

Parameters

Parameter Description
texture The texture that will be resized
newWidth The width of the output texture
newHeight The height of the output texture
filterMode Default: FilterMode.Bilinear
The filter mode used when resizing the texture

Returns

The texture resized to the input resolution

Description

Scales the input texture to the desired resolution

Does not modify the original texture, returns a new resized one

private void Function()
{
    // Replace with your texture you want to resize
    Texture2D textureToResize;

    // Resize the texture to a specific resolution
    // In this example it will be resized to 2048x2048 with a Bilinear filter mode
    // This does not modify the original texture but returns a new one with the new resolution
    Texture2D resizedTexture = TextureUtilities.ResizeTexture(textureToResize, 2048, 2048, FilterMode.Bilinear);
}

SetReadable

Declaration

public static void SetReadable(Texture2D texture, bool logChanges = false)

Parameters

Parameter Description
texture The texture that will set to readable
logChanges Default: false
Debugs if the texture is set to readable if it is not already

Description

Re-Imports the input texture as readable if necessary

private void Function()
{
    // Replace with your texture you want to read from
    Texture2D texture;

    // Sets the texture to readable if it is not already
    // Modifies the original texture
    TextureUtilities.SetReadable(texture);

    // No return value so use the texture input into the function here
}

Declaration

public static void SetReadable(Texture2D[] textures, bool logChanges = false)

Parameters

Parameter Description
textures The array of textures that will set to readable
logChanges Default: false
Debugs if the texture is set to readable if it is not already

Description

Re-Imports the input textures as readable if necessary

private void Function()
{
    // Replace with your textures you want to read from
    Texture2D[] textures;

    // Sets the textures to readable if they are not already
    // Modifies the original textures
    TextureUtilities.SetReadable(textures);

    // No return value so use the textures input into the function here
}

ConvertFromCompressedNormal

Declaration

public static Texture2D ConvertFromCompressedNormal(Texture2D texture)

Parameters

Parameter Description
texture The texture that will be converted

Returns

The texture converted to an uncompressed normal

Description

Converts a unity compressed normal map back to an uncompressed one, from red to blue essentially

Does not modify the original texture, returns a new converted one

private void Function()
{
    // Replace with your compressed normal
    Texture2D compressedNormal;

    // Convert the unity compressed normal to a regular normal texture
    // This does not modify the original texture but returns a new one with the uncompressed normal
    Texture2D uncompressedNormal = TextureUtilities.ConvertFromCompressedNormal(compressedNormal);
}