简体   繁体   English

金属着色器中采样器 lod_options (MSL) 的正确用法是什么?

[英]What is the correct usage of sampler lod_options (MSL) in Metal shader?

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.我正在尝试通过Metal Shading Language Specification学习 MSL,并且看到您可以在采样纹理时通过指定sample函数中的选项来设置 LOD 选项。 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. lod_options包括bias、level、gradient2d 等。

I've looked all over but cannot find the usage syntax for this.我已经查看了所有内容,但找不到用于此的使用语法。 Are these named arguments?这些是命名参数吗? Is lod_options a struct? lod_options是结构吗? For example, if I want to specify the LOD level, what is the correct way to do it?例如,如果我想指定 LOD 级别,那么正确的做法是什么? 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;没有lod_options类型; you can think of it as a placeholder for one of the bias , level , gradient2d , etc. types.您可以将其视为biaslevelgradient2d等类型之一的占位符。 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.这些类型中的每一种都是不同的结构,它允许 Metal 标准库为每个此类选项具有sample函数的重载变体。

To specify, for example, the mipmap level to sample, you'd provide a parameter of level type:例如,要指定要采样的 mipmap 级别,您需要提供level类型的参数:

float4 color = myTexture.sample(mySampler, coords, level(1));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM