Unity Shader study notes - simple graphics

        Two-dimensional Cartesian coordinate system: You can find the distance and direction of the target from yourself by setting yourself as the origin

         Three-dimensional Cartesian coordinate system: define three coordinate axes and an origin, these three coordinate axes are the basis vectors of the coordinate system, and these three coordinate axes are perpendicular to each other, and the length is 1, such a basis vector is called an orthonormal basis. If they are perpendicular to each other but have a length other than 1, they are called orthonormal bases.

         Three-dimensional can be divided into left-handed coordinate system and right-handed coordinate system. The two-dimensional coordinate system can be rotated so that the directions of the two coordinate systems coincide. However, the three-dimensional coordinate system may have a situation where the directions cannot be completely coincident regardless of rotation. For example, the following two coordinate systems . 

        Use two coordinate systems to describe the following pictures:

        Therefore, in a left-handed coordinate system, first translate 1 unit in the positive direction of the x-axis, then move 4 units in the negative direction of the z-axis, and finally rotate 60° in the positive direction of the rotation. In the right-handed coordinate system, first translate 1 unit in the positive direction of the x-axis, then move 4 units in the positive direction of the z-axis, and finally rotate 60° in the negative direction of the rotation.

        For model space, Unity uses a left-handed coordinate system.

        For the observation space (the coordinate system with the camera as the origin), Unity uses a right-handed coordinate system, and the forward direction of the camera is the negative direction of the z-axis. That is to say, the reduction of the z-axis coordinates means the increase of the depth of the scene.


         Some practice questions:

        Personal answer:

(1) Right-handed coordinate system

(2) The rotated coordinates are (1, 0, 0), and the second rotated coordinates are (1, 0, 0)

(3) -10 in observation space and 10 in model space


        Multiplication and division of scalar and vector: (Note that division can only be divided by vector by scalar)

         Vector addition and subtraction:


                The modulus of the vector: The geometric meaning of the modulus of the two-dimensional vector is to use the Pythagorean theorem. The absolute value of the two components of the vector corresponds to the length of the two right-angled sides of the triangle, and the length of the hypotenuse is the modulus of the vector.

         Unit vector: When we only care about the direction of the vector instead of the modulus, we need to calculate the unit vector, which generally refers to those vectors whose modulus is 1, also known as the normalized vector. (Zero vectors cannot be normalized because the denominator cannot be 0 when doing division)


        Dot product:

         Formula one:

        The geometric meaning of the dot product: projection, you can also know the direction relationship between the two vectors (before and after)

         The following properties can be obtained. The third property means that we can directly use the dot product to find the modulus of the vector. We only need to take the square root of the result. However, in most cases, we just want to compare the lengths of two vectors, so we can Use the result of the dot product directly.

         Formula two:

        According to formula 2 we can get the angle between the two vectors (between 0°~180°) 


 Cross product: The cross product is still a vector, and its geometric meaning is that a new vector that is perpendicular to the two vectors can be obtained at the same time. The modulus of this new vector is the product of the moduli of a and b and then multiplied by their The sine value of the included angle, the direction of this new vector represents that b is on the left or right of a.


        matrix:

         Both matrices and vectors are arrays, so the two can be connected. The vector can be regarded as an nx1 column matrix or a 1xn row matrix, such as vector v=(3,8,6)

        Multiplication of scalars and matrices: 

        Multiplication of matrix and matrix: For each element cij, find the i-th row in A and the j-th column in B, then multiply their corresponding elements and add them up.

         Therefore, matrix multiplication is not commutative, but associative.

 some special matrices

        Square matrix: referred to as a square matrix, refers to those matrices with the same number of rows and columns. In 3D rendering, the most commonly used are 3x3 and 4x4 square matrices. The diagonal elements of a square matrix refer to the elements with the same row number and column number. If all elements of a matrix are zero except for the diagonal elements, then this matrix is ​​called a diagonal matrix.


        Identity matrix: The result of multiplying any matrix with him is still the original matrix, ie MI=IM=M


        Transpose matrix: It is an operation on the original matrix, that is, transpose operation. Given an rxc matrix M, her transpose can be expressed as , this is a cxr matrix, the calculation only needs to flip the original matrix, that is to say, the i-th row of the original matrix becomes the i-th column, And column j becomes row j.

   


         Inverse matrix: Not all matrices have an inverse matrix. The first premise is that the matrix must be a square matrix. The most important property of an inverse matrix is ​​that

         How to judge whether a matrix is ​​invertible, simply put, if the determinant of a matrix is ​​not 0, then it is invertible.

 

         The geometric meaning of the inverse matrix: the matrix can represent a transformation, and the inverse matrix allows us to restore this transformation


         Orthogonal matrix: Orthogonality is a property of a matrix. If the product of a square matrix M and its transposed matrix is ​​an identity matrix, we say that the matrix is ​​orthogonal

        According to the definition of an orthogonal matrix: as shown in the figure below, each row of the matrix, namely c1, c2, c3 is a unit vector, because only in this way can the dot product between them and themselves be 1, and the three of them are perpendicular to each other, so The dot product between them can be 0

 

Guess you like

Origin blog.csdn.net/weixin_45081191/article/details/129169131