我正在尝试在AR SceneKit演示的后处理步骤中进行深度测试。为此,我需要渲染器ARSCNView的深度图。使用SCNTechnique似乎无法获得它。
当尝试将DRAW_SCENE传递的深度用作SCNTechnique的DRAW_QUAD传递的输入时,我一直保持空白(充满1.0-s)深度缓冲区。 我遵循了SCNTechnique上的指南,并命名了深度目标。 这是SCNTechnique实施中的错误,还是我在配置中缺少某些内容?
颜色缓冲区已正确链接,https://github.com/lachlanhurst/SCNTechniqueTest/tree/pixelate中的示例有效。
这是技术列表:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>passes</key>
<dict>
<key>pixelate_scene</key>
<dict>
<key>draw</key>
<string>DRAW_SCENE</string>
<key>inputs</key>
<dict/>
<key>outputs</key>
<dict>
<key>color</key>
<string>color_scene</string>
<key>depth</key>
<string>depth_scene</string>
</dict>
<key>colorStates</key>
<dict>
<key>clear</key>
<true/>
<key>clearColor</key>
<string>sceneBackground</string>
</dict>
</dict>
<key>resample_pixelation</key>
<dict>
<key>draw</key>
<string>DRAW_QUAD</string>
<key>program</key>
<string>doesntexist</string>
<key>metalVertexShader</key>
<string>pixelate_pass_through_vertex</string>
<key>metalFragmentShader</key>
<string>pixelate_pass_through_fragment</string>
<key>inputs</key>
<dict>
<key>colorSampler</key>
<string>color_scene</string>
<key>depthSampler</key>
<string>depth_scene</string>
</dict>
<key>outputs</key>
<dict>
<key>color</key>
<string>COLOR</string>
</dict>
</dict>
</dict>
<key>sequence</key>
<array>
<string>pixelate_scene</string>
<string>resample_pixelation</string>
</array>
<key>targets</key>
<dict>
<key>color_scene</key>
<dict>
<key>type</key>
<string>color</string>
</dict>
<key>depth_scene</key>
<dict>
<key>type</key>
<string>depth</string>
</dict>
</dict>
<key>symbols</key>
<dict/>
</dict>
</plist>
着色器如下所示:
#include <metal_stdlib>
#include <metal_geometric>
using namespace metal;
#include <SceneKit/scn_metal>
struct custom_vertex_t
{
float4 position [[attribute(SCNVertexSemanticPosition)]];
};
constexpr sampler s = sampler(coord::normalized,
address::repeat,
filter::nearest);
struct out_vertex_t
{
float4 position [[position]];
float2 uv;
};
vertex out_vertex_t pixelate_pass_through_vertex(custom_vertex_t in [[stage_in]], constant SCNSceneBuffer& scn_frame [[buffer(0)]])
{
out_vertex_t 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 pixelate_pass_through_fragment(out_vertex_t vert [[stage_in]], texture2d<float, access::sample> colorSampler [[texture(0)]], texture2d<float, access::sample> depthSampler [[texture(1)]])
{
float4 fragment_color = colorSampler.sample( s, vert.uv);
float ar_depth = depthSampler.sample(s, vert.uv).r;
return half4(fragment_color * 0.5 + float4(ar_depth) * 0.5);
};
答案 0 :(得分:0)
在片段着色器中,depthSampler
的类型应为depth2d
而不是texture2d
。使用SCNTechnique
正确设置管道可能有些棘手,但是一旦所有难题都解决了,它就可以工作。