Texture Sampling Choices

I’m generating a sampler of sampling modes to better understand the different modes.

https://playground.babylonjs.com/#85CZC6#1

Two questions:

  1. Besides
    BABYLON.Texture.NEAREST_SAMPLINGMODE, // 1
    BABYLON.Texture.BILINEAR_SAMPLINGMODE, // 2 and
    BABYLON.Texture.TRILINEAR_SAMPLINGMODE, // 3
    what are the possible sampling modes, if any (I see many constants in Texture that do not contain “SAMPLINGMODE”)?
    and
  2. When are BILINEAR and TRILINEAR effectively different (how can I show the difference in a sampler)?
    (I suspect that these questions are broader then they appear. Suggestions of what to read are welcome.)

Hey hey!
Here are all the choices you have:
Babylon.js/texture.ts at 2b72313def0986eb49d30dbd36a9d80e6505c33c · BabylonJS/Babylon.js (github.com)

TRILINEAR is BILINEAR filtering with LINEARING filtering of the mip maps as well

2 Likes

NEAREST_SAMPLINGMODE is an alias for NEAREST_NEAREST.
BILINEAR_SAMPLINGMODE is an alias for LINEAR_LINEAR.
TRILINEAR_SAMPLINGMODE is an alias for LINEAR_LINEAR_MIPLINEAR.

The naming of the sampling mode constant has this scheme: X_Y_MIPZ, with _MIPZ being optional (in that case, it means there won’t be any mipmap selection/filtering).

X applies when the texture is magnified (meaning it is displayed bigger than its natural size), Y applies when it is minified (meaning it is displayed smaller than its natural size), Z applies on mipmaps (so it can only apply when a texture is minified).

The values of X/Y/Z can be either LINEAR or NEAREST, the former meaning there will be an interpolation between texels, the latter meaning the GPU will pick a single value (no interpolation).

So, you can see you can have 8 different combinations for X_Y_MIPZ. But there are also 4 combinations without _MIPZ in the name (only X_Y), meaning there won’t be any mipmap selection at all. When you use MIPNEAREST, you will still pick a value from the nearest mipmap, whereas if you don’t use _MIPZ you will pick a value directly from the regular texture (even if minified), not from a mipmap.

3 Likes

Found this as a good description of the underlying OpenGL textures: https://learnopengl.com/Getting-started/Textures

See https://playground.babylonjs.com/#85CZC6#2 for a sampler of:
BABYLON.Texture.LINEAR_LINEAR, // Same as BILINEAR_SAMPLINGMODE
BABYLON.Texture.LINEAR_NEAREST,
BABYLON.Texture.NEAREST_LINEAR,
BABYLON.Texture.NEAREST_NEAREST, // Same as NEAREST_SAMPLINGMODE
with various texture sizes

2 Likes