Astra Unity 2.6.6
Astra Unity Plugin
Astra.Asset.TextureUtilities Class Reference

Utilities for working with Textures More...

Classes

class  TextureJob
 

Public Types

enum  BlendType { Albedo = 0 , Normal = 1 , MetalGloss = 2 }
 

Static Public Member Functions

static Texture2D OverlayTextures (Texture2D aBaseTexture, Texture2D aToCopyTexture)
 Produces a Texture2D image composite of two images, where the base texture's R channel is only overwritten when the copy texture's R channel is less than the threshold of 0.48f for a given pixel. More...
 
static void OverlayArrayOfTexturesGPU (ref Texture2D outputTexture, Texture2D[] textures, string shaderName="Unlit/AlphaCombiner", bool debug=false, Color? backgroundOverload=null, Material mat=null, RenderTextureReadWrite rwMode=RenderTextureReadWrite.Default)
 Merge multiple textures into one, this is done on the GPU and is currently specific to the alpha injection system This is MUCH faster then the original cpu only method (150ms to about 8.5ms) More...
 
static RenderTexture OverlayArrayOfTexturesCompute (List< Texture > textures, List< float > strengths, BlendType blendType, RenderTextureFormat format=RenderTextureFormat.ARGB32, bool linear=false, bool debug=false)
 Merge multiple decal textures into one on the GPU via compute shader. More...
 
static RenderTexture OverlayArrayOfTexturesGPU (Texture[] textures, string shaderName="Unlit/AlphaCombiner", bool debug=false, Color? backgroundOverload=null, RenderTextureFormat format=RenderTextureFormat.ARGB32, Material[] mats=null, int maxSize=-1, bool linear=false, int width=-1, int height=-1)
 Processes a stack of textures by rendering them out as quads textures at indexes higher will be closest to the camera with the texture at slot 0 the farthest away More...
 
static Texture2D GetReadableTexture (Texture2D texture, TextureFormat format=TextureFormat.ARGB32, bool mipmap=true, bool linear=false, bool destroyOriginal=false, bool colorSpaceConvert=true)
 Converts any Texture2D into a readable Texture2D, this is useful for textures not marked Read/Write enabled More...
 
static TextureJob GetReadableTextureAsync (Texture2D texture, TextureFormat format=TextureFormat.ARGB32, bool mipmap=true, bool linear=false, bool destroyOriginal=false, bool colorSpaceConvert=true)
 
static Texture2D QuickScale (Texture2D texture, int width, int height)
 Quick operation to scale a given texture to the specified size on the GPU More...
 
static Texture2D QuickScale (Texture2D texture, int width, int height, TextureFormat format, bool linear=false)
 Quick operation to scale a given texture to the specified size on the GPU More...
 
static Texture2D RenderMaterialToTexture2D (Material mat, bool debug=false, Color? backgroundOverload=null, bool linear=false, int width=2048, int height=2048)
 Renders a material to a texture, blocking. This is useful for baking complex materials into a single diffuse More...
 
static GameObject DebugTexture (Texture tex)
 Creates a visible quad at 0,0,0 for display and debugging purposes More...
 
static GameObject DebugMaterial (Material material)
 Creates a visible quad at 0,0,0 for display of the material More...
 
static Color[] SampleTextureAtUVs (Texture2D texture, Vector2[] uvs)
 
static Color32[] Sample32TextureAtUVs (Texture2D texture, Vector2[] uvs)
 
static int GetPixelSlotFromUV (int x, int y, int width, int height=0)
 Retrieves the slot in a continuous array for colors More...
 
static int GetPixelSlotFromUV (float x, float y, int width, int height)
 Retrieves the slot in a continuous array for colors More...
 
static int GetPixelSlotFromUV (Vector2 uv, int width, int height)
 
static TextureFormat GetTextureFormatFromRenderTextureFormat (RenderTextureFormat srcFormat)
 Returns a suitable uncompressed textureformat from a render texture format, this is a "guess" More...
 
static RenderTextureFormat GetRenderTextureFormatFromTextureFormat (TextureFormat srcFormat)
 
static bool IsTextureFormatCompressed (TextureFormat format)
 
static bool IsReadable (Texture2D texture)
 Tells us if a texture is readable or not, for legacy versions of unity (2018.2-) this is done by exception catching More...
 
static bool IsPNG (byte[] bytes)
 Tells you if the bytes you loaded is a raw PNG file or not More...
 

Properties

static Light[] scannedLights [getset]
 

Detailed Description

Utilities for working with Textures

