【问题标题】:Specify sampling method in Metal Core Image Kernel在 Metal Core Image Kernel 中指定采样方法
【发布时间】:2022-02-05 21:27:53
【问题描述】:

在 Metal 中,我们可以像这样创建采样器

      constexpr sampler s(coord::normalized, address::clamp_to_edge, filter::linear);

然后我们可以使用这个采样器对任何纹理进行采样。

我想知道 Metal Core Image Kernels 中是否有类似的东西。

【问题讨论】:

    标签: ios metal core-image metalkit ciimage


    【解决方案1】:

    是的,有!你可以使用CISampler,而不是CIImage

    let sampler = CISampler(image: image, options: [
        kCISamplerWrapMode: kCISamplerWrapClamp,
        kCISamplerFilterMode: kCISamplerFilterLinear
    ])
    

    您还可以在options 中设置kCISamplerAffineMatrix 以定义在采样时应用于坐标的变换(我认为normalized 是默认行为)。

    或者,您可以在CIImage 上使用这些便利助手来设置包装和过滤模式:

    // for linear & clamp-to-edge
    let newImage = image.samplingLinear().clampedToExtent()
    // for nearest & clamp-to-black (actually transparent, not black)
    let newImage = image.samplingNearest().cropped(to: aRect)
    

    使用这些方法,您还可以强制内置过滤器使用相应的模式。

    【讨论】:

    • 请看this问题。我对采样器的疑虑越来越大!
    • 还有另一个与采样有关的one。请看一看。
    • 你知道如何将现有的Metal片段着色器转换为Core Image Kernel吗?如果在 Metal 片段着色器中我们使用插值顶点坐标对片段着色器中的所有纹理进行采样,那么 Core Image Kernel 中的等价物是什么?
    • 恐怕我不太明白... CI 内核是计算(不是片段)着色器。像素值将根据采样器设置(线性或最近)在坐标之间插值。
    • 我明白了。我所坚持的是将用 Metal vertex/fragment shader 编写的代码准确地转换为计算着色器(CIKernel)。
    猜你喜欢
    • 1970-01-01
    • 2021-06-28
    • 2020-10-28
    • 1970-01-01
    • 2017-01-25
    • 2022-01-08
    • 1970-01-01
    • 2016-07-13
    • 2018-07-21
    相关资源
    最近更新 更多