首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在SCNTechnique的DRAW_QUAD传递中来自ARSCNView的空白深度缓冲区

在SCNTechnique的DRAW_QUAD传递中来自ARSCNView的空白深度缓冲区
EN

Stack Overflow用户
提问于 2018-09-25 17:23:32
回答 1查看 438关注 0票数 5

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

当我尝试使用DRAW_SCENE传递的深度作为SCNTechnique中DRAW_QUAD传递的输入时,我总是得到空白(满是1.0秒)的深度缓冲区。我遵循了SCNTechnique上的指南,并将深度目标命名为。这是SCNTechnique实现中的一个错误,还是我在配置中遗漏了什么?

颜色缓冲区链接正确,https://github.com/lachlanhurst/SCNTechniqueTest/tree/pixelate中的示例可以正常工作。

这是金属技术的调试视图,如您所见,深度缓冲区是完全白色的。

这里是技术plist:

代码语言:javascript
复制
<?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>

着色器如下所示:

代码语言:javascript
复制
#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);
};
EN

回答 1

Stack Overflow用户

发布于 2019-06-29 15:07:13

在片段着色器中,depthSampler的类型应为depth2d,而不是texture2d。使用SCNTechnique正确设置管道可能有点棘手,但一旦所有的难题都解决了,它就可以工作了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52494738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档