简体   繁体   中英

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

I'm using an SCNTechnique with SceneKit to implement my own multipass rendering. 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.

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. 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.

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.

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 ). You can have a look atDepth Precision Visualized for more information on that.

The related SCNCamera APIs are zNear , zFar and automaticallyAdjustsZRange .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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