metal - Mac 应用程序的金属帧缓冲颜色
问题描述
如何在我的着色器中为 mac 应用程序读取帧缓冲区当前颜色。我很容易使用 [[color(0)]] 在 ios 应用程序中做同样的事情。
我尝试使用如下所示的纹理,一些像素被遗漏了。
texture2d_array normal_1 [[纹理(0)]]
示例代码
fragment float4 funcname(QuadFragIn inFrag [[ stage_in ]],
texture2d_array<float> normal_1 [[texture(0)]])
{
float4 color_0 = float4(normal_1.sample(tex_sampler, inFrag.m_TexCoord, 0));
float4 color_1 = float4(normal_1.sample(tex_sampler, inFrag.m_TexCoord, 1));
float4 color_2 = float4(normal_1.sample(tex_sampler, inFrag.m_TexCoord, 2));
int index = inFrag.index;
if(index == 0)
{
return color_0;
}
else if(index == 1)
{
return color_1;
}
else
{
return color_2;
}
}[![enter image description here][1]][1]
在输出文件附件中,白条是相关问题。
解决方案
根据金属着色语言规范(https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf,表 12 下的注释)
对于
[[color(m)]]
, m 用于在片段函数中访问(读取或写入)多个颜色附件时指定颜色附件索引。该[[color(m)]]
属性仅在 iOS 中受支持。
这意味着您不能进行像素回读(从同一渲染通道中的附加纹理中读取已经渲染的像素)。
避免必须进行像素回读的一种方法是在单独的渲染通道中进行像素写入和读取:您在第一个渲染通道中渲染您想要的内容,然后将第一个渲染通道的结果附加为纹理,您可以对其进行采样或读取.
推荐阅读
- xctest - xcodebuild error DVTAssertions: ASSERTION FAILURE while execution single command line test,但所有测试用例命令工作正常
- nginx - 如何创建子域
- c++ - 使用 ifstream,被调用文件中的数据不打印
- c# - 哪个构建操作 (C# Microsoft Visual Studio) 适合启动在 Windows 窗体中具有零个或多个依赖项的 .exe 软件?
- java - 带有 Maven 的 Java 自动模块
- php - 在jQuery中解析数组的JSON数组
- linq - 如何在 mvc 中使用 linq 处理大量数据
- google-cloud-firestore - 如何从两个不同的 Firestore 查询构建 ListView?
- python - 如何在 django restframework 中反转 ViewSet 的自定义操作的 URL
- zsh - zsh 如何解释 shebangs 中的非绝对路径?(WAS:为什么 python3 -i 允许 shebang 中的非绝对路径?)