OpenGL vs DirectX OpenGL / Vulkan / DircetX

이문서도 꼭 읽어보자!

MatricesTips.pdf


1. 좌표계
OpenGL : 오른손 좌표계
DirectX : 왼손 좌표계


2. 행렬 ( Matrix )


row major인지 coulmn major인지 판단하는 방법은 컴퓨터 메모리 구조와 관련이 있으며 벡터와 행렬을 계산하는 방식에 따라 구분하면 된다. 
예를들면 행우선(coulmn major) 방식에선 메모리에 적재된 일련의 4개의 요소들이 4x1의 요소로 구성이된다. 즉 세로 기둥을 구성한다.
행우선(column major) 행렬계산에선 벡터가 오른쪽에 위치하게 되며 벡터를 그림으로 표현하면 4x1의 세로기둥 형태가 된다.  반대로  열우선(row major) 행렬 계산의 경우 올바른 벡터와 행렬의 계산식에서 벡터는 행렬의 왼쪽에 위치하게 되며 벡터를 그림으로 표현하면 1x4의 가로형태가 된다.

OpenGL : 행우선 ( column major )


column-major

A way to represent items in a N-dimensional array in the 1-dimensional computer memory. In column-major order, the leftmost index “varies the fastest”: for example the array:

[[1, 2, 3], [4, 5, 6]]

is represented in the column-major order as:

[1, 4, 2, 5, 3, 6]

Column-major order is also known as the Fortran order, as the Fortran programming language uses it.

    V' = T * Rz * Ry * Rx * S * V
    V' = Proj * View * World * V




DirectX : 열우선 ( row major )


row-major

A way to represent items in a N-dimensional array in the 1-dimensional computer memory. In row-major order, the rightmost index “varies the fastest”: for example the array:

[[1, 2, 3], [4, 5, 6]]

is represented in the row-major order as:

[1, 2, 3, 4, 5, 6]

Row-major order is also known as the C order, as the C programming language uses it. New Numpy arrays are by default in row-major order.

    V'  = V * S * Rx * Ry * Rz * T
    V' = V * World * View * Proj



Matrix Ordering

Matrix packing order for uniform parameters is set to column-major by default. This means each column of the matrix is stored in a single constant register. On the other hand, a row-major matrix packs each row of the matrix in a single constant register. Matrix packing can be changed with the #pragmapack_matrix directive, or with the row_major or the column_major keyword.

The data in a matrix is loaded into shader constant registers before a shader runs. There are two choices for how the matrix data is read: in row-major order or in column-major order. Column-major order means that each matrix column will be stored in a single constant register, and row-major order means that each row of the matrix will be stored in a single constant register. This is an important consideration for how many constant registers are used for a matrix.

A row-major matrix is laid out like the following:

11121314
21222324
31323334
41424344

 

A column-major matrix is laid out like the following:

11213141
12223242
13233343
14243444

 

Row-major and column-major matrix ordering determine the order the matrix components are read from shader inputs. Once the data is written into constant registers, matrix order has no effect on how the data is used or accessed from within shader code. Also, matrices declared in a shader body do not get packed into constant registers. Row-major and column-major packing order has no influence on the packing order of constructors (which always follows row-major ordering).

The order of the data in a matrix can be declared at compile time or the compiler will order the data at runtime for the most efficient use.

Examples

HLSL uses two special types, a vector type and a matrix type to make programming 2D and 3D graphics easier. Each of these types contain more than one component; a vector contains up to four components, and a matrix contains up to 16 components. When vectors and matrices are used in standard HLSL equations, the math performed is designed to work per-component. For instance, HLSL implements this multiply:


덧글

댓글 입력 영역