Super Mario 64 Source
A Super Mario 64 decompilation, brought to you by a bunch of clever folks.
Data Structures | Functions | Variables
rendering_graph_node.c File Reference
#include <ultra64.h>
#include "sm64.h"
#include "main.h"
#include "display.h"
#include "print.h"
#include "engine/math_util.h"
#include "area.h"
#include "shadow.h"
#include "memory.h"
#include "game.h"
#include "rendering_graph_node.h"

Data Structures

struct  GeoAnimState
 Animation nodes have state in global variables, so this struct captures the animation state so a 'context switch' can be made when rendering the held object. More...
 
struct  RenderModeContainer
 

Functions

static void geo_process_master_list_sub (struct GraphNodeMasterList *node)
 Process a master list node. More...
 
static void geo_append_display_list (void *displayList, s16 layer)
 Appends the display list to one of the master lists based on the layer parameter. More...
 
static void geo_process_master_list (struct GraphNodeMasterList *node)
 Process the master list node. More...
 
static void geo_process_ortho_projection (struct GraphNodeOrthoProjection *node)
 Process an orthographic projection node. More...
 
static void geo_process_perspective (struct GraphNodePerspective *node)
 Process a perspective projection node. More...
 
static void geo_process_level_of_detail (struct GraphNodeLevelOfDetail *node)
 Process a level of detail node. More...
 
static void geo_process_switch (struct GraphNodeSwitchCase *node)
 Process a switch case node. More...
 
static void geo_process_camera (struct GraphNodeCamera *node)
 Process a camera node. More...
 
static void geo_process_translation_rotation (struct GraphNodeTranslationRotation *node)
 Process a translation / rotation node. More...
 
static void geo_process_translation (struct GraphNodeTranslation *node)
 Process a translation node. More...
 
static void geo_process_rotation (struct GraphNodeRotation *node)
 Process a rotation node. More...
 
static void geo_process_scale (struct GraphNodeScale *node)
 Process a scaling node. More...
 
static void geo_process_billboard (struct GraphNodeBillboard *node)
 Process a billboard node. More...
 
static void geo_process_display_list (struct GraphNodeDisplayList *node)
 Process a display list node. More...
 
static void geo_process_generated_list (struct GraphNodeGenerated *node)
 Process a generated list. More...
 
static void geo_process_background (struct GraphNodeBackground *node)
 Process a background node. More...
 
static void geo_process_animated_part (struct GraphNodeAnimatedPart *node)
 Render an animated part. More...
 
void geo_set_animation_globals (struct GraphNodeObject_sub *node, s32 hasAnimation)
 Initialize the animation-related global variables for the currently drawn object's animation. More...
 
static void geo_process_shadow (struct GraphNodeShadow *node)
 Process a shadow node. More...
 
static int obj_is_in_view (struct GraphNodeObject *node, Mat4 matrix)
 Check whether an object is in view to determine whether it should be drawn. More...
 
static void geo_process_object (struct Object *node)
 Process an object node. More...
 
static void geo_process_object_parent (struct GraphNodeObjectParent *node)
 Process an object parent node. More...
 
void geo_process_held_object (struct GraphNodeHeldObject *node)
 Process a held object node. More...
 
void geo_try_process_children (struct GraphNode *node)
 Processes the children of the given GraphNode if it has any. More...
 
void geo_process_node_and_siblings (struct GraphNode *firstNode)
 Process a generic geo node and its siblings. More...
 
void geo_process_root (struct GraphNodeRoot *node, Vp *b, Vp *c, s32 clearColor)
 Process a root node. More...
 

Variables

s16 gMatStackIndex
 This file contains the code that processes the scene graph for rendering. More...
 
Mat4 gMatStack [32]
 
MtxgMatStackFixed [32]
 
struct GeoAnimState gGeoTempState
 
u8 gCurAnimType
 
u8 gCurAnimEnabled
 
s16 gCurrAnimFrame
 
f32 gCurAnimTranslationMultiplier
 
