I'm trying to learn MSL through the Metal Shading Language Specification, and saw that you can set LOD options when sampling a texture by specifying the options in the sample
function. This is one of the examples given in the spec:
Tv sample(sampler s, float2 coord, lod_options options, int2 offset = int2(0)) const
lod_options
include bias, level, gradient2d, etc.
I've looked all over but cannot find the usage syntax for this. Are these named arguments? Is lod_options
a struct? For example, if I want to specify the LOD level, what is the correct way to do it? I know these options can also be specified in the sampler object itself, but if I want to do it here, what would be the right syntax to do so?
There is no lod_options
type as such; you can think of it as a placeholder for one of the bias
, level
, gradient2d
, etc. types. Each of these types is a different struct, which allows the Metal standard library to have an overloaded variant of the sample
function for each such option.
To specify, for example, the mipmap level to sample, you'd provide a parameter of level
type:
float4 color = myTexture.sample(mySampler, coords, level(1));