片段着色器中的简单径向渐变创建带

问题描述

我正在渲染半径为0.5(在GPU坐标中)的圆/椭圆,并使用以下着色器功能

#include <Metal_stdlib>
using namespace Metal;

struct VertexIn {
  float4 position [[ attribute(0) ]];
};

struct VertexOut {
  float4 position [[ position ]];
  float4 gpuPosition [[ attribute(1) ]];
};

vertex VertexOut vertex_main(const VertexIn vertex_in [[ stage_in ]]) {
  return VertexOut {
    .position = vertex_in.position,.gpuPosition = vertex_in.position
  };
}

fragment float4 fragment_main(VertexOut in [[ stage_in ]]) {
  float d = distance(in.gpuPosition.xyz,float3(0,0));
  float radius = 0.5;
  float soften = 10;
  float final = (1 - d / radius) / soften;
  return float4(final,final);
}

soften = 1时,渐变看起来非常平滑。当我将其提高到10或更高时,您会开始看到条带而不是平滑的渐变。这是在Xcode中的Metal调试器中的外观:

Xcode Screenshot

(注意:我缩小了alpha窗口以使效果更明显,否则很难在屏幕截图中看到)

什么原因导致条带效应?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)