Textures

Textures offer a way to store 2d (3d not yet supported) data on the GPU. They can be used to store images, but also other data like heightmaps, particle positions, etc.

They can be created manually, or loaded in via load().

Creating a texture

By default shadeup assumes 32bit floats per channel, but you can also specify a type (more below)

Uploading data to a texture

Much like buffers, you can upload data to a texture by assigning to it.

Downloading data from a texture

And again, like a buffer, you can download data from a texture by calling texture.download().

Sampling a texture in a shader

Textures can be sampled in a shader by using the texture2d.sample(pos: float2) function.

By default textures are sampled with bilinear filtering when available (non-32 bit and non-int) and will not wrap. Currently this behavior is not configurable.

texture.sample() -> float4 always returns a float4 no matter the type of the texture.

Texture formats

By default textures are created with a 32 bit format. You can configure this during creation by specifying a mode:

The following formats are available:

  • 32bit
  • 16bit
  • 8bit
  • depth
  • depth-32

Loading textures

This is a preview of the asset loading guide, but you can load textures like this:

Shadeup comes with a number of built-in assets, but you can also load your own. See the asset loading guide for more information.

Texture arrays

Texture arrays are a way to store multiple textures in a single structure. They can be created like this:

Note: Currently texture arrays are read-only on the GPU.

They can be sampled like this:

Drawing to a texture

Textures can be used as render targets. This is done by using the texture2d.draw() or texture2d.drawXXX() functions.

Internally textures have their own depth buffer if one is not provied