【发布时间】:2021-05-08 03:26:05
【问题描述】:
我正在为一个需要实施鱼眼着色器的学校项目工作,我正在努力确定顶点深度值的过程。我知道对于空间 P1 = (x, y, z, w) 中的一个点,P * 我的投影矩阵应该产生一个新点 P2 = (a, b, c, d),其中对于近点和之间的任何点远剪裁平面 P2.c/P2.d 产生介于 0 和 1 之间的数字。
我的 hlsl 顶点着色器包含此代码,其中 input.Position 是原始顶点位置
float distance3d(float4 input) // Finds 3d hypotenuse
{
return sqrt(input[0] * input[0] + input[1] * input[1] + input[3] * input[3]);
}
//Vertex Position data
float4 worldPosition = mul(input.Position, World); // object to world xform
float4 viewPosition = mul(worldPosition, View); // world to camera xform
output.Position = mul(viewPosition, Projection); // perspective xform
float z = output.Position[3];
float distance = distance3d(output.Position) * (z < 0 ? -1 : 1);
float f = Projection[2][2];
float n = Projection[3][2];
output.Position[3] = distance;
output.Position[2] = -distance * f + square * n;
我的投影矩阵是使用这段代码生成的。
new Matrix( -focalLength * Math.Sin(-FOV), 0, 0, 0,
0, -focalLength * Math.Sin(-FOV), 0, 0,
0, 0, -farPlane / (farPlane - nearPlane), -1,
0, 0, -farPlane / (farPlane - nearPlane) * nearPlane, 0);
法线投影:https://imgur.com/Z00CPP3
鱼眼投影:https://imgur.com/0qPv87V
如您所见,远三角形呈现在近三角形前面。
感谢您的帮助。
【问题讨论】:
标签: 3d xna shader hlsl fisheye