textureGrad function – Metal (MSL) equivalent

Viewed 200

I'm currently trying to reimplement this technique for variation in tiling texture repetition – https://www.iquilezles.org/www/articles/texturerepetition/texturerepetition.htm – in Metal.

Some parts of the code refer to the textureGrad function (https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureGrad.xhtml). As it's not totally clear to me how this is implemented under the hood I wanted to ask if there is a MSL equivalent that I haven't found yet or maybe someone could give me a hint on how to reimplement it.

Thank you!

1 Answers

MSL equivalent:

fragment float4 Fragment(ColorInOut in [[stage_in]],
                            texture2d<float> texture [[texture(0)]])
{
    constexpr sampler sampleFilter(mip_filter::linear, mag_filter::linear, min_filter::linear);
    float4 color = texture.sample(sampleFilter, in.texCoord.xy, gradient2d(0, 0));
    return float4(color);
}
Related