u16gCurrAnimAttribute
 
s16gCurAnimData
 
struct AllocOnlyPoolgDisplayListHeap
 
struct RenderModeContainer renderModeTable_1Cycle [2]
 
struct RenderModeContainer renderModeTable_2Cycle [2]
 
struct GraphNodeRootgCurGraphNodeRoot = NULL
 
struct GraphNodeMasterListgCurGraphNodeMasterList = NULL
 
struct GraphNodePerspectivegCurGraphNodeCamFrustum = NULL
 
struct GraphNodeCameragCurGraphNodeCamera = NULL
 
struct GraphNodeObjectgCurGraphNodeObject = NULL
 
struct GraphNodeHeldObjectgCurGraphNodeHeldObject = NULL
 
u16 gAreaUpdateCounter = 0
 

Function Documentation

◆ geo_append_display_list()

static void geo_append_display_list ( void displayList,
s16  layer 
)
static

Appends the display list to one of the master lists based on the layer parameter.

Look at the RenderModeContainer struct to see the corresponding render modes of layers.

◆ geo_process_animated_part()

static void geo_process_animated_part ( struct GraphNodeAnimatedPart node)
static

Render an animated part.

The current animation state is not part of the node but set in global variables. If an animated part is skipped, everything afterwards desyncs.

◆ geo_process_background()

static void geo_process_background ( struct GraphNodeBackground node)
static

Process a background node.

Tries to retrieve a background display list from the function of the node. If that function is null or returns null, a black rectangle is drawn instead.

◆ geo_process_billboard()

static void geo_process_billboard ( struct GraphNodeBillboard node)
static

Process a billboard node.

A transformation matrix is created that makes its children face the camera, and it is pushed on the floating point and fixed point matrix stacks. For the rest it acts as a normal display list node.

◆ geo_process_camera()

static void geo_process_camera ( struct GraphNodeCamera node)
static

Process a camera node.

◆ geo_process_display_list()

static void geo_process_display_list ( struct GraphNodeDisplayList node)
static

Process a display list node.

It draws a display list without first pushing a transformation on the stack, so all transformations are inherited from the parent node. It processes its children if it has them.

◆ geo_process_generated_list()

static void geo_process_generated_list ( struct GraphNodeGenerated node)
static

Process a generated list.

Instead of storing a pointer to a display list, the list is generated on the fly by a function.

◆ geo_process_held_object()

void geo_process_held_object ( struct GraphNodeHeldObject node)

Process a held object node.

◆ geo_process_level_of_detail()

static void geo_process_level_of_detail ( struct GraphNodeLevelOfDetail node)
static

Process a level of detail node.

From the current transformation matrix, the perpendicular distance to the camera is extracted and the children of this node are only processed if that distance is within the render range of this node.

◆ geo_process_master_list()

static void geo_process_master_list ( struct GraphNodeMasterList node)
static

Process the master list node.

◆ geo_process_master_list_sub()

static void geo_process_master_list_sub ( struct GraphNodeMasterList node)
static

Process a master list node.

Bug:
This is where the LookAt values should be calculated but aren't. As a result, environment mapping is broken on Fast3DEX2 without the changes below.

◆ geo_process_node_and_siblings()

void geo_process_node_and_siblings ( struct GraphNode firstNode)

Process a generic geo node and its siblings.

The first argument is the start node, and all its siblings will be iterated over.

◆ geo_process_object()

static void geo_process_object ( struct Object node)
static

Process an object node.

◆ geo_process_object_parent()

static void geo_process_object_parent ( struct GraphNodeObjectParent node)
static

Process an object parent node.

Temporarily assigns itself as the parent of the subtree rooted at 'sharedChild' and processes the subtree, after which the actual children are be processed. (in practice they are null though)

◆ geo_process_ortho_projection()

static void geo_process_ortho_projection ( struct GraphNodeOrthoProjection node)
static

Process an orthographic projection node.

◆ geo_process_perspective()

static void geo_process_perspective ( struct GraphNodePerspective node)
static

