3D to 2D projection using view frustum has issues with translation

Maghoumi

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??

Maghoumi

The problem was so silly that I'm ashamed of wasting this much time.

Turned out that some of the points in my point cloud had wrong w components. I wasn't running into any issues on OpenGL side because the shader was manually setting all ws to 1. On the rasterizer side, the wrong w's caused points that were at longer distances to the camera to project at wrong perspective locations.

The test spheres that I used didn't have any problems because they had the right w components.

Edit:
Just thought I'd also mention this: there's no need to extract view frustum planes to determine whether projected points fall inside the view frustum or not. One can simply perform this check by determining whether all x', y' and z' components in a transformed point (x', y', z', w') (i.e. after multiplying by matrix P x V x M) fall in the range w' and -w'. If all three components fall in that range, that point is visible, otherwise that point is outside the view frustum.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

3D Spaces (Model/World, View/Eye, Projection)

From Java

how to use JOML to simulate OpenGL like Model, View Matrices on 3D projection to 2D plane?

From Dev

Numpy fastest 3D to 2D projection

From Dev

Numpy fastest 3D to 2D projection

From Dev

Ortho projection of 3D points with a vector

From Dev

3D projection doesnt work

From Dev

3D projection to screen PHP

From Dev

Why use a Matrix for 3D Projection?

From Dev

Matplotlib separate 2D contour projection plots of 3D data

From Dev

python : 2D perspective projection of a 3D surface plot

From Dev

Analysis of a 3D point cloud by projection in a 2D surface

From Dev

How to determine the projection (2D or 3D) of a matplotlib axes object?

From Dev

python : 2D perspective projection of a 3D surface plot

From Dev

Iterative non-linear-least-squares opimizing a 3d to 2d projection

From Dev

Scenekit Pan 2D Translation to Orthographic 3D only horizontal

From Dev

Point cloud projection to 2D

From Dev

3D Model Translation deforming the object

From Dev

sorting 3D matrix by using 2D matrix

From Dev

View frustum culling questions

From Dev

View frustum culling questions

From Dev

how to get screen coords using projection with a multipolygon in d3

From Dev

Plot GeoJSON line string on canvas using D3 projection

From Dev

How do I minimize mercator projection using D3

From Dev

How to deal with negative depth in 3D perspective projection

From Java

ValueError: Unknown projection '3d' (once again)

From Dev

3D perspective projection coordinates in clip space

From Dev

A bit about 3D perspective projection & matrix transforms

From Dev

Can I turn an existing ax object into a 3d projection?

From Dev

ValueError: Unknown projection '3d' (once again)

Related Related

  1. 1

    3D Spaces (Model/World, View/Eye, Projection)

  2. 2

    how to use JOML to simulate OpenGL like Model, View Matrices on 3D projection to 2D plane?

  3. 3

    Numpy fastest 3D to 2D projection

  4. 4

    Numpy fastest 3D to 2D projection

  5. 5

    Ortho projection of 3D points with a vector

  6. 6

    3D projection doesnt work

  7. 7

    3D projection to screen PHP

  8. 8

    Why use a Matrix for 3D Projection?

  9. 9

    Matplotlib separate 2D contour projection plots of 3D data

  10. 10

    python : 2D perspective projection of a 3D surface plot

  11. 11

    Analysis of a 3D point cloud by projection in a 2D surface

  12. 12

    How to determine the projection (2D or 3D) of a matplotlib axes object?

  13. 13

    python : 2D perspective projection of a 3D surface plot

  14. 14

    Iterative non-linear-least-squares opimizing a 3d to 2d projection

  15. 15

    Scenekit Pan 2D Translation to Orthographic 3D only horizontal

  16. 16

    Point cloud projection to 2D

  17. 17

    3D Model Translation deforming the object

  18. 18

    sorting 3D matrix by using 2D matrix

  19. 19

    View frustum culling questions

  20. 20

    View frustum culling questions

  21. 21

    how to get screen coords using projection with a multipolygon in d3

  22. 22

    Plot GeoJSON line string on canvas using D3 projection

  23. 23

    How do I minimize mercator projection using D3

  24. 24

    How to deal with negative depth in 3D perspective projection

  25. 25

    ValueError: Unknown projection '3d' (once again)

  26. 26

    3D perspective projection coordinates in clip space

  27. 27

    A bit about 3D perspective projection & matrix transforms

  28. 28

    Can I turn an existing ax object into a 3d projection?

  29. 29

    ValueError: Unknown projection '3d' (once again)

HotTag

Archive