Intrinsics2 min read

sample_bias

Samples a texture with a LOD bias.

Reading Time
2 min
Word Count
193
Sections
12
Try It Live

Test sample_bias in a live shader

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

Open Playground

Live Demo

The sample_bias function reads a texture with an added bias to the automatically computed mip level. This can sharpen or blur the result.

Signature

bwsl
sample_bias :: (texture2D tex, sampler samp, float2 uv, float bias) -> float4 {...}

Parameters

ParameterTypeDescription
textexture2DThe texture to sample
sampsamplerSampler state
uvfloat2Texture coordinates
biasfloatLOD bias (negative = sharper, positive = blurrier)

Return Value

Returns the texel value with the biased mip level.

Example

bwsl
pipeline SharpTextures {
@fragment_only
fragment {
// Sample with sharpening bias for distant textures
float dist = length(input.worldPos - cameraPos);
float sharpenBias = -0.5; // Negative = sharper
// Apply stronger sharpening at distance
float bias = lerp(0.0, sharpenBias, saturate(dist / 100.0));
float4 color = sample_bias(resources.albedoTex, resources.linearSampler, input.uv, bias);
output.color = color;
}
}

Common Use Cases

Texture Sharpening

bwsl
// Sharpen textures slightly
float4 sharp = sample_bias(resources.tex, resources.linearSampler, uv, -0.5); // Use lower mip

Distance-Based Blur

bwsl
// Blur distant objects
float blurAmount = saturate(distance / maxDist) * 2.0;
float4 blurred = sample_bias(resources.tex, resources.linearSampler, uv, blurAmount);

Material Roughness Hint

bwsl
// Suggest blurrier appearance for rough materials
float roughnessBias = roughness * 1.5;
float4 diffuse = sample_bias(resources.diffuseTex, resources.linearSampler, uv, roughnessBias);

Anti-Aliasing Adjustment

bwsl
// Reduce aliasing on high-frequency textures
float4 color = sample_bias(resources.detailTex, resources.linearSampler, uv * 10.0, 0.5);

LOD Debugging

bwsl
// Force higher mip levels for testing
float4 debugMip = sample_bias(resources.tex, resources.linearSampler, uv, debugBias);

Bias Values

  • Negative bias: Uses a smaller mip level (sharper, more aliasing)
  • Zero bias: Normal automatic LOD selection
  • Positive bias: Uses a larger mip level (blurrier, less detail)

Fragment Shader Only

sample_bias relies on automatic LOD calculation, which is only available in fragment shaders. Use sample_lod in vertex or compute shaders.

Typical Values

  • Sharpening: -0.5 to -1.0
  • Subtle blur: 0.5 to 1.0
  • Strong blur: 1.0 to 3.0

Compiled Output

When compiled to GLSL:

glsl
texture(tex, uv, bias)

When compiled to HLSL:

hlsl
tex.SampleBias(samplerState, uv, bias)

When compiled to Metal:

metal
tex.sample(sampler, uv, bias(biasValue))

See Also