[英]SCNTechnique on ARSCNView does not affect CameraFeed (Scene Background) on iOS 13
[英]Blank depth buffer from ARSCNView in DRAW_QUAD pass of SCNTechnique
我正在尝试在AR SceneKit演示的后处理步骤中进行深度测试。 我需要渲染渲染ARSCNView的深度图。 使用SCNTechnique似乎无法获得它。
当我尝试使用DRAW_SCENE传递的深度作为SCNTechnique中DRAW_QUAD传递的输入时,我一直变为空白(充满1.0秒)深度缓冲区。 我跟随SCNTechnique的指南并命名了深度目标。 这是SCNTechnique实现中的错误,还是我在配置中遗漏了什么?
颜色缓冲区链接正确, https://github.com/lachlanhurst/SCNTechniqueTest/tree/pixelate中的示例有效。
这是技术plist:
<?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);
};
在片段着色器中, depthSampler
的类型应为depth2d
而不是texture2d
。 使用SCNTechnique
正确设置管道可能有点棘手,但只要拼图的所有和平正确,它就会起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.