OpenGL Transformation 几何变换的顺序概要(MVP,NDC,Window坐标变换过程)

Geometry transforming or culling sequence:

  • application passing the vertex pos(object space pos) to the shader program。
  • transforming of clip space pos from object space pos by mulipling the MVP matrix
    • to world space pos from object space pos by multipling the model/world matrix
      ( x w o r l d y w o r l d z w o r l d ) = M m o d e l / w o r l d ( x o b j y o b j z o b j ) \left( \begin{matrix} x_{\color{#aaaaaa}world}\\ y_{\color{#aaaaaa}world}\\ z_{\color{#aaaaaa}world} \end{matrix} \right)= M_{\color{#aaaaaa}model/world} \left( \begin{matrix} x_{\color{#aaaaaa}obj}\\ y_{\color{#aaaaaa}obj}\\ z_{\color{#aaaaaa}obj} \end{matrix} \right) ​xworld​yworld​zworld​​ ​=Mmodel/world​ ​xobj​yobj​zobj​​ ​
    • to view space pos from world space pos by multipling the view/camera/eye matrix
      • right-hand coordinates
        ( x e y e y e y e z e y e ) = M m o d e l V i e w ( x o b j y o b j z o b j ) = M v i e w ⋅ M m o d e l / w o r l d ( x o b j y o b j z o b j ) \left( \begin{matrix} x_{\color{#aaaaaa}eye}\\ y_{\color{#aaaaaa}eye}\\ z_{\color{#aaaaaa}eye} \end{matrix} \right)= M_{\color{#aaaaaa}modelView} \left( \begin{matrix} x_{\color{#aaaaaa}obj}\\ y_{\color{#aaaaaa}obj}\\ z_{\color{#aaaaaa}obj} \end{matrix} \right)= M_{\color{#aaaaaa}view} \cdot M_{\color{#aaaaaa}model/world} \left( \begin{matrix} x_{\color{#aaaaaa}obj}\\ y_{\color{#aaaaaa}obj}\\ z_{\color{#aaaaaa}obj} \end{matrix} \right) ​xeye​yeye​zeye​​ ​=MmodelView​ ​xobj​yobj​zobj​​ ​=Mview​⋅Mmodel/world​ ​xobj​yobj​zobj​​ ​
    • to projection/clip space pos from view space pos by multipling the projective/clip matrix
      ( x c l i p y c l i p z c l i p ) = M p r o j e c t ( x e y e y e y e z e y e ) \left( \begin{matrix} x_{\color{#aaaaaa}clip}\\ y_{\color{#aaaaaa}clip}\\ z_{\color{#aaaaaa}clip} \end{matrix} \right)= M_{\color{#aaaaaa}project} \left( \begin{matrix} x_{\color{#aaaaaa}eye}\\ y_{\color{#aaaaaa}eye}\\ z_{\color{#aaaaaa}eye} \end{matrix} \right) ​xclip​yclip​zclip​​ ​=Mproject​ ​xeye​yeye​zeye​​ ​

      • culling the vertex which − w c l i p > x y z c l i p > w c l i p -w_{\color{#aaaaaa}clip}>xyz_{\color{#aaaaaa}clip}>w_{\color{#aaaaaa}clip} −wclip​>xyzclip​>wclip​。

        • add edge/vertex when culling occurs。
      • only reserve the vertex which − w c l i p < x y z c l i p < w c l i p -w_{\color{#aaaaaa}clip}<xyz_{\color{#aaaaaa}clip}<w_{\color{#aaaaaa}clip} −wclip​<xyzclip​<wclip​。
      • projection/clip space pos still are Homogeneouse coordinates
        • to perspective effect, transforming to NDC space (Euclidean/Cartesian space) from projection/clip space pos, then dividing by the w c l i p w_{\color{#aaaaaa}clip} wclip​, x y z n d c = x y z c l i p / w c l i p xyz_{\color{#aaaaaa}ndc}=xyz_{\color{#aaaaaa}clip}/w_{\color{#aaaaaa}clip} xyzndc​=xyzclip​/wclip​。
  • to NDC(Normalized Device Coordinates) space, just using clip space pos divide by w c l i p w_{\color{#aaaaaa}clip} wclip​。
    ∵ e y e s p a c e i s r i g h t − h a n d c o o r d i n a t e s ∴ w c l i p = − z c l i p ∴ ( x c l i p y c l i p z c l i p w c l i p → ( − z c l i p ) ) = [ ⋅ ⋯ ⋯ ⋅ ⋮ ⋱ ⋱ ⋮ ⋅ ⋯ ⋯ ⋅ 0 0 − 1 0 ] ( x e y e y e y e z e y e w e y e ) ( x n d c y n d c z n d c ) = ( x c l i p / w c l i p y c l i p / w c l i p z c l i p / w c l i p ) { − w c l i p < x y z n d c < w c l i p x y z n d c = x y z c l i p / w c l i p − 1 < x y z n d c < 1 \because eye \space space \space is \space right-hand \space coordinates\\ \therefore w_{\color{#aaaaaa}clip}=-z_{\color{#aaaaaa}clip}\\ \therefore\left( \begin{matrix} x_{\color{#aaaaaa}clip}\\ y_{\color{#aaaaaa}clip}\\ z_{\color{#aaaaaa}clip}\\ w_{\color{#aaaaaa}clip} \rightarrow ({\color{#ff0000}-z_{\color{#aaaaaa}clip}})\\ \end{matrix} \right)= \begin{bmatrix} \cdot & \cdots & \cdots & \cdot \\ \vdots & \ddots & \ddots & \vdots \\ \cdot & \cdots & \cdots & \cdot \\ 0 & 0 & \color{#ff0000}-1 & 0 \end{bmatrix} \left( \begin{matrix} x_{\color{#aaaaaa}eye}\\ y_{\color{#aaaaaa}eye}\\ \color{#ff0000}z_{\color{#aaaaaa}eye}\\ \color{#ff0000}w_{\color{#aaaaaa}eye} \end{matrix} \right)\\ \left( \begin{matrix} x_{\color{#aaaaaa}ndc}\\ y_{\color{#aaaaaa}ndc}\\ z_{\color{#aaaaaa}ndc} \end{matrix} \right)= \left( \begin{matrix} x_{\color{#aaaaaa}clip}/w_{\color{#aaaaaa}clip}\\ y_{\color{#aaaaaa}clip}/w_{\color{#aaaaaa}clip}\\ z_{\color{#aaaaaa}clip}/w_{\color{#aaaaaa}clip} \end{matrix} \right) \begin{cases} -w_{\color{#aaaaaa}clip}<xyz_{\color{#aaaaaa}ndc}<w_{\color{#aaaaaa}clip}\\ xyz_{\color{#aaaaaa}ndc}=xyz_{\color{#aaaaaa}clip}/w_{\color{#aaaaaa}clip}\\ -1<xyz_{\color{#aaaaaa}ndc}<1 \end{cases} ∵eye space is right−hand coordinates∴wclip​=−zclip​∴ ​xclip​yclip​zclip​wclip​→(−zclip​)​ ​= ​⋅⋮⋅0​⋯⋱⋯0​⋯⋱⋯−1​⋅⋮⋅0​ ​ ​xeye​yeye​zeye​weye​​ ​ ​xndc​yndc​zndc​​ ​= ​xclip​/wclip​yclip​/wclip​zclip​/wclip​​ ​⎩ ⎨ ⎧​−wclip​<xyzndc​<wclip​xyzndc​=xyzclip​/wclip​−1<xyzndc​<1​

    • w c l i p = − z c l i p w_{\color{#aaaaaa}clip}=-z_{\color{#aaaaaa}clip} wclip​=−zclip​ see OpenGL Projection Matrix。
    • NDC like a cube, [l,r] range [-1,1], [b,t] range [-1,1], [-n,-f] range [-1,1],see Perspective Projection。
  • to mapping Window Coordinates (Screen Coordinates), using glViewport(x,y,w,h), glDepthRange(n,f) functions set the parameters of mapping, see following formula:

( x w i n d o w / s c r e e n y w i n d o w / s c r e e n z w i n d o w / s c r e e n ) = ( w 2 x n d c + ( x + w 2 ) h 2 y n d c + ( y + h 2 ) f − n 2 z n d c + ( f + n ) 2 ) { x w i n d o w = { − 1 ⇒ x 1 ⇒ x + w y w i n d o w = { − 1 ⇒ y 1 ⇒ y + h z w i n d o w = { − 1 ⇒ n 1 ⇒ f \left( \begin{matrix} x_{\color{#aaaaaa}window/screen}\\ y_{\color{#aaaaaa}window/screen}\\ z_{\color{#aaaaaa}window/screen} \end{matrix} \right)= \left( \begin{matrix} \frac{w}{2}x_{\color{#aaaaaa}ndc}+\left(x+\frac{w}{2}\right) \\ \frac{h}{2}y_{\color{#aaaaaa}ndc}+\left(y+\frac{h}{2}\right) \\ \frac{f-n}{2}z_{\color{#aaaaaa}ndc}+\frac{\left(f+n\right)}{2} \end{matrix} \right) \begin{cases} x_{\color{#aaaaaa}window}= \begin{cases} -1 \Rightarrow x \\ 1 \Rightarrow x+w \\ \end{cases}\\ y_{\color{#aaaaaa}window}= \begin{cases} -1 \Rightarrow y \\ 1 \Rightarrow y+h \\ \end{cases}\\ z_{\color{#aaaaaa}window}= \begin{cases} -1 \Rightarrow n \\ 1 \Rightarrow f \\ \end{cases}\\ \end{cases} ​xwindow/screen​ywindow/screen​zwindow/screen​​ ​= ​2w​xndc​+(x+2w​)2h​yndc​+(y+2h​)2f−n​zndc​+2(f+n)​​ ​⎩ ⎨ ⎧​xwindow​={−1⇒x1⇒x+w​ywindow​={−1⇒y1⇒y+h​zwindow​={−1⇒n1⇒f​​


参考前辈一文:纹理投影,里面有 GPU-GEMS 一图


References

  • LaTeX 各种命令,符号
  • OpenGL Transformation
    • Object Space Coordinates
    • Eye Space Coordinates
    • Clip Space Coordinates
    • NDC(Normalized Device Coordinates)
      • Perspective Projection
    • Window Coordinates (Screen Coordinates)
    • OpenGL Projection Matrix
    • Homogeneous Coordinates

OpenGL Transformation 几何变换的顺序概要(MVP,NDC,Window坐标变换过程)相关推荐

  1. OpenGL的几何变换4之内观察全景图

    上一次写了OpenGL的几何变换3之内观察全景图 上次采用的是图片分割化方式,这次采用数据分割化方式. 先说下思路,数据分割化方式呢,是只读取一张图片imgData,然后通过glTexCoord2f( ...

  2. OpenGL transformation变换的实例

    OpenGL transformation变换的实例 先上图,再解答. 完整主要的源代码 源代码剖析 先上图,再解答. 完整主要的源代码 #include <glad/glad.h> #i ...

  3. OpenGL使用链表进行顺序独立的透明度

    OpenGL使用链表进行顺序独立的透明度 先上图,再解答. 完整主要的源代码 源代码剖析 先上图,再解答. 完整主要的源代码 #include <stdio.h> #include &qu ...

  4. OpenGL Transformation

    http://www.songho.ca/opengl/gl_transform.html https://blog.csdn.net/wangdingqiaoit/article/details/5 ...

  5. openGL之几何变换(绘制球体)---openGL学习笔记(六)

    openGL中的变换包括:   ①视图(modeling)---指定观察者或者相机位置  GLU.glLookAt() 默认情况下,在透视投影中观察者是从原点向Z轴负方向看去,也可以自行设置.   ② ...

  6. 坐标变换过程(vertex transformation)

     原文:https://blog.csdn.net/wangdingqiaoit/article/details/51594408 在上面的图中,注意,OpenGL只定义了裁剪坐标系.规范化设备坐标系 ...

  7. OpenGL红宝书的部分学习记录

    我看的OpenGL红宝书为: <OpenGL编程指南>-- 原书第9版 OpenGL Programming Guide – The Official Guide to Learning ...

  8. Unity Shader - Billboard 广告板/广告牌 - BB树,BB投影

    文章目录 实现 CPU层 使用简单实现方式 模仿Shader层的复杂逻辑写法 向量叉乘的顺序 新的BB本地坐标系矩阵:newLocalMatrix可以不构建 2D的Billboard GPU层 带有可 ...

  9. OpenGL笔记之矩阵变换(Matrix Transformation)

    本文是学习OpenGL过程中的一篇笔记.在学习过程中,主要参照了大名鼎鼎的 <OpenGL Programming Guide>(中文名<OpenGL编程指南>,有些人还称之为 ...

  10. 计算机图形学の三维几何变换材质光照(OpenGL)

    OpenGL三维几何变换 & 材质光照 显示效果: 源码: #define NDEBUG #ifndef GLUT_DISABLE_ATEXIT_HACK #define GLUT_DISAB ...

最新文章

  1. java 高并发解决方案
  2. 2009年中国贫富标准线
  3. 交换机模拟配置软件_网络设备模拟器Packet Tracer实验
  4. nginx中的数组结构ngx_array_t
  5. 【正一专栏】2018年欧冠八强猜想
  6. php视频上传教程,PHP实现视频文件上传完整实例,_PHP教程
  7. 2018年10个最佳项目管理工具及链接
  8. 【Java】《面向对象程序设计——Java语言》Castle代码修改整理
  9. Spring Boot学习总结(18)——Springboot 2.0选择HikariCP作为默认数据库连接池的五大理由
  10. 文学系列:《红与黑》读书笔记
  11. 接收机端口电压dBuV如何转化为功率dBmW
  12. 2021年BATJ30套大厂Android经典高频面试题,附答案
  13. input框的23种类型
  14. 【转】安装虚拟机VMware及在VMware下安装Ghost XP系统图文教程(附PQ分区及VMware共享教程)
  15. linux filp open,诚意请教一个filp_open的问题。
  16. 在线教育和线下教育的优劣势
  17. Python ctypes的byref和pointer区别
  18. Latex脚注加超链接
  19. 【web服务】nginx为什么这么受企业欢迎?看完这边文章你就懂了
  20. Android 原生 多屏显示 (分屏) 原理 解析

热门文章

  1. 数据结构之线性表(九)——线性表的应用
  2. 爱情中不需要太多“礼貌”
  3. 不能启动tooltalk消息服务器,国家信息安全漏洞库
  4. 基于JSP的教学评价系统的设计与实现
  5. vue手写动画效果和animate库的使用
  6. Python爬虫初学爬取网站天气数据
  7. 知识补充,忽然发现的问题,相对路径与绝对路径的区别
  8. Kmeans原理实现——(python实现包含手肘法,kmeans++,降维可视化)
  9. keepalived健康检查方式
  10. 【换季谨防死“肌”】