xcode - 金属着色器混合片段接收错误的颜色值
问题描述
我在金属中有 2 次通行证:
1 - 节点通行证
2 - mix_pass
用 xCode 调试它:
fragment half4 node_fragment (NodeColorInOut vert [[stage_in]])
{
float4 color = float4((vert.center.x + 1.0) * 0.5 , (vert.center.y + 1.0) * -0.5, 0.0, 0.0);
return half4(color);
}
vert.center是在node_vertex计算的来自节点中心的数据。不管为什么。我有我的理由。
从 XCODE 调试器中,我可以确认“float4 color”返回 [ 0.416 , -0.345,0.0,0.0 ]。这意味着它使用 Y ([1]) 值 -0.345 正确返回了 half4 颜色。
到目前为止,一切都很好!
问题是当它进入 mix_pass 时。
- 混合顶点:
vertex MixColorInOut mix_vertex (VertexInput in [[stage_in]],
constant SCNSceneBuffer & scn_frame [[buffer (0)]])
{
MixColorInOut out;
out.position = in.position;
out.uv = float2 ((in.position.x + 1.0) * 0.5, (in.position.y + 1.0) * -0.5);
return out;
}
- 混合片段:
fragment half4 mix_fragment (MixColorInOut vert [[stage_in]],
texture2d <float, access :: sample> colorScene [[texture (0)]],
depth2d <float, access :: sample> depthScene [[texture (1)]],
texture2d <float, access :: sample> colorNode [[texture (2)]],
depth2d <float, access :: sample> depthNode [[texture (3)]])
{
…
// this part runs only when it's a pixel inside the node
float3 center_map = colorNode.sample(s, vert.uv).rgb;
…
}
在调试器中(选择节点内的像素) float3 center_map为 [0.416, 0.0 ,0.0,0.0]。
0.0对于第二个组件,它应该是-0.345。
这是为什么?这很疯狂,因为 node_fragment 的调试器显示 Y ([1]) 的值为-0.345。
理论上,它应该是之前通过调试器确认的确切颜色值 [0.416, -0.345 ,0.0,0.0]。
当我执行 center_map.x 时,它返回正确的值 0.416,这意味着它正在从 node_fragment 获取 x 颜色值。
但是当我做center_map.y时,它是 0.0,这不是 node_fragment 的调试器中显示的值。
任何线索这里有什么问题?
解决方案
第一次使用什么像素格式?大多数像素格式都是unsigned,包括MTLPixelFormatBGRA8Unorm_sRGB
SceneKit 默认使用的格式。
如果您只使用两个颜色组件MTLPixelFormatRG32Float
是一个不错的选择。
推荐阅读
- r - R:创建具有阳性测试结果的频率表
- android - 如何让我的应用程序将从 android 设备上卸载
- azcopy - 如何使用 azcopy 版本 10.3.0 使用 powershell 将文件从 Blob 存储复制然后删除到 VM
- php - 如何在用户上次登录时订购帖子?
- spring - 控制建议如何捕获异常
- python - Python使用循环来制作公式
- python-3.x - How to extract data to a file using scrapy?
- java - Thymeleaf: display global errors by error code
- php - How to correctly construct a SOAP request to use in __SoapCall?
- ruby-on-rails - 使用 belongs_to 关系进行编辑