All Questions


Harits Nur Fauzan

Question About Camera Matrix


I have a question regarding the camera matrix. I don't quite understand how that variable actually works, or what value does it hold. Am I right to assume that it's the current camera position in the world position? Thanks!

  • Nathan Lovato replied

    The CAMERA_MATRIX is a transformation matrix that, when multiplied with some coordinates, converts the coordinates from world space to view space.

    In the tutorial, the line:

    down_camera_angle = (vec4(0, -1, 0, 1) * CAMERA_MATRIX).xyz;

    Projects a vector pointing down onto the view.

  • Razoric replied

    Hello! There are multiple coordinate systems in shaders:

    • Model space, where 0,0,0 is the origin of the 3D model in the file
    • World space, where 0,0,0 is the origin of the 3D world
    • View space, where 0,0,0 is the camera
    • Clip space, where 0,0,0 is the top left of the screen

    The matrices are mathematical constructs that, when multiplied with a Vector, transform a point from one coordinate system to another:

    • The WORLD_MATRIX goes from model space to world space
    • INV_CAMERA_MATRIX goes from world to view.
    • PROJECTION_MATRIX goes from view to clip
    • CAMERA_MATRIX goes from view to world
    • MODELVIEW_MATRIX goes from model to view
    • INV_PROJECTION_MATRIX goes from clip to view

    There is one more transformation you don't have access to, which happens between the fragment and vertex shader which turns the vertex into 'NDC', or normalized device coordinates.

    The default vertex shader, unless you use special render modes or the POSITION built-in, will multiply the vertex and normal by the modelview matrix, then by the projection matrix.

  • N
    Harits Nur Fauzan replied

    Oh okay, so those matrices will change a vector from one coordinate space to another, thanks for the answers!