1

I need to create this software rasterizer that given the projection (P), view (V) and model (M) matrices, can create the 2D image of a point cloud (pc) from the given point of view in a bitmap format (a monochrome bitmap).

I've got the math down (and things seem to be working for the most part):

  1. Transform the point cloud's points pc' = (P x V x M) x pc (note that the point cloud is already in homogeneous system)
  2. For each point, divide all components by its w (while being careful to discard points that have w close to zero.
  3. Discard points that fall outside the view frustum (by extracting the frustum planes from the P using the method described here)
  4. Transform x and y coordinates of each point to screen coordinates using (x + 1) * imageWidth / 2 and (-y + 1) * imageHeight / 2 (to have the correct y coordinate).
  5. Map the resulting x and y coordinates to bitmap linear index using (int)y * imageWidth + (int)x (with bound-checking).

It seems that everything works fine: I get the exact bitmap as if I were rendering it with OpenGL, rotating the point cloud by an arbitrary quaternion still gives valid results.

Things are good until I have a translation component in matrix M! As soon as I have the slightest amount of translation, the image breaks: the point cloud gets heavily distorted (as if a non-affine transform has been applied to it). It doesn't matter along which direction the translation is applied, ANY translation messes everything up to the point that the point cloud is not recognizable anymore. At first I though my model matrix was transposed (resulting in a non-affine transformation), but that doesn't appear to be the case.

I could post some code if needed, but given the above overview, am I missing anything?? Is there any special consideration that may be needed??

4

1 回答 1

1

这个问题太愚蠢了,我为浪费这么多时间而感到羞耻。

结果发现我的点云中的一些点有错误的w组件。我在 OpenGL 方面没有遇到任何问题,因为着色器手动将所有ws 设置为 1。在光栅化方面,错误w的 ' 导致距相机较远的点投影在错误的透视位置。

我使用的测试球没有任何问题,因为它们有正确的w组件。

编辑:
只是想我也会提到这一点:没有必要提取视锥平面来确定投影点是否落在视锥内。可以通过确定变换点中的所有 和 分量x'(即乘以矩阵 之后)是否落在范围 和 中y'来简单地执行此检查。如果所有三个组件都在该范围内,则该点可见,否则该点位于视锥体之外。z'(x', y', z', w')P x V x Mw'-w'

于 2016-06-26T20:00:41.893 回答