Process a perspective projection node.

◆ geo_process_root()

void geo_process_root ( struct GraphNodeRoot node,
Vp b,
Vp c,
s32  clearColor 
)

Process a root node.

This is the entry point for processing the scene graph. The root node itself sets up the viewport, then all its children are processed to set up the projection and draw display lists.

◆ geo_process_rotation()

static void geo_process_rotation ( struct GraphNodeRotation node)
static

Process a rotation node.

A transformation matrix based on the node's rotation is created and pushed on both the float and fixed point matrix stacks. For the rest it acts as a normal display list node.

◆ geo_process_scale()

static void geo_process_scale ( struct GraphNodeScale node)
static

Process a scaling node.

A transformation matrix based on the node's scale is created and pushed on both the float and fixed point matrix stacks. For the rest it acts as a normal display list node.

◆ geo_process_shadow()

static void geo_process_shadow ( struct GraphNodeShadow node)
static

Process a shadow node.

Renders a shadow under an object offset by the translation of the first animated component and rotated according to the floor below it.

◆ geo_process_switch()

static void geo_process_switch ( struct GraphNodeSwitchCase node)
static

Process a switch case node.

The node's selection function is called if it is 0, and among the node's children, only the selected child is processed next.

◆ geo_process_translation()

static void geo_process_translation ( struct GraphNodeTranslation node)
static

Process a translation node.

A transformation matrix based on the node's translation is created and pushed on both the float and fixed point matrix stacks. For the rest it acts as a normal display list node.

◆ geo_process_translation_rotation()

static void geo_process_translation_rotation ( struct GraphNodeTranslationRotation node)
static

Process a translation / rotation node.

A transformation matrix based on the node's translation and rotation is created and pushed on both the float and fixed point matrix stacks. For the rest it acts as a normal display list node.

◆ geo_set_animation_globals()

void geo_set_animation_globals ( struct GraphNodeObject_sub node,
s32  hasAnimation 
)

Initialize the animation-related global variables for the currently drawn object's animation.

◆ geo_try_process_children()

void geo_try_process_children ( struct GraphNode node)

Processes the children of the given GraphNode if it has any.

◆ obj_is_in_view()

static int obj_is_in_view ( struct GraphNodeObject node,
Mat4  matrix 
)
static

Check whether an object is in view to determine whether it should be drawn.

This is known as frustrum culling. It checks whether the object is far away, very close / behind the camera, or horizontally out of view. It does not check whether it is vertically out of view. It assumes a sphere of 300 units around the object's position unless the object has a culling radius node that specifies otherwise.

The matrix parameter should be the top of the matrix stack, which is the object's transformation matrix times the camera 'look-at' matrix. The math is counter-intuitive, but it checks column 3 (translation vector) of this matrix to determine where the origin (0,0,0) in object space will be once transformed to camera space (x+ = right, y+ = up, z = 'coming out the screen'). In 3D graphics, you typically model the world as being moved in front of a static camera instead of a moving camera through a static world, which in this case simplifies calculations. Note that the perspective matrix is not on the matrix stack, so there are still calculations with the fov to compute the slope of the lines of the frustrum.

   z-

\ | / \ | / \ | / \ | / \ | / |/ C x+

Since (0,0,0) is unaffected by rotation, columns 0, 1 and 2 are ignored.

Why is there a f32 cast?

This makes the HOLP not update when the camera is far away, and it

Variable Documentation

◆ gAreaUpdateCounter

u16 gAreaUpdateCounter = 0

◆ gCurAnimData

s16* gCurAnimData

◆ gCurAnimEnabled

u8 gCurAnimEnabled

◆ gCurAnimTranslationMultiplier

f32 gCurAnimTranslationMultiplier

◆ gCurAnimType

u8 gCurAnimType

◆ gCurGraphNodeCamera

struct GraphNodeCamera* gCurGraphNodeCamera = NULL

◆ gCurGraphNodeCamFrustum

struct GraphNodePerspective* gCurGraphNodeCamFrustum = NULL

◆ gCurGraphNodeHeldObject

struct GraphNodeHeldObject* gCurGraphNodeHeldObject = NULL

◆ gCurGraphNodeMasterList

struct GraphNodeMasterList* gCurGraphNodeMasterList = NULL

◆ gCurGraphNodeObject

struct GraphNodeObject* gCurGraphNodeObject = NULL

◆ gCurGraphNodeRoot

struct GraphNodeRoot* gCurGraphNodeRoot = NULL

◆ gCurrAnimAttribute

u16* gCurrAnimAttribute

◆ gCurrAnimFrame

s16 gCurrAnimFrame

◆ gDisplayListHeap

struct AllocOnlyPool* gDisplayListHeap

◆ gGeoTempState

struct GeoAnimState gGeoTempState

◆ gMatStack

Mat4 gMatStack[32]

◆ gMatStackFixed

Mtx* gMatStackFixed[32]

◆ gMatStackIndex

s16 gMatStackIndex

This file contains the code that processes the scene graph for rendering.

The scene graph is responsible for drawing everything except the HUD / text boxes. First the root of the scene graph is processed when geo_process_root is called from level_script.c. The rest of the tree is traversed recursively using the function geo_process_node_and_siblings, which switches over all geo node types and calls a specialized function accordingly. The types are defined in engine/graph_node.h

The scene graph typically looks like:

  • Root (viewport)
    • Master list
      • Ortho projection
        • Background (skybox)
    • Master list
      • Perspective
        • Camera
          • <area-specific display lists>
          • Object parent
            • <group with 240 object nodes>
    • Master list
      • Script node (Cannon overlay)

◆ renderModeTable_1Cycle

struct RenderModeContainer renderModeTable_1Cycle[2]
Initial value:
= { { {
} },
{ {
} } }
#define G_RM_AA_ZB_XLU_DECAL
Definition: gbi.h:913
#define G_RM_AA_ZB_XLU_INTER
Definition: gbi.h:917
#define G_RM_AA_ZB_OPA_DECAL
Definition: gbi.h:911
#define G_RM_AA_ZB_OPA_INTER
Definition: gbi.h:915
#define G_RM_OPA_SURF
Definition: gbi.h:984
#define G_RM_AA_ZB_TEX_EDGE
Definition: gbi.h:923
#define G_RM_AA_TEX_EDGE
Definition: gbi.h:953
#define G_RM_AA_OPA_SURF
Definition: gbi.h:945
#define G_RM_AA_ZB_XLU_SURF
Definition: gbi.h:909
#define G_RM_ZB_OPA_SURF
Definition: gbi.h:969
#define G_RM_AA_XLU_SURF
Definition: gbi.h:947
#define G_RM_AA_ZB_OPA_SURF
Definition: gbi.h:907

◆ renderModeTable_2Cycle

struct RenderModeContainer renderModeTable_2Cycle[2]
Initial value:
= { { {
} },
{ {
} } }
#define G_RM_AA_TEX_EDGE2
Definition: gbi.h:954
#define G_RM_OPA_SURF2
Definition: gbi.h:985
#define G_RM_AA_ZB_XLU_DECAL2
Definition: gbi.h:914
#define G_RM_AA_ZB_OPA_DECAL2
Definition: gbi.h:912
#define G_RM_AA_ZB_OPA_INTER2
Definition: gbi.h:916
#define G_RM_AA_OPA_SURF2
Definition: gbi.h:946
#define G_RM_AA_ZB_XLU_SURF2
Definition: gbi.h:910
#define G_RM_AA_ZB_OPA_SURF2
Definition: gbi.h:908
#define G_RM_AA_ZB_TEX_EDGE2
Definition: gbi.h:924
#define G_RM_AA_XLU_SURF2
Definition: gbi.h:948
#define G_RM_ZB_OPA_SURF2
Definition: gbi.h:970
#define G_RM_AA_ZB_XLU_INTER2
Definition: gbi.h:918