我正在尝试实现一个简单的光线追踪算法
所以第一步是将像素坐标转换成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
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
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)
发布评论
评论(1)
假设您的相机是某种金字塔。它有一个底面,我将其称为“相机屏幕”,金字塔的高度(也称为焦距)将标记为 F(或在方程中为 Ws)。
假设
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 之间)处,您的身高为稍微搞乱一下,分数
d
为实际上:所以:
同样:
现在,让我们将
U
表示为从左到右的向量,V
从下到上,'W'从眼睛向前。所有这些向量都被标准化。现在,假设眼睛位于
(0,0)
正上方,即金字塔矩形面中心的正上方。要从眼睛直接转到
(0,0)
,您可以执行以下操作:然后从该点转到屏幕上索引
(i,j)
处的另一个点您会这样:您将能够看到
i = 0
时Us = 0
和j = 0 时
(因为Vs = 0
B = -T
且L = -R
,因为眼睛位于矩形中心的正上方)。最后,如果我们将其组合在一起,屏幕上索引
(i,j)
处的点就是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).
Let's assume
j
goes from the bottom to the top (from-Ny/2
to+Ny/2
in steps of1/Ny
), andi
goes from left to right (from-Nx/2
to+Nx/2
in steps of1/Nx
). Note that if Ny is even, j goes up toNx/2-1
(and similar whenNx
is even).As you go from bottom to top in the image, on the screen, you move from the
B
value to theT
value. At the fractiond
(between 0=bottom and 1=top) of your way from bottom to top, your height isA bit of messing around shows that the fraction
d
is actually:So:
And similarly:
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:And then to go from that point to another point on the screen at indexes
(i,j)
you would go:You will be able to see that
Us = 0
fori = 0
andVs = 0
forj = 0
(sinceB = -T
andL = -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)
isEnjoy!