Texture sampler

Texture sampler

Sampling functions

Return type

Description

int

textureFilter enumeration
Can be passed in the filterMode argument of the sampling functions below.

  1. textureFilter.point: No interpolation (nearest sample)

  2. textureFilter.linear: Linear interpolation between the 4 nearest texels

int

textureAddr enumeration
Can be passed in the wrapMode argument of the sampling functions below.

  1. textureAddr.clamp: Clamps UV coordinates to the [0, 1] range

  2. textureAddr.wrap: Wraps UV coordinates that are outside the [0, 1] range back into [0, 1] ("Repeat" mode)

float4

SamplerName.sample(float2 uv [, int filterMode [, int wrapMode]])
Samples a texel on the texture at the specified UV coordinates in parameter uv.

float4

SamplerName.sample(float subRectId, float2 uv [, int filterMode [, int wrapMode]])
Samples a texel on the texture atlas at the specified UV coordinates in parameter uv and atlas tile subRectId.
subRectId is in the [0, atlasRectCount-1] range

float2

SamplerName.remapDensity(float2 uv [, int filterMode [, int wrapMode]])
Builds a new UV from the input uv so that the final UV distribution matches the density of the texture.

float2

SamplerName.remapDensity(float subRectId, float2 uv [, int filterMode [, int wrapMode]])
Builds a new UV from the input uv so that the final UV distribution matches the density of the texture atlas tile subRectId.
subRectId is in the [0, atlasRectCount-1] range

float2

SamplerName.sampleDensity([int filterMode [, int wrapMode]])
Builds a random UV coordinate so that the final UV distribution matches the density of the texture.

float2

SamplerName.sampleDensity(float subRectId [, int filterMode [, int wrapMode]])
Returns a float2 containing the texture texel dimensions.
(can be just an abstract aspect ratio if the sampler is an attribute sampler overriden by the game engine and is a procedural 'infinite' texture rather than a physical texture).

float4

SamplerName.read(int texelId) [v2.16.0]
Performs a fast direct-read of the texture using the input texelId. In a 64x64 texture, calling the function with ID = 0 will output the value of the first texel, calling it with ID = 63 will read the last texel of the first row, ID = 4095 will read the last texel of the last row. You can use the texel*ToID() set of functions to convert from UVs or x,y texel coordinates to flat texelIDs suitable to give to this function.

float

SamplerName.readChannel(int texelId, int channelId) [v2.16.0]
Performs a fast direct-read of the texture using the input texelId. The function will output the channel channelID of the texel.
channelID must be a per-wave or constant value, and cannot vary per-particle. The accepted values are 0, 1, 2, or 3, for R, G, B, and A channels respectively.
See the wave functions scripting page for more information on per-waves values.

int2

SamplerName.texelUVToCoords(float2 uv [, int wrapMode]) [v2.16.0]
Converts from [0,1] UV coordinates to x,y integer texel coordinates.

int

SamplerName.texelUVToID(float2 uv [, int wrapMode]) [v2.16.0]
Converts from [0,1] UV coordinates to flat texel IDs.

float2

SamplerName.texelCoordsToUV(int2 texelCoords) [v2.16.0]
Converts from x,y integer texel coordinates to [0,1] UV coordinates.

int

SamplerName.texelCoordsToID(int2 texelCoords) [v2.16.0]
Converts from x,y integer texel coordinates to flat texel IDs.

float2

SamplerName.texelIDToUV(int texelId) [v2.16.0]
Converts from flat texel IDs to [0,1] UV coordinates.

int2

SamplerName.texelIDToCoords(int texelId) [v2.16.0]
Converts from flat texel IDs to x,y integer texel coordinates.

float2

SamplerName.texelUVToFrac(float2 uv [, int wrapMode]) [v2.16.0]
Extracts the fractional sub-texel lerp factors from the input UV.

float2

SamplerName.texelSubUVToGlobalUV(float2 uv, float subRectId [, int wrapMode]]) [v2.16.0]
Converts a sub-UV in the image atlas at the specified UV coordinates uv and atlas tile subRectId, into a global texture UV suitable to then be converted to flat IDs or x,y integer texel coordinates.

Properties

Return type

Description

float2

SamplerName.dimensions()
Returns a float2 containing the texture texel dimensions.

int

SamplerName.atlasRectCount()
Returns the number of sub-rectangles in the texture atlas. Returns zero if there’s no atlas.

Note: These are describing the reference implementation. When using attribute samplers, the behavior of these functions can vary depending on the implementation in the game-engine where the effect is loaded.