Why would it be beneficial to have a separate projection matrix, yet combine model and view matrix?

后端 未结 2 859
没有蜡笔的小新
没有蜡笔的小新 2021-01-30 10:32

When you are learning 3D programming, you are taught that it\'s easiest think in terms of 3 transformation matrices:

  1. The Model Matrix. This matrix is i

2条回答
  •  一生所求
    2021-01-30 11:17

    Look at it practically. First, the fewer matrices you send, the fewer matrices you have to multiply with positions/normals/etc. And therefore, the faster your vertex shaders.

    So point 1: fewer matrices is better.

    However, there are certain things you probably need to do. Unless you're doing 2D rendering or some simple 3D demo-applications, you are going to need to do lighting. This typically means that you're going to need to transform positions and normals into either world or camera (view) space, then do some lighting operations on them (either in the vertex shader or the fragment shader).

    You can't do that if you only go from model space to projection space. You cannot do lighting in post-projection space, because that space is non-linear. The math becomes much more complicated.

    So, point 2: You need at least one stop between model and projection.

    So we need at least 2 matrices. Why model-to-camera rather than model-to-world? Because working in world space in shaders is a bad idea. You can encounter numerical precision problems related to translations that are distant from the origin. Whereas, if you worked in camera space, you wouldn't encounter those problems, because nothing is too far from the camera (and if it is, it should probably be outside the far depth plane).

    Therefore: we use camera space as the intermediate space for lighting.

提交回复
热议问题