【问题标题】:Texture Reading in Fragment Shader片段着色器中的纹理读取
【发布时间】:2019-01-23 06:33:40
【问题描述】:

我正在将纹理传递给片段着色器我想将该像素值中的纹理颜色与蓝色 Alpha 0.2 混合我该怎么做?

片段着色器

fragment float4 bezier_fragment(VertexOutBezier params[[stage_in]],
                                texture2d<float> texture [[texture(0)]]

VertexOutBezier

struct VertexOutBezier {
    float4 pos[[position]];
    float4 color;

};

目前我正在这样做,但在示例中的此着色器函数中出现错误。 "No matching member function for call to 'sample'" 在 float canvasColor Initialization 行中

fragment float4 bezier_fragment(VertexOutBezier params[[stage_in]],
                                texture2d<float> texture [[texture(0)]]
                                )
{
    constexpr sampler defaultSampler;
    float4 canvasColor = texture.sample(defaultSampler, params.pos);
    float4 finalColor = mix(canvasColor, params.color, 0.2);
    return finalColor;
}

【问题讨论】:

  • 当您发布这样的问题时,您应该逐字显示完整编译器输出。

标签: ios swift metal metalkit


【解决方案1】:

替换这一行:

float4 canvasColor = texture.sample(defaultSampler, params.pos);

float4 canvasColor = texture.sample(defaultSampler, params.pos.xy);

2D 纹理由 2 个坐标采样,您提供了 4 个。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-04
    相关资源
    最近更新 更多