简体   繁体   English

金属深度2d的最大值<float> /Depth32Float 使用 SceneKit 时</float>

[英]Maximum value of metal depth2d<float>/Depth32Float when using SceneKit

I'm using an SCNTechnique with SceneKit to implement my own multipass rendering.我正在使用带有 SceneKit 的 SCNTechnique 来实现我自己的多通道渲染。 I have 1 DRAW_SCENE pass that outputs to separate colour and depth targets, and then a second DRAW_QUAD pass that uses those targets and outputs to COLOR.我有 1 个 DRAW_SCENE 通道输出到单独的颜色和深度目标,然后有第二个 DRAW_QUAD 通道使用这些目标并输出到颜色。

It's all working great, my only question is what the range of values for the depth target are?一切都很好,我唯一的问题是深度目标的值范围是多少? I'd like to normalise them between 0 and 1, but unsure what the maximum SceneKit produces is when it arrives in my fragment shader as a depth2d sampler.我想将它们标准化为 0 和 1 之间,但不确定 SceneKit 产生的最大值是当它作为 depth2d 采样器到达我的片段着色器时。 The largest value I've seen in the debugger when inspecting frames is 0.129, I'm sure that's not the max, but no idea what is.检查帧时我在调试器中看到的最大值是 0.129,我确定这不是最大值,但不知道是什么。

fragment half4 depth_of_field_fragment(out_vertex_t vert [[stage_in]],
                                       texture2d<float, access::sample> colorSampler [[texture(0)]],
                                       depth2d<float, access::sample> depthSampler [[texture(1)]],
                                       texture2d<float, access::sample> pixelatedSampler [[texture(2)]])
{
    float depth = depthSampler.sample(nearestSampler, vert.uv); //range 0 to ??? max I've seen is 0.129
    float normalisedDepth = depth * ???; // range 0 to 1.0
    if (normalisedDepth > 0.8) {
        return half4(colorSampler.sample(linearSampler, vert.uv));
    } else {
        return half4(pixelatedSampler.sample(nearestSampler, vert.uv));
    }
};

单个通道,1 个 DRAW_SCENE 通道,前哨到颜色和深度目标,然后是一个 DRAW_QUAD 通道,使用这些目标并输出到 COLOR

序列,由一个颜色和深度通道组成,然后是一个使用这两者的通道

SceneKit depth values are in the [0,1] range. SceneKit 深度值在[0,1]范围内。

Depending on the usesReverseZ property the near plane has a depth value of 1 (resp. 0 ) and the far plane a depth value of 0 (resp. 1 ).根据usesReverseZ属性,近平面的深度值为1 (resp. 0 ),远平面的深度值为0 (resp. 1 )。 You can have a look atDepth Precision Visualized for more information on that.您可以查看Depth Precision Visualized了解更多信息。

The related SCNCamera APIs are zNear , zFar and automaticallyAdjustsZRange .相关的SCNCamera API 是zNearzFarautomaticallyAdjustsZRange

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM