Intrinsics1 min read

sample_offset

Samples a texture with an integer texel offset.

Reading Time
1 min
Word Count
118
Sections
7
Try It Live

Test sample_offset in a live shader

Open the playground, start from a visual preset, and wire sample_offset into the fragment stage to see how it behaves with real values.

Open Playground

The sample_offset function samples a texture at UV coordinates plus a constant integer texel offset. Use it for small fixed kernels such as blur taps, edge detection, and neighborhood lookups that still use filtered sampling.

Live Demo

Signature

bwsl
sample_offset :: (texture2D tex, sampler samp, float2 uv, int2 offset) -> float4 {...}

Parameters

ParameterTypeDescription
textexture2DTexture to sample
sampsamplerSampler state
uvfloat2Texture coordinates
offsetint2Integer texel offset applied to the sample

Return Value

Returns the filtered sample value from the offset texture coordinate.

Example

bwsl
float4 center = sample(resources.albedo, resources.albedoSampler, uv);
float4 right = sample_offset(resources.albedo, resources.albedoSampler, uv, int2(1, 0));
float4 up = sample_offset(resources.albedo, resources.albedoSampler, uv, int2(0, 1));

Compiled Output

When compiled to GLSL:

glsl
textureOffset(tex, uv, offset)

See Also