从剪辑空间到屏幕坐标的转换何时发生? [英] When does the transition from clip space to screen coordinates happen?

查看:184
本文介绍了从剪辑空间到屏幕坐标的转换何时发生?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究渲染流水线,当我到达剪切阶段时,我们向视频(眼睛或相机)空间中的进行了解释,我们必须将其传递到剪辑空间,也称为规范化设备空间(NDC),即从-1到1的立方空间。但是,现在我不明白何时从这个空间发生在屏幕坐标空间上:


  1. 在裁剪之后和光栅化之前?

  2. 在光栅化和剪刀和z测试之前?

  3. 不,剪辑空间和NDC空间不是一回事。

    剪辑空间实际上是一步远离NDC,所有坐标除以 Clip.W 来生成NDC。结果NDC空间范围[ -1 1 ]之外的任何内容都对应于裁剪卷外的点。 NDC之前的坐标空间有一个原因称为片段空间;)

    严格地说,NDC空间不一定是立方体。的确,NDC空间在OpenGL中是一个立方体,但在Direct3D中它不是。在D3D中,NDC空间中的Z坐标从 0.0 1.0 ,范围从 -1.0 1.0 在GL中。 GL和D3D中的X和Y表现相同(也就是说,它们的范围从 -1.0 1.0 )。 NDC是一个标准坐标空间,但它在不同的API中具有不同的表示形式。最后,NDC空间到屏幕空间(AKA窗口空间)发生在光栅化过程中,并由您的视口和深度范围。片段位置在任何其他坐标空间中都没有意义,这就是栅格化所产生的结果: fragment




    更新:



    在OpenGL 4.5中引入了 GL_ARB_clip_control 允许您在GL中采用D3D的NDC约定。





    传统的OpenGL行为是:



      glClipControl(GL_LOWER_LEFT,GL_NEGATIVE_ONE_TO_ONE); 



    Direct3D行为可以通过以下方式实现:



      glClipControl(GL_UPPER_LEFT,GL_ZERO_TO_ONE); // Y轴在D3D 
    中倒置


    I was studying the rendering pipeline and when I got to the clipping stage it was explained that from the view (eye or camera) space we have to pass to the clip space, also called normalized device space (NDC), that is a cubic space from -1 to 1.

    However, now I don't understand when the passage from this space to the screen coordinates space happens:

    1. Right after clipping and before rasterization?

    2. After rasterization and before scissor and z-test?

    3. At the end just before writing on the frame buffer?

    解决方案

    No, clip space and NDC space are not the same thing.

    Clip space is actually one step away from NDC, all coordinates are divided by Clip.W to produce NDC. Anything outside of the range [-1,1] in resulting NDC space corresponds to a point that is outside of the clipping volume. There is a reason the coordinate space before NDC is called clip space ;)

    Strictly speaking, however, NDC space is not necessarily cubic. It is true that NDC space is a cube in OpenGL, but in Direct3D it is not. In D3D the Z coordinate in NDC space ranges from 0.0 to 1.0, while it ranges from -1.0 to 1.0 in GL. X and Y behave the same in GL and D3D (that is, they range from -1.0 to 1.0). NDC is a standard coordinate space, but it has different representation in different APIs.

    Lastly, NDC space to screen space (AKA window space) occurs during rasterization and is defined by your viewport and depth range. Fragment locations really would not make sense in any other coordinate space, and this is what rasterization produces: fragments.


    Update:

    Introduced in OpenGL 4.5, the extension GL_ARB_clip_control allows you to adopt D3D's NDC convention in GL.

    Traditional OpenGL behavior is:

    glClipControl (GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
    

    Direct3D behavior can be achieved through:

    glClipControl (GL_UPPER_LEFT, GL_ZERO_TO_ONE); // Y-axis is inverted in D3D
    

    这篇关于从剪辑空间到屏幕坐标的转换何时发生?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