Skip to content
The Chat Archive
o4-mini-2025-04-16· OpenAI LMArena Human Preference 140K

3.1 Supporting a Non-Identity Modelview Matrix Until now we have assumed that the…

  1. User

    3.1 Supporting a Non-Identity Modelview Matrix Until now we have assumed that the modelview matrix is an identity matrices. However, the goal obviously is to make the algorithm work for an arbitrary view. This is, in fact, so easy that it’s almost unbelievable. If you think about it for a moment then you’ll immediately understand it, and that’s why we are not going to explain this in any great detail. All we are giving to you is this:

    1. If the matrixM is equal to the projection matrix P (i.e., M P = ), then the algorithm gives the clipping planes in view space (i.e., camera space).
    2. If the matrixM is equal to the combined projection and modelview matrices, then the algorithm gives the clipping planes in model space (i.e., VP M ⋅ = , where V is the modelview matrix, and P is the projection matrix).

    Can you explain to me about this section and how i can get the frustum planes in world space?

  2. Assistant

    Here’s the gist of what the text is saying:

    1. If you feed the projection matrix P alone into your “plane‐extraction” routine, you get the six frustum‐planes in camera (view) space.
    2. If you feed the combined projection × modelview (P⋅V) into the same routine, you get the frustum planes in model space (because V was your full model-and-view transform).

    Getting the planes in World space

    A) Extract & then “un‐project”

    1. Extract planes in view (camera) space by running your usual code on
      M = P
    2. Transform each plane from view‐space back into world‐space by using the inverse-transpose of your view matrix V_view:

    Let a plane be represented by the 4‐vector (nᵥ, dᵥ) in view space. Then its world–space counterpart (n_w, d_w) is
    [ n_w; d_w ] = (V_view)⁻ᵀ ⋅ [ nᵥ; dᵥ ]
    Finally, normalize (n_w, d_w) so that ‖n_w‖ = 1.

    // pseudocode:  V_view is a 4×4 view‐matrix, planes[i] = {n, d}
    mat4 invT = inverse(transpose(V_view));
    for each plane {vec3 n_v; float d_v} in view‐space:
        vec4 p_v = vec4(n_v, d_v);
        vec4 p_w = invT * p_v;       
        // normalize
        float L = length(p_w.xyz);
        n_w = p_w.xyz / L;
        d_w = p_w.w   / L;
    

    B) Direct extraction in world space

    If you never applied a “model” transform (or if you want your frustum in world‐space, i.e. before camera transform), just combine projection × view (but not the model into it):

    M = P ⋅ V_view

    and feed that into your plane‐extraction code. The six planes you get will then be expressed in world‐coordinates.


    Plane‐Extraction Reminder

    Whichever M you choose (P, or P⋅V_view, or P⋅(V_model⋅V_view)), the actual extract usually goes like this (row‐major example):

    // M = proj × view  or  M = proj alone
    vec4 row0 = M[0], row1 = M[1], row2 = M[2], row3 = M[3];
    
    Plane planes[6];
    // left
    planes[0].n = (row3 + row0).xyz;  planes[0].d = (row3 + row0).w;
    // right
    planes[1].n = (row3 - row0).xyz;  planes[1].d = (row3 - row0).w;
    // bottom
    planes[2].n = (row3 + row1).xyz;  planes[2].d = (row3 + row1).w;
    // top
    planes[3].n = (row3 - row1).xyz;  planes[3].d = (row3 - row1).w;
    // near
    planes[4].n = (row3 + row2).xyz;  planes[4].d = (row3 + row2).w;
    // far
    planes[5].n = (row3 - row2).xyz;  planes[5].d = (row3 - row2).w;
    
    // finally normalize each plane:
    for each plane p:
        float L = length(p.n);
        p.n /= L;
        p.d /= L;
    

    – If M = P ⇒ planes in view space
    – If M = P⋅V_view ⇒ planes in world space
    – If M = P⋅(V_view⋅M_model) ⇒ planes in model space

    Pick the M that matches the space you want. 🎯

  3. User

    why does d need to be normalized too?

  4. Assistant

    The short answer is: a plane in “normal-distance” form is

      n·x + d = 0

    where n is a unit-length normal (‖n‖=1) and d is the (signed) distance from the origin along n. If you only normalize n and leave d unchanged, you no longer have that property, and your distance‐tests (e.g. for frustum culling) will be wrong.


    A more detailed breakdown

    1. Raw extraction gives you a plane [n₀, d₀] such that
      n₀·x + d₀ = 0
      but typically ‖n₀‖ ≠ 1.

    2. The signed distance from a point x to that plane is
      (n₀·x + d₀) / ‖n₀‖.
      We’d like a form where you can just write
      n·x + d
      and have that already be the distance.

    3. So you factor out L = ‖n₀‖:
      (n₀·x + d₀) = L ( (n₀/L)·x + (d₀/L) ).

      Define
      n = n₀ / L,
      d = d₀ / L.
      Now ‖n‖=1 and
      n·x + d = (signed) distance.

    4. If you forgot to divide d₀ by L, your plane equation would become
      (n₀/L)·x + d₀ = 0
      which is a different plane and gives totally wrong distances/culling results!


    In code

    // suppose you extracted
    vec3 n0;  
    float d0;  
    float L = length(n0);
    
    // normalize both:
    // — new normal is unit-length
    vec3 n = n0 / L;
    // — new d now correctly encodes the signed distance
    float d = d0 / L;
    

    Now for any world‐space point x,
      n·x + d
    is exactly the signed distance to the plane.

    That’s why you must normalize both the normal and the d-term together.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.