Member Function Documentation

◆ DebugMaterial()

static GameObject Astra.Asset.TextureUtilities.DebugMaterial ( Material  material)
inlinestatic

Creates a visible quad at 0,0,0 for display of the material

Parameters
materialThe material you want to visualize
Returns
A gameobject that contains the quad and renderer

◆ DebugTexture()

static GameObject Astra.Asset.TextureUtilities.DebugTexture ( Texture  tex)
inlinestatic

Creates a visible quad at 0,0,0 for display and debugging purposes

Parameters
texThe texture you want to visualize
Returns
A gameobject that contains the quad and renderer

◆ GetPixelSlotFromUV() [1/2]

static int Astra.Asset.TextureUtilities.GetPixelSlotFromUV ( float  x,
float  y,
int  width,
int  height 
)
inlinestatic

Retrieves the slot in a continuous array for colors

Parameters
xA uv value such as 0.3 or 1.5
y
width
height
Returns

◆ GetPixelSlotFromUV() [2/2]

static int Astra.Asset.TextureUtilities.GetPixelSlotFromUV ( int  x,
int  y,
int  width,
int  height = 0 
)
inlinestatic

Retrieves the slot in a continuous array for colors

Parameters
xThe horizontal position stating left from 0->width eg: 500
yThe vertical position starting bottom from 0->height
widthPixels wide eg: 256
heightPixels tall eg: 512
Returns

◆ GetReadableTexture()

static Texture2D Astra.Asset.TextureUtilities.GetReadableTexture ( Texture2D  texture,
TextureFormat  format = TextureFormat.ARGB32,
bool  mipmap = true,
bool  linear = false,
bool  destroyOriginal = false,
bool  colorSpaceConvert = true 
)
inlinestatic

Converts any Texture2D into a readable Texture2D, this is useful for textures not marked Read/Write enabled

Parameters
texturesource texture you want to make readable
formatThe color channel format defaults to ARGB32 not all formats are supported
mipmapIf you want mipmaps generated
linearTrue if you want linear colorspace otherwise in gamma
destroyOriginalnote this one SWAPS the default behaviour, as you usually want to keep the original around when calling this function!
colorSpaceConvertControls if you want GL.sRGBWrite manipulated when you're in linear space, has no effect in gamma
Returns
The newly readable texture

◆ GetTextureFormatFromRenderTextureFormat()

static TextureFormat Astra.Asset.TextureUtilities.GetTextureFormatFromRenderTextureFormat ( RenderTextureFormat  srcFormat)
inlinestatic

Returns a suitable uncompressed textureformat from a render texture format, this is a "guess"

Parameters
srcFormat
Returns

◆ IsPNG()

static bool Astra.Asset.TextureUtilities.IsPNG ( byte[]  bytes)
inlinestatic

Tells you if the bytes you loaded is a raw PNG file or not

Parameters
bytesThe byte array from
Returns

◆ IsReadable()

static bool Astra.Asset.TextureUtilities.IsReadable ( Texture2D  texture)
inlinestatic

Tells us if a texture is readable or not, for legacy versions of unity (2018.2-) this is done by exception catching

Parameters
textureThe texture you want to test
Returns

◆ OverlayArrayOfTexturesCompute()

static RenderTexture Astra.Asset.TextureUtilities.OverlayArrayOfTexturesCompute ( List< Texture >  textures,
List< float >  strengths,
BlendType  blendType,
RenderTextureFormat  format = RenderTextureFormat.ARGB32,
bool  linear = false,
bool  debug = false 
)
inlinestatic

Merge multiple decal textures into one on the GPU via compute shader.

Parameters
texturesList of textures to merge
strengthsList of strengths for merging normals where 0.0 : 100% transparent and 1.0 : 100% opaque
decalSlotA string indicating what kind of blend operation e.g. albedo, normal, metallic
formatFormat for the RenderTexture used for this operation. Defaults to RenderTextureFormat.ARGB32
linearWhether to use the RenderTextureReadWrite.Linear mode. Defaults to false
debugIf true, keep the merge object afterwards to look at. Defaults false

◆ OverlayArrayOfTexturesGPU() [1/2]

static void Astra.Asset.TextureUtilities.OverlayArrayOfTexturesGPU ( ref Texture2D  outputTexture,
Texture2D[]  textures,
string  shaderName = "Unlit/AlphaCombiner",
bool  debug = false,
Color?  backgroundOverload = null,
Material  mat = null,
RenderTextureReadWrite  rwMode = RenderTextureReadWrite.Default 
)
inlinestatic

