gpt4 book ai didi

ios - SCNTechnique 的 DRAW_QUAD channel 中来自 ARSCNView 的空白深度缓冲区

转载 作者:可可西里 更新时间:2023-11-01 04:55:06 25 4
gpt4 key购买 nike

我正在尝试在 AR SceneKit 演示的后处理步骤中进行深度测试。为此,我需要渲染 ARSCNView 的深度图。使用 SCN 技术似乎不可能得到它。

当尝试使用 DRAW_SCENE channel 的深度作为 SCNTechnique 中 DRAW_QUAD channel 的输入时,我不断得到空白(充满 1.0-s)深度缓冲区。我已按照 SCNTechnique 上的指南进行操作并命名深度目标。这是 SCNTechnique 实现中的错误,还是我在配置中遗漏了什么?

颜色缓冲区链接正确,示例来自 https://github.com/lachlanhurst/SCNTechniqueTest/tree/pixelate有效。

这是 Metal 技术的调试 View ,如您所见,深度缓冲区是完全白色的。 Metal shader debug view

这是技术 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 正确设置管道可能有些棘手,但只要所有问题都正确,它就会起作用。

关于ios - SCNTechnique 的 DRAW_QUAD channel 中来自 ARSCNView 的空白深度缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52494738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com