着色器返回原始颜色

时间:2018-08-13 12:05:05

标签: ios swift metal metalkit

我正在绘制一个四边形并附加一个纹理,并且正在使用内核函数绘制一个圆。

kernel void compute(texture2d<float,access::write> output [[texture(0)]],
                     constant float2 &time [[buffer(0)]],
                    uint2 gid [[thread_position_in_grid]])
{
    int width = output.get_width();
    int height = output.get_height();  
    float2 iResolution = float2(width, height); 
    float2 x = time;
    float2 uv = float2(gid.x,height - gid.y) / iResolution;
    uv -= x;  // -0.5 <> 0.5
    float d = length(uv);
    float r = 0.09;
    float c = smoothstep(r, r-0.015, d);
    output.write(float4(float3(c), 1), gid);
}

此处此函数在圆形区域返回白色,在外部返回黑色。我需要外部原始纹理颜色,因为我需要读取传递的纹理并返回颜色。提出一种实现方法

0 个答案:

没有答案
相关问题