Merge multiple textures into one, this is done on the GPU and is currently specific to the alpha injection system This is MUCH faster then the original cpu only method (150ms to about 8.5ms)

Parameters
outputTextureThe Texture to merge into
texturesList of textures to merge
shaderNameShader to use, defaults to Unlit/AlphaCombiner
debugIf true, keep the merge object afterwards to look at. Defaults false
backgroundOverloadBackground color to use. Defaults to white.
matMaterial to use. If set, overrides the shader with the shader in this material. Defaults to null.
rwModeColor space conversion mode for the RenderTexture this operation uses. Defaults to RenderTextureReadWrite.Default.

◆ OverlayArrayOfTexturesGPU() [2/2]

static RenderTexture Astra.Asset.TextureUtilities.OverlayArrayOfTexturesGPU ( Texture[]  textures,
string  shaderName = "Unlit/AlphaCombiner",
bool  debug = false,
Color?  backgroundOverload = null,
RenderTextureFormat  format = RenderTextureFormat.ARGB32,
Material[]  mats = null,
int  maxSize = -1,
bool  linear = false,
int  width = -1,
int  height = -1 
)
inlinestatic

Processes a stack of textures by rendering them out as quads textures at indexes higher will be closest to the camera with the texture at slot 0 the farthest away

NOTE: this method is better to use then the version that returns a Texture2D as that one needs to trip a readpixels call This call is about 0.5ms, the read pixel call typically takes about 20 times as long (~8.5ms)

Parameters
texturesThe textures to render, highest index is closets, lowest index is farthest
shaderNameShader to use, defaults to Unlit/AlphaCombiner
debugIf true, keep the merge object afterwards to look at. Defaults false
backgroundOverloadBackground color to use. Defaults to white.
formatFormat for the RenderTexture used for this operation. Defaults to RenderTextureFormat.ARGB32.
matsList of Materials to use, one for each texture passed in. If set, overrides the shader with the shader in this material for the associated texture. Defaults to null.
maxSizeMaximum size for the resulting texture's width and height. Defaults to -1.
linearWhether to use the RenderTextureReadWrite.Linear mode. Defaults to false
widthWidth of the resulting texture, or -1 to be ignored. Defaults to -1
heightHeight of the resulting texture, or -1 to be ignored. Defaults to -1
Returns
The composited and fully rendered flattened RenderTexture

◆ OverlayTextures()

static Texture2D Astra.Asset.TextureUtilities.OverlayTextures ( Texture2D  aBaseTexture,
Texture2D  aToCopyTexture 
)
inlinestatic

Produces a Texture2D image composite of two images, where the base texture's R channel is only overwritten when the copy texture's R channel is less than the threshold of 0.48f for a given pixel.

Returns
The textures.
Parameters
aBaseTextureA base texture.
aToCopyTextureA to copy texture.

◆ QuickScale() [1/2]

static Texture2D Astra.Asset.TextureUtilities.QuickScale ( Texture2D  texture,
int  width,
int  height 
)
inlinestatic

Quick operation to scale a given texture to the specified size on the GPU

Parameters
textureTexture to scale
widthTarget width of result
heightTarget height of result
Returns
Scaled texture

◆ QuickScale() [2/2]

static Texture2D Astra.Asset.TextureUtilities.QuickScale ( Texture2D  texture,
int  width,
int  height,
TextureFormat  format,
bool  linear = false 
)
inlinestatic

Quick operation to scale a given texture to the specified size on the GPU

Parameters
textureTexture to scale
widthTarget width of result
heightTarget height of result
formatTextureFormat to use for the resulting texture
linearWhether to use the RenderTextureReadWrite.Linear mode for rendering. Defaults to false.
Returns
Scaled texture

◆ RenderMaterialToTexture2D()

static Texture2D Astra.Asset.TextureUtilities.RenderMaterialToTexture2D ( Material  mat,
bool  debug = false,
Color?  backgroundOverload = null,
bool  linear = false,
int  width = 2048,
int  height = 2048 
)
inlinestatic

Renders a material to a texture, blocking. This is useful for baking complex materials into a single diffuse

Parameters
matThe material you want to bake
debugSet true to keep temporary textures in scene/memory for debugging
backgroundOverloadSet to a color to replace the default color to use in the texture
linearIf true, will render and set colors using linear, you typically do not want this as most colors should be in gamma/sRGB
widthThe width of the output texture
heightThe height of the output texture
Returns
The computed texutre

The documentation for this class was generated from the following file: