Garry's Mod Wiki

Revision Difference

Render_Order#522303

<cat>Dev</cat> # Render Order This is the call order for . The lower a hook is on the list, the higher priority it has for drawing. This list is only to be used for priority reference; in reality, while rendering a frame, the engine might call certain groups of hooks multiple times to achieve reflective properties, draw render targets, and fulfill <page>render.RenderView</page> or <page>render.RenderHUD</page> calls. Hook | Render context | Notes | -----|----------------|------| | <page>WEAPON:RenderScreen</page> | None | Call condition: Weapon is scripted. Context must be setup with <page>cam</page> to draw | | <page>GM:RenderScene</page> | None | Context must be setup with <page>cam</page> to draw. Returning true in this hook will skip all the way down to <page>GM:PostRender</page> | | <page>GM:DrawMonitors</page> | None | Context must be setup with <page>cam</page> to draw | | <page>GM:PreDrawSkyBox</page> | 3D | Call condition: r_3dsky is enabled and <page>Global.EyePos</page> is in world bounds | | <page>GM:SetupSkyboxFog</page> | 3D | Call condition: r_3dsky is enabled and <page>Global.EyePos</page> is in world bounds | | <page>WEAPON:TranslateFOV</page> | 3D | Call condition: Weapon is scripted | | <page>GM:PostDraw2DSkyBox</page> | 3D | Call condition: r_skybox, r_drawopaqueworld, and r_drawworld are enabled, and <page>Global.EyePos</page> is in world bounds | | <page text="DrawOpaqueRenderables">#DrawOpaqueRenderables</page>(false, r_skybox is enabled) | 3D | Call condition: r_3dsky, r_drawentities, and r_drawopaquerenderables are enabled and <page>Global.EyePos</page> is in world bounds. For opaque entities in the skybox | | <page text="DrawTranslucentRenderables">#DrawTranslucentRenderables</page>(false, r_skybox is enabled) | 3D | Call condition: r_3dsky is enabled and <page>Global.EyePos</page> is in world bounds. For translucent entities in the skybox | | [DrawOpaqueRenderables](#drawopaquerenderables)(false, r_skybox is enabled) | 3D | Call condition: r_3dsky, r_drawentities, and r_drawopaquerenderables are enabled and <page>Global.EyePos</page> is in world bounds. For opaque entities in the skybox | | [DrawTranslucentRenderables](#drawtranslucentrenderables)(false, r_skybox is enabled) | 3D | Call condition: r_3dsky is enabled and <page>Global.EyePos</page> is in world bounds. For translucent entities in the skybox | | <page>GM:PostDrawSkyBox</page> | 3D | Call condition: r_3dsky is enabled and <page>Global.EyePos</page> is in world bounds | | <page text="DrawWaterReflections">#DrawWaterReflections</page> | 3D | Call condition: r_WaterDrawReflection and r_drawworld is enabled and reflective water is visible | | <page text="DrawWorld">#DrawWorld</page> | 3D | | | [DrawWaterReflections](#drawwaterreflections) | 3D | Call condition: r_WaterDrawReflection and r_drawworld is enabled and reflective water is visible | | [DrawWorld](#drawworld) | 3D | | | <page>GM:GetMotionBlurValues</page> | 3D | | | <page>GM:PreDrawViewModel</page> | 3D | <bug issue="3024">This is called once with no arguments.</bug> | | <page>ENTITY:Draw</page> | 3D | For animated scripted entities with rendergroup RENDERGROUP_VIEWMODEL | | <page>ENTITY:RenderOverride</page> | 3D | For non-viewmodel entities or viewmodels not linked to a weapon with rendergroup RENDERGROUP_VIEWMODEL | | <page>GM:PreDrawViewModel</page> | 3D | For engine "viewmodel" and "predicted_viewmodel" entities linked to a weapon | | <page>WEAPON:PreDrawViewModel</page> | 3D | [Dependent on gamemode implementation](https://github.com/Facepunch/garrysmod/blob/784cd57576d85712fa13a7cea3a9523b4df966b0/garrysmod/gamemodes/base/gamemode/cl_init.lua#L580) | | <page>ENTITY:RenderOverride</page> | 3D | For engine "viewmodel" and "predicted_viewmodel" entities linked to a weapon | | <page>WEAPON:ViewModelDrawn</page> | 3D | For engine "viewmodel" and "predicted_viewmodel" entities linked to a weapon | | <page>GM:PostDrawViewModel</page> | 3D | For engine "viewmodel" and "predicted_viewmodel" entities linked to a weapon | | <page>WEAPON:PostDrawViewModel</page> | 3D | [Dependent on gamemode implementation](https://github.com/Facepunch/garrysmod/blob/784cd57576d85712fa13a7cea3a9523b4df966b0/garrysmod/gamemodes/base/gamemode/cl_init.lua#L614) | | <page>GM:PreDrawPlayerHands</page> | 3D | [Dependent on gamemode implementation](https://github.com/Facepunch/garrysmod/blob/784cd57576d85712fa13a7cea3a9523b4df966b0/garrysmod/gamemodes/base/gamemode/cl_init.lua#L597) | | <page>ENTITY:RenderOverride</page> | 3D | [Dependent on gamemode implementation](https://github.com/Facepunch/garrysmod/blob/784cd57576d85712fa13a7cea3a9523b4df966b0/garrysmod/gamemodes/base/gamemode/cl_init.lua#L600) | | <page>GM:PostDrawPlayerHands</page> | 3D | [Dependent on gamemode implementation](https://github.com/Facepunch/garrysmod/blob/784cd57576d85712fa13a7cea3a9523b4df966b0/garrysmod/gamemodes/base/gamemode/cl_init.lua#L605) | | <page>ENTITY:DrawTranslucent</page> | 3D | For animated scripted entities with rendergroup RENDERGROUP_VIEWMODEL_TRANSLUCENT | | <page>ENTITY:RenderOverride</page> | 3D | For entities with rendergroup RENDERGROUP_VIEWMODEL_TRANSLUCENT | | <page>GM:PreDrawEffects</page> | 3D | | | <page>GM:RenderScreenspaceEffects</page> | 2D | | | <page>GM:PostDrawEffects</page> | 2D | | | <page>GM:PreDrawHalos</page> | 2D | [Hook called from Lua](https://github.com/Facepunch/garrysmod/blob/master/garrysmod/lua/includes/modules/halo.lua#L148), which means more <page>GM:PostDrawEffects</page> hooks can be called afterward | | <page>GM:PreDrawHUD</page> | 2D | | | <page text="DrawActiveHUD">#DrawActiveHUD</page> | 2D | Call condition: r_drawvgui is enabled and game is not paused | | [DrawActiveHUD](#drawactivehud) | 2D | Call condition: r_drawvgui is enabled and game is not paused | | <page>GM:PostDrawHUD</page> | 2D | | | <page>GM:HUDShouldDraw</page> | 2D | Call condition: r_drawvgui is enabled. For NetGraph | | <page>GM:DrawOverlay</page> | 2D | Call condition: r_drawvgui is enabled | | <page>GM:PostRenderVGUI</page> | 2D | | | <page>GM:PostRender</page> | None | Context must be setup with <page>cam</page> to draw | # Hook Blocks For simplicity, "blocks" of hooks will be defined to reduce the repetitive listing of the same functions. These blocks can also relate to groups of methods in the Source renderer that are called multiple times. ## DrawWaterReflections Hook | Notes | -----|------| | <page>GM:SetupWorldFog</page> | | | <page>GM:PostDraw2DSkyBox</page> | Call condition: r_drawopaqueworld and r_drawworld are enabled | | <page text="DrawOpaqueRenderables">#DrawOpaqueRenderables</page>(false, true) | Call condition: r_drawopaquerenderables is enabled. Draws reflections for opaque entities in the world not completely submerged in reflective water | | <page text="DrawTranslucentRenderables">#DrawTranslucentRenderables</page>(false, false) | Draws reflections for translucent entities in the world not completely submerged in reflective water | | [DrawOpaqueRenderables](#drawopaquerenderables)(false, true) | Call condition: r_drawopaquerenderables is enabled. Draws reflections for opaque entities in the world not completely submerged in reflective water | | [DrawTranslucentRenderables](#drawtranslucentrenderables)(false, false) | Draws reflections for translucent entities in the world not completely submerged in reflective water | | <page>WEAPON:TranslateFOV</page> | Call condition: Weapon is scripted | | <page text="DrawOpaqueRenderables">#DrawOpaqueRenderables</page>(false, false) | Call condition: r_drawopaquerenderables is enabled. Draws refractions for opaque entities in reflective water | | <page text="DrawTranslucentRenderables">#DrawTranslucentRenderables</page>(false, false) | Draws refractions for translucent entities in reflective water | | [DrawOpaqueRenderables](#drawopaquerenderables)(false, false) | Call condition: r_drawopaquerenderables is enabled. Draws refractions for opaque entities in reflective water | | [DrawTranslucentRenderables](#drawtranslucentrenderables)(false, false) | Draws refractions for translucent entities in reflective water | ## DrawWorld Hook | Notes | -----|------| | <page>GM:NeedsDepthPass</page> | | | <page>GM:SetupWorldFog</page> | | | <page text="DrawOpaqueRenderables">#DrawOpaqueRenderables</page>(false, false) | Call condition: r_drawentities and r_drawopaquerenderables are enabled. For opaque entities in the world not completely submerged in reflective water | | <page text="DrawTranslucentRenderables">#DrawTranslucentRenderables</page>(false, false) | For translucent entities in the world not completely submerged in reflective water | | [DrawOpaqueRenderables](#drawopaquerenderables)(false, false) | Call condition: r_drawentities and r_drawopaquerenderables are enabled. For opaque entities in the world not completely submerged in reflective water | | [DrawTranslucentRenderables](#drawtranslucentrenderables)(false, false) | For translucent entities in the world not completely submerged in reflective water | ## DrawOpaqueRenderables This block specifies two boolean arguments that point to what PreDraw*Renderables and PostDraw*Renderables will be called with. The first arg is true if the rendering is writing to the depth buffer, and the second is true if the rendering is being done for skybox objects. <page>GM:PrePlayerDraw</page> and <page>GM:PostPlayerDraw</page> will be called for every visible, opaque player, just as <page>ENTITY:RenderOverride</page> will be for every visible, opaque entity. The order in which entities are drawn is based on their distance from the viewport in the world, and thus the entity type hook pairings can be called in any order. In other words, the entity hooks can be called before the player hooks depending on the object render order. With that, the only guarenteed hook orderings are: * (<page>GM:ShouldDrawLocalPlayer</page> is checked first if the player entity being drawn is the local player) -> <page>ENTITY:RenderOverride</page> -> <page>GM:PrePlayerDraw</page> -> <page>GM:PostPlayerDraw</page> for players * (<page>ENTITY:Draw</page> if the entity is scripted and animated) -> <page>ENTITY:RenderOverride</page> for entities * (<page>WEAPON:DrawWorldModel</page> if the weapon is scripted) -> <page>ENTITY:RenderOverride</page> for weapons Opaque rendergroups include RENDERGROUP_OPAQUE_HUGE, RENDERGROUP_OPAQUE, RENDERGROUP_BOTH, and RENDERGROUP_OPAQUE_BRUSH. Hook | Notes | -----|------| | <page>GM:ShouldDrawLocalPlayer</page> | Called if the local player is opaque, the thirdperson concommand is not active, and <page>GM:CalcView</page> did not return a table with key "drawviewer" set to true. The return will be cached for all other relevant Draw*Renderables blocks so that it is only called once per frame | | <page>ENTITY:RenderOverride</page> | For opaque players | | <page>GM:PrePlayerDraw</page> | For opaque players | | <page>GM:PostPlayerDraw</page> | For opaque players | | <page>ENTITY:Draw</page> | For opaque, animated scriped entities | | <page>ENTITY:RenderOverride</page> | For opaque entities | | <page>WEAPON:DrawWorldModel</page> | For opaque scriped weapons | | <page>ENTITY:RenderOverride</page> | For opaque weapons | | <page>GM:PostDrawOpaqueRenderables</page>(isDrawingDepth, isDrawingSkybox) | | ## DrawTranslucentRenderables All of the prior logic from DrawOpaqueRenderables applies here. Translucent rendergroups include RENDERGROUP_TRANSLUCENT and RENDERGROUP_BOTH. Hook | Notes | -----|------| | <page>GM:ShouldDrawLocalPlayer</page> | Called if the local player is translucent, the thirdperson concommand is not active, and <page>GM:CalcView</page> did not return a table with key "drawviewer" set to true. The return will be cached for all other relevant Draw*Renderables blocks so that it is only called once per frame | | <page>ENTITY:RenderOverride</page> | For translucent players | | <page>GM:PrePlayerDraw</page> | For translucent players | | <page>GM:PostPlayerDraw</page> | For translucent players | | <page>ENTITY:Draw</page> | For translucent, animated scriped entities | | <page>ENTITY:RenderOverride</page> | For translucent entities | | <page>WEAPON:DrawWorldModelTranslucent</page> | For translucent scriped weapons | | <page>ENTITY:RenderOverride</page> | For translucent weapons | | <page>GM:DrawPhysgunBeam</page> | For engine physgun_beam entities | | <page>GM:PostDrawTranslucentRenderables</page>(isDrawingDepth, isDrawingSkybox) | | ## DrawActiveHUD Hook | Notes | -----|------| | <page>WEAPON:DrawHUDBackground</page> | Call condition: Weapon is scripted | | <page>GM:HUDPaint</page> | | | <page>GM:HUDDrawTargetID</page> | | | <page>GM:HUDDrawPickupHistory</page> | | | <page>GM:DrawDeathNotice</page> | | | <page>WEAPON:DrawHUD</page> | | | <page>GM:HUDDrawScoreBoard</page> | | | <page>WEAPON:TranslateFOV</page> | Call condition: Weapon is scripted | | <page>WEAPON:DoDrawCrosshair</page> | Call condition: Weapon is scripted and has SWEP.DrawCrosshair set to true | | <page>GM:HUDShouldDraw</page> | For CHudWeaponSelection |