质地透视校正在三维坐标 [英] perspective correction of texture coordinates in 3d

查看:140
本文介绍了质地透视校正在三维坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个软件渲染这是目前运作良好,但我试图让纹理坐标的透视校正和似乎并不正确。我现在用的都是一样的矩阵数学和OpenGL为我的渲染器。要光栅化三角形我做到以下几点:

  1. 使用模型视图和投影矩阵变换顶点,并转化为剪辑坐标。

  2. 在每个三角形的每个像素,计算重心坐标插补属性(颜色,纹理坐标,法线等)

  3. 要纠正角度来看,我用透视校正插值: (w是顶点的深度坐标,c是顶点的纹理坐标,b为一个顶点的重心重量)

  1 / W = B0 *(1 / W0)+ B1 *(1 / W1)+ B2 *(1 / W2)
C / W = B0 *(C0 / W0)+ B1 *(C1 / W1)+ B2 *(C2 / W2)
C =(C / W)/(1 / w)的
 

这应该纠正的角度来看,它可以帮助一点,但仍有明显的角度来看问题。我失去了一些东西在这里,也许有些舍入的问题(我用浮漂的所有数学)?

在这个图像

请参阅在纹理错误沿对角线坐标明显,这是具有深度的坐标进行分工的结果。

此外,这通常是用于纹理坐标进行...是必要的其它性质(如法线等),以及

解决方案

我破解这个问题上code最近。您可以使用单应,如果你打算修改内存中的纹理之前,将其分配到表面。这是计算昂贵,并增加了一个额外的依赖于你的程序。有一个很好的黑客工具,将解决这个问题给你。

OpenGL的自动透视矫正适用于您的渲染纹理。所有你需要做的是乘以你的纹理坐标 - 飞机上的每个角落(UV 0.0-1.0F)的Z分量(一个XYZ位置矢量的世界空间深度),它会甩开的OpenGL的透视校正

我问最近解决了这个问题。给这个链接一个镜头:

<一个href="http://stackoverflow.com/questions/5892120/texture-mapping-a-trapezoid-with-a-square-texture-in-opengl">texture用方形纹理的OpenGL

映射一个梯形

我看,解决了这个问题被称为纸,<一个href="http://www.google.com/url?sa=t&source=web&cd=1&ved=0CCAQFjAA&url=http%3A%2F%2Fciteseerx.ist.psu.edu%2Fviewdoc%2Fdownload%3Fdoi%3D10.1.1.1.9091%26rep%3Drep1%26type%3Dpdf&rct=j&q=Navigating%20Static%20Environments%20Using%20Image-Space%20Simplification%20and%20Morphing&ei=Ch3CTf_WOMPngQfE7fDdAQ&usg=AFQjCNEPoJ0iKc-Hr32MiyGd7O90kd6E0Q&cad=rja"相对=nofollow>浏览静态环境中使用图片,空间和简化变形 - 第9页附录A

希望这有助于!

CT

I'm writing a software renderer which is currently working well, but I'm trying to get perspective correction of texture coordinates and that doesn't seem to be correct. I am using all the same matrix math as opengl for my renderer. To rasterise a triangle I do the following:

  1. transform the vertices using the modelview and projection matrixes, and transform into clip coordinates.

  2. for each pixel in each triangle, calculate barycentric coordinates to interpolate properties (color, texture coordinates, normals etc.)

  3. to correct for perspective I use perspective correct interpolation: (w is depth coordinate of vertex, c is texture coordinate of vertex, b is the barycentric weight of a vertex)

1/w = b0*(1/w0) + b1*(1/w1) + b2*(1/w2)
c/w = b0*(c0/w0) + b1*(c1/w1) + b2*(c2/w2)
c = (c/w)/(1/w)

This should correct for perspective, and it helps a little, but there is still an obvious perspective problem. Am I missing something here, perhaps some rounding issues (I'm using floats for all math)?

See in this image the error in the texture coordinates evident along the diagonal, this is the result having done the division by depth coordinates.

Also, this is usually done for texture coordinates... is it necessary for other properties (e.g. normals etc.) as well?

解决方案

I cracked the code on this issue recently. You can use a homography if you plan on modifying the texture in memory prior to assigning it to the surface. That's computationally expensive and adds an additional dependency to your program. There's a nice hack that'll fix the problem for you.

OpenGL automatically applies perspective correction to the texture you are rendering. All you need to do is multiply your texture coordinates (UV - 0.0f-1.0f) by the Z component (world space depth of an XYZ position vector) of each corner of the plane and it'll "throw off" OpenGL's perspective correction.

I asked and solved this problem recently. Give this link a shot:

texture mapping a trapezoid with a square texture in OpenGL

The paper I read that fixed this issue is called, "Navigating Static Environments Using Image-Space Simplification and Morphing" - page 9 appendix A.

Hope this helps!

ct

这篇关于质地透视校正在三维坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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