从像素坐标获取 uvw 坐标以进行光线追踪

发布于 2024-11-29 12:49:22 字数 349 浏览 2 评论 0 原文

我正在尝试实现一个简单的光线追踪算法 所以第一步是将像素坐标转换成uvw坐标系 我正在使用我在书中找到的两个方程 在此处输入图像描述

其中 l,r,b,t 是视锥体点,(i,j) 是像素索引,(nx,ny)是场景宽度和高度

,然后计算规范坐标我使用

我想要去理解前面的方程以及为什么它们给出透视投影的 uwv 坐标而不是正交投影(当我使用正交投影时,方程仍然给出结果,就像使用透视投影一样)

I'm trying to implement a simple ray-tracing algorithm
so the first step is to convert pixel coordinates into uvw coordinates system
iam using those two equations that i found in a book
enter image description here

where l,r,b,t are the view frustum points , (i,j) are the pixel indexes , (nx,ny) are the scene width and height

then to calculate canonical coordinate i use

enter image description here

i want to understand the previous equations and why they give uwv coordinates for perspective projection not for orthogonal projection (when i use orthogonal projection the equation still gives the result as if perspective projection is used)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

超可爱的懒熊 2024-12-06 12:49:22

假设您的相机是某种金字塔。它有一个底面,我将其称为“相机屏幕”,金字塔的高度(也称为焦距)将标记为 F(或在方程中为 Ws)。

         T(op)
       *---------*
       |\       /|
       | \     / |
       |  \   /  |
       |   \ /   |
L(eft) |    *E(ye| R(ight)
       |   / \   |
       |  /   \  |
       | /     \ |
       |/       \|
       *---------*
         B(ottom)

假设 j 从下到上(从 -Ny/2+Ny/2,步长为 1/ Ny),i 从左到右(从 -Nx/2+Nx/2,步长为 <代码>1/Nx)。请注意,如果 Ny 为偶数,则 j 上升到 Nx/2-1(当 Nx 为偶数时类似)。

当您在图像中从下到上时,在屏幕上,您会从 B 值移动到 T 值。在从下到上的分数 d(介于 0=bottom 和 1=top 之间)处,您的身高为

Vs = T + (B-T) * d

稍微搞乱一下,分数 d 为实际上:

d = (j + 0.5) / Ny

所以:

Vs = T + (B-T) * (j + 0.5) / Ny

同样:

Us = L + (R-L) * (i + 0.5) / Nx

现在,让我们将U表示为从左到右的向量,V从下到上,'W'从眼睛向前。所有这些向量都被标准化。

现在,假设眼睛位于 (0,0) 正上方,即金字塔矩形面中心的正上方。

要从眼睛直接转到 (0,0),您可以执行以下操作:

Ws * W

然后从该点转到屏幕上索引 (i,j) 处的另一个点您会这​​样:

Us * U + Vs * V

您将能够看到 i = 0Us = 0j = 0 时 Vs = 0 (因为B = -TL = -R,因为眼睛位于矩形中心的正上方)。

最后,如果我们将其组合在一起,屏幕上索引 (i,j) 处的点就是

S = E + Us * U + Vs * V + Ws * W

Enjoy!

Let's assume your camera is some sort of a pyramid. It has a bottom face which I'll refer to as the "camera screen", and the height of the pyramid, also known as the focal length, will be marked as F (or in your equations, Ws).

         T(op)
       *---------*
       |\       /|
       | \     / |
       |  \   /  |
       |   \ /   |
L(eft) |    *E(ye| R(ight)
       |   / \   |
       |  /   \  |
       | /     \ |
       |/       \|
       *---------*
         B(ottom)

Let's assume j goes from the bottom to the top (from -Ny/2 to +Ny/2 in steps of 1/Ny), and i goes from left to right (from -Nx/2 to +Nx/2 in steps of 1/Nx). Note that if Ny is even, j goes up to Nx/2-1 (and similar when Nx is even).

As you go from bottom to top in the image, on the screen, you move from the B value to the T value. At the fraction d (between 0=bottom and 1=top) of your way from bottom to top, your height is

Vs = T + (B-T) * d

A bit of messing around shows that the fraction d is actually:

d = (j + 0.5) / Ny

So:

Vs = T + (B-T) * (j + 0.5) / Ny

And similarly:

Us = L + (R-L) * (i + 0.5) / Nx

Now, let's denote U as the vector going from left to right, V from bottom to top, 'W' going from the eye forward. All these vectors are normalized.

Now, assume the eye is located directly above (0,0) where that is exactly above the center of the rectangular face of the pyramid.

To go from the eye directly to (0,0) you would go:

Ws * W

And then to go from that point to another point on the screen at indexes (i,j) you would go:

Us * U + Vs * V

You will be able to see that Us = 0 for i = 0 and Vs = 0 for j = 0 (since B = -T and L = -R, as the eye is directly above the center of the rectangle).

And finally, if we compose it together, a point on the screen at indexes (i,j) is

S = E + Us * U + Vs * V + Ws * W

Enjoy!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文