Garry's Mod Wiki

render

The render library is a powerful set of functions that let you control how the world and its contents are rendered. It can also be used to draw some 3D clientside effects such as beams, boxes and spheres.

Methods

render.AddBeam( Vector startPos, number width, number textureEnd, table color )
Adds a beam segment to the beam started by render. StartBeam.
render.BlurRenderTarget( ITexture rendertarget, number blurx, number blury, number passes )
Blurs the render target ( or a given texture ) Calling this on a RenderTarget created with TEXTUREFLAGS_POINTSAMPLE will result in strange visual glitching.
render.BrushMaterialOverride( IMaterial mat = nil )
This function overrides the brush material for next render operations. It can be used with Entity:DrawModel.
string render.Capture( table captureData )
Captures a part of the current render target and returns the data as a binary string in the given format. Since the pixel buffer clears itself every frame, this will return a black screen outside of render hooks. To capture the user's final view, use GM:PostRender. This will not capture the Steam overlay or third-party injections (such as the Discord overlay, Overwolf, and advanced cheats) on the user's screen. In PNG mode, this function can produce unexpected result where foreground is rendered as transparent. This is caused by render. SetWriteDepthToDestAlpha set to true when doing most of render operations, including rendering in _rt_fullframefb. If you want to capture render target's content as PNG image only for output quality, set RenderCaptureData structure's alpha to false when capturing render targets with render. SetWriteDepthToDestAlpha set to true. Issue Tracker: 2571
render.CapturePixels()
This is a rendering function that requires a 2d rendering context. This means that it will only work in 2d Rendering Hooks. Dumps the current render target and allows the pixels to be accessed by render. ReadPixel. Capturing outside a render hook will return 0 0 0 255
render.Clear( number r, number g, number b, number a, boolean clearDepth = false, boolean clearStencil = false )
Clears the current render target and the specified buffers. This sets the alpha incorrectly for surface draw calls for render targets. Issue Tracker: 2085
Clears the portion of the active Render Target that passes the current stencil buffer conditions.
render.ClearDepth( boolean clearStencil = true )
Resets the depth buffer.
render.ClearRenderTarget( ITexture texture, table color )
Clears a render target It uses render. Clear then render. SetRenderTarget on the modified render target.
render.ClearStencil()
Resets all values in the stencil buffer to zero.
render.ClearStencilBufferRectangle( number originX, number originY, number endX, number endY, number stencilValue )
Sets the stencil value in a specified rect. This is not affected by render. SetStencilWriteMask
Vector render.ComputeDynamicLighting( Vector position, Vector normal )
Calculates the lighting caused by dynamic lights for the specified surface.
Vector render.ComputeLighting( Vector position, Vector normal )
Calculates the light color of a certain surface.
Calculates diameter of a 3D sphere on a 2D screen. This is a rendering function that requires a 3d rendering context. This means that it will only work in 3d Rendering Hooks.
Copies the currently active Render Target to the specified texture. This does not copy the Depth buffer, no method for that is known at this moment so a common workaround is to store the source texture somewhere else, perform your drawing operations, save the result somewhere else and reapply the source texture.
render.CopyTexture( ITexture texture_from, ITexture texture_to )
Copies the contents of one texture to another. Only works with rendertargets. This does not copy the Depth buffer, no method for that is known at this moment so a common workaround is to store the source texture somewhere else, perform your drawing operations, save the result somewhere else and reapply the source texture.
render.CullMode( number cullMode )
Sets the cull mode. The culling mode defines how back faces are culled when rendering geometry.
render.DepthRange( number depthmin, number depthmax )
Set's the depth range of the upcoming render.
render.DrawBeam( Vector startPos, Vector endPos, number width, number textureStart, number textureEnd, Color color = Color( 255, 255, 255 ) )
This is a rendering function that requires a 3d rendering context. This means that it will only work in 3d Rendering Hooks. Draws a single-segment Beam made out of a textured, billboarded quad stretching between two points. For more detailed information, including usage examples, see the Beams Rendering Reference
render.DrawBox( Vector position, Angle angles, Vector mins, Vector maxs, table color = Color( 255, 255, 255 ) )
Draws a box in 3D space. This is a rendering function that requires a 3d rendering context. This means that it will only work in 3d Rendering Hooks.
render.DrawLine( Vector startPos, Vector endPos, table color = Color( 255, 255, 255 ), boolean writeZ = false )
Draws a line in 3D space. This is a rendering function that requires a 3d rendering context. This means that it will only work in 3d Rendering Hooks.
render.DrawQuad( Vector vert1, Vector vert2, Vector vert3, Vector vert4, table color = Color( 255, 255, 255 ) )
Draws 2 connected triangles. Expects material to be set by render. SetMaterial. This is a rendering function that requires a 3d rendering context. This means that it will only work in 3d Rendering Hooks.
render.DrawQuadEasy( Vector position, Vector normal, number width, number height, table color, number rotation = 0 )
Draws a quad. This is a rendering function that requires a 3d rendering context. This means that it will only work in 3d Rendering Hooks.
render.DrawScreenQuad( boolean applyPoster = false )
Draws the current material set by render. SetMaterial to the whole screen. The color cannot be customized. See also render. DrawScreenQuadEx. This is a rendering function that requires a 2d rendering context. This means that it will only work in 2d Rendering Hooks.
render.DrawScreenQuadEx( number startX, number startY, number width, number height )
Draws the current material set by render. SetMaterial to the area specified. Color cannot be customized. See also render. DrawScreenQuad. This is a rendering function that requires a 2d rendering context. This means that it will only work in 2d Rendering Hooks.
render.DrawSphere( Vector position, number radius, number longitudeSteps, number latitudeSteps, table color = Color( 255, 255, 255 ) )
Draws a sphere in 3D space. The material previously set with render. SetMaterial will be applied the sphere's surface. See also render. DrawWireframeSphere for a wireframe equivalent. This is a rendering function that requires a 3d rendering context. This means that it will only work in 3d Rendering Hooks.
render.DrawSprite( Vector position, number width, number height, table color = Color( 255, 255, 255 ) )
Draws a sprite in 3D space. This is a rendering function that requires a 3d rendering context. This means that it will only work in 3d Rendering Hooks.
Draws a texture over the whole screen. This is a rendering function that requires a 2d rendering context. This means that it will only work in 2d Rendering Hooks.
render.DrawTextureToScreenRect( ITexture tex, number x, number y, number width, number height )
Draws a textured rectangle. This is a rendering function that requires a 2d rendering context. This means that it will only work in 2d Rendering Hooks.
render.DrawWireframeBox( Vector position, Angle angle, Vector mins, Vector maxs, table color = Color( 255, 255, 255 ), boolean writeZ = false )
Draws a wireframe box in 3D space. This is a rendering function that requires a 3d rendering context. This means that it will only work in 3d Rendering Hooks.
render.DrawWireframeSphere( Vector position, number radius, number longitudeSteps, number latitudeSteps, table color = Color( 255, 255, 255 ), boolean writeZ = false )
Draws a wireframe sphere in 3d space. This is a rendering function that requires a 3d rendering context. This means that it will only work in 3d Rendering Hooks.
Sets the status of the clip renderer, returning previous state. To prevent unintended rendering behavior of other mods/the game, you must reset the clipping state to its previous value.
render.EndBeam()
Ends the beam mesh of a beam started with render. StartBeam.
render.FogColor( number red, number green, number blue )
Sets the color of the fog.
render.FogEnd( number distance )
Sets the at which the fog reaches its max density.
render.FogMaxDensity( number maxDensity )
Sets the maximum density of the fog.
render.FogMode( number fogMode )
Sets the mode of fog.
render.FogStart( number fogStart )
Sets the distance at which the fog starts showing up.
Returns the ambient color of the map.
number render.GetBlend()
Returns the current alpha blending.
This is used internally - although you're able to use it you probably shouldn't. You can use GetRenderTargetEx if you need to create a Render Target Returns the Render Target texture that is used internally for the Bloom Post Processing effect.
This is used internally - although you're able to use it you probably shouldn't. You probably want to just use a custom render target. See GetRenderTargetEx. Returns the Render Target texture used internally for the Blur Post Processing effect. Despite its name, this function is not used for the Bloom effect.
Returns the current color modulation values as normals.
Returns the maximum available directX version.
Returns the current fog color.
Returns the fog start and end distance.
Returns the fog mode.
Returns the full screen depth texture.
Returns whether HDR is currently enabled or not. This takes into account hardware support, current map and current client settings.
Vector render.GetLightColor( Vector position )
Gets the light exposure on the specified position.
This is used internally - although you're able to use it you probably shouldn't. You probably want to just use a custom render target. See GetRenderTargetEx. Returns the first render target texture that is used internally for Motion Blur and Frame Blend post processing effects.
This is used internally - although you're able to use it you probably shouldn't. You probably want to just use a custom render target. See GetRenderTargetEx. Returns the second render target texture that is used internally for Motion Blur and Frame Blend post processing effects.
This is used internally - although you're able to use it you probably shouldn't. You probably want to just use a custom render target. See GetRenderTargetEx. Returns the first render target texture that was used internally for Morph post processing effect The post processing effect was removed from the base game at some point during development of Garry's Mod 13, but can still be found as a community mod: https://steamcommunity. com/sharedfiles/filedetails/?id=501088470
This is used internally - although you're able to use it you probably shouldn't. You probably want to just use a custom render target. See GetRenderTargetEx. Returns the second render target texture that was used internally for Morph post processing effect. See render. GetMorphTex0 for more information. .
Returns the Power Of Two Frame Buffer texture.
We advise against using this. It may be changed or removed in a future update. Alias of render. GetPowerOfTwoTexture. Alias of render. GetPowerOfTwoTexture.
Returns the currently active render target. Instead of saving the current render target using this function and restoring to it later, it is generally better practice to use render. PushRenderTarget and render. PopRenderTarget.
Returns the _rt_ResolvedFullFrameDepth texture for SSAO depth. It will only be updated if GM:NeedsDepthPass returns true.
ITexture render.GetScreenEffectTexture( number textureIndex = 0 )
Obtain an ITexture of the screen. You must call render. UpdateScreenEffectTexture in order to update this texture with the currently rendered scene. This texture is mainly used within GM:RenderScreenspaceEffects
Returns the first quarter sized frame buffer texture.
Returns the second quarter sized frame buffer texture.
Returns a floating point texture (RGBA16161616F format) the same resolution as the screen. The gmodscreenspace doesn't behave as expected when drawing a floating-point texture to an integer texture (e. g. the default render target). Use an UnlitGeneric material instead
See render. GetSuperFPTex
Vector render.GetSurfaceColor( Vector startPos, Vector endPos )
Performs a render trace and returns the color of the surface hit, this uses a low res version of the texture.
Returns a vector representing linear tone mapping scale.
table render.GetViewSetup( boolean noPlayer = false )
Returns the current view setup.
render.MaterialOverride( IMaterial material = nil )
Sets the render material override for all next calls of Entity:DrawModel. Also overrides render. MaterialOverrideByIndex.
render.MaterialOverrideByIndex( number index = nil, IMaterial material = nil )
Similar to render. MaterialOverride, but overrides the materials per index. Similar to Entity:SetSubMaterial render. MaterialOverride overrides effects of this function.
Returns the maximum texture height the renderer can handle.
Returns the maximum texture width the renderer can handle.
render.Model( table settings, CSEnt ent = nil )
Creates a new ClientsideModel, renders it at the specified pos/ang, and removes it. Can also be given an existing CSEnt to reuse instead. This function is only meant to be used in a single render pass kind of scenario, if you need to render a model continuously, use a cached ClientsideModel and provide it as a second argument. Using this with a map model (game. GetWorld():GetModel()) crashes the game. Issue Tracker: 2688
render.ModelMaterialOverride( IMaterial material )
Sets a material to override a model's default material. Similar to Entity:SetMaterial except it uses an IMaterial argument and it can be used to change materials on models which are part of the world geometry.
render.OverrideAlphaWriteEnable( boolean enable, boolean shouldWrite )
Overrides the write behaviour of all next rendering operations towards the alpha channel of the current render target. See also render. OverrideBlend. Doing surface draw calls with alpha set to 0 is a no-op and will never have any effect.
render.OverrideBlend( boolean enabled, number srcBlend, number destBlend, number blendFunc, number srcBlendAlpha = none, number destBlendAlpha = none, number blendFuncAlpha = none )
Overrides the internal graphical functions used to determine the final color and alpha of a rendered texture. See also render. OverrideAlphaWriteEnable. Doing surface draw calls with alpha set to 0 is a no-op and won't have an effect.
render.OverrideBlendFunc( boolean enabled, number srcBlend, number destBlend, number srcBlendAlpha = nil, number destBlendAlpha = nil )
We advise against using this. It may be changed or removed in a future update. Use render. OverrideBlend instead. Overrides the internal graphical functions used to determine the final color and alpha of a rendered texture. See also render. OverrideAlphaWriteEnable. Doing surface draw calls with alpha set to 0 is a no-op and will never have any effect.
render.OverrideColorWriteEnable( boolean enable, boolean shouldWrite )
Overrides the write behaviour of all next rendering operations towards the color channel of the current render target.
render.OverrideDepthEnable( boolean enable, boolean shouldWrite )
Overrides the write behaviour of all next rendering operations towards the depth buffer.
Perform stencil operations to every pixel on the screen.
Removes the current active clipping plane from the clip plane stack.
render.PopFilterMag()
Pops (Removes) the texture filter most recently pushed (Added) onto the magnification texture filter stack. This function should only be called after a magnification filter has been pushed via render. PushFilterMag() For more detailed information and a usage example, see the texture minification and magnification render reference.
render.PopFilterMin()
Pops (Removes) the texture filter most recently pushed (Added) onto the minification texture filter stack. This function should only be called after a minification filter has been pushed via render. PushFilterMin() For more detailed information and a usage example, see the texture minification and magnification render reference.
Pops the current flashlight mode from the flashlight mode stack.
render.PopRenderTarget()
Pops the last render target and viewport from the RT stack and sets them as the current render target and viewport. This is should be called to restore the previous render target and viewport after a call to render. PushRenderTarget.
render.PushCustomClipPlane( Vector normal, number distance )
Pushes a new clipping plane of the clip plane stack and sets it as active. A max of 2 clip planes are supported on Linux/POSIX, and 6 on Windows. Issue Tracker: 2687
render.PushFilterMag( number texFilterType )
Pushes (Adds) a texture filter onto the magnification texture filter stack. This will modify how textures are stretched to sizes larger than their native resolution for upcoming rendering and drawing operations. For a version of this same function that modifies filtering for texture sizes smaller than their native resolution, see render. PushFilterMin() Always be sure to call render. PopFilterMag() afterwards to avoid texture filtering problems. For more detailed information and a usage example, see the texture minification and magnification render reference.
render.PushFilterMin( number texFilterType )
Pushes (Adds) a texture filter onto the minification texture filter stack. This will modify how textures are compressed to a lower resolution than their native resolution for upcoming rendering and drawing operations. For a version of this same function that modifies filtering for texture sizes larger than their native resolution, see render. PushFilterMag() Always be sure to call render. PopFilterMin() afterwards to avoid texture filtering problems. For more detailed information and a usage example, see the texture minification and magnification render reference.
render.PushFlashlightMode( boolean enable = false )
Enables the flashlight projection for the upcoming rendering. We advise against using this. It may be changed or removed in a future update. This will leave models lit under specific conditions. You should use render. RenderFlashlights which is meant as a direct replacement for this function.
render.PushRenderTarget( ITexture texture, number x = 0, number y = 0, number w = texture:Width(), number h = texture:Height() )
Pushes the current render target and viewport to the RT stack then sets a new current render target and viewport. If the viewport is not specified, the dimensions of the render target are used instead. This is similar to a call to render. SetRenderTarget and render. SetViewPort where the current render target and viewport have been saved beforehand, except the viewport isn't clipped to screen bounds. See also render. PopRenderTarget. If you want to render to the render target in 2d mode and it is not the same size as the screen, use cam. Start2D and cam. End2D. If the render target is bigger than the screen, rendering done with the surface library will be clipped to the screen bounds unless you call DisableClipping
Reads the color of the specified pixel from the RenderTarget sent by render. CapturePixels
render.RedownloadAllLightmaps( boolean DoStaticProps = false, boolean UpdateStaticLighting = false )
This applies the changes made to map lighting using engine. LightStyle.
render.RenderFlashlights( function renderFunc )
Renders additive flashlights on an IMesh, a direct replacement for render. PushFlashlightMode.
render.RenderHUD( number x, number y, number w, number h )
Renders the HUD on the screen.
render.RenderView( table view = nil )
Renders the scene with the specified viewData to the current active render target. Static props and LODs are rendered improperly due to incorrectly perceived distance. Issue Tracker: 1330
Resets the model lighting to the specified color. Calls render. SetModelLighting for every direction with given color.
render.ResetToneMappingScale( number scale )
Resets the HDR tone multiplier to the specified value. This will only work on HDR maps, and the value will automatically fade to what it was ( or whatever render. SetGoalToneMappingScale is ) if called only once.
render.SetAmbientLight( number r, number g, number b )
Sets the ambient lighting for any upcoming render operation.
render.SetBlend( number blending )
Sets the alpha blending for every upcoming render operation. This does not affect non-model render. Draw* functions. Issue Tracker: 3166
Sets the current drawing material to "color". The material is defined as: "UnlitGeneric" { "$basetexture" "color/white" "$model" 1 "$translucent" 1 "$vertexalpha" 1 "$vertexcolor" 1 }
Sets the current drawing material to color_ignorez. The material is defined as: "UnlitGeneric" { "$basetexture" "color/white" "$model" 1 "$translucent" 1 "$vertexalpha" 1 "$vertexcolor" 1 "$ignorez" 1 }
Sets the color modulation.
render.SetFogZ( number fogZ )
If the fog mode is set to MATERIAL_FOG_LINEAR_BELOW_FOG_Z, the fog will only be rendered below the specified height.
Sets the goal HDR tone mapping scale. Use this in a rendering/think hook as it is reset every frame.
render.SetLightingMode( number Mode )
Sets lighting mode when rendering something. Do not forget to restore the default value to avoid unexpected behavior, like the world and the HUD/UI being affected
render.SetLightingOrigin( Vector lightingOrigin )
Sets the lighting origin. This does not work for prop_physics. Issue Tracker: 2804
Sets the texture to be used as the lightmap in upcoming rendering operations. This is required when rendering meshes using a material with a lightmapped shader such as LightmappedGeneric. This is a rendering function that requires a 3d rendering context. This means that it will only work in 3d Rendering Hooks. This is a rendering function that requires a 2d rendering context. This means that it will only work in 2d Rendering Hooks.
render.SetLocalModelLights( table lights = {} )
Sets up the local lighting for any upcoming render operation. Up to 4 local lights can be defined, with one of three different types (point, directional, spot). Disables all local lights if called with no arguments.
render.SetMaterial( IMaterial mat )
Sets the material to be used in any upcoming render operation using the render. Not to be confused with surface. SetMaterial.
render.SetModelLighting( number lightDirection, number red, number green, number blue )
Sets up the ambient lighting for any upcoming render operation. Ambient lighting can be seen as a cube enclosing the object to be drawn, each of its faces representing a directional light source that shines towards the object. Thus, there is a total of six different light sources that can be configured separately. Light color components are not restricted to a specific range (i. e. 0-255), instead, higher values will result in a brighter light.
render.SetRenderTarget( ITexture texture )
Sets the render target to the specified rt.
render.SetRenderTargetEx( number rtIndex, ITexture texture )
Sets the render target with the specified index to the specified rt.
render.SetScissorRect( number startX, number startY, number endX, number endY, boolean enable )
Sets a scissoring rect which limits the drawing area.
render.SetShadowColor( number red, number green, number blue )
Sets the shadow color.
render.SetShadowDirection( Vector shadowDirections )
Sets the shadow projection direction.
render.SetShadowDistance( number shadowDistance )
Sets the maximum shadow projection range.
render.SetShadowsDisabled( boolean newState )
Sets whether any future render operations will ignore shadow drawing.
render.SetStencilCompareFunction( number compareFunction )
Sets the compare function of the stencil. Pixels which fail the stencil comparison function are not written to the render target. The operation to be performed on the stencil buffer values for these pixels can be set using render. SetStencilFailOperation. Pixels which pass the stencil comparison function are written to the render target unless they fail the depth buffer test (where applicable). The operation to perform on the stencil buffer values for these pixels can be set using render. SetStencilPassOperation and render. SetStencilZFailOperation.
render.SetStencilEnable( boolean newState )
Sets whether stencil tests are carried out for each rendered pixel. Only pixels passing the stencil test are written to the render target.
render.SetStencilFailOperation( number failOperation )
Sets the operation to be performed on the stencil buffer values if the compare function was not successful. Note that this takes place before depth testing.
render.SetStencilPassOperation( number passOperation )
Sets the operation to be performed on the stencil buffer values if the compare function was successful.
render.SetStencilReferenceValue( number referenceValue )
Sets the reference value which will be used for all stencil operations. This is an unsigned integer.
render.SetStencilTestMask( number mask )
Sets the unsigned 8-bit test bitflag mask that will be bitwise ANDed with all values as they are read from the Stencil Buffer
render.SetStencilWriteMask( number mask )
Sets the unsigned 8-bit write bitflag mask that will be bitwise ANDed with any value that is written to the Stencil Buffer.
render.SetStencilZFailOperation( number zFailOperation )
Sets the operation to be performed on the stencil buffer values if the stencil test is passed but the depth buffer test fails.
render.SetViewPort( number x, number y, number w, number h )
Changes the view port position and size. The values will be clamped to the game's screen resolution. If you are looking to render something to a texture (render target), you should use render. PushRenderTarget. This function will override values of ScrW and ScrH with the ones you set.
Sets the internal parameter INT_RENDERPARM_WRITE_DEPTH_TO_DESTALPHA
render.Spin()
Swaps the frame buffers/cycles the frame. In other words, this updates the screen. If you take a really long time during a single frame render, it is a good idea to use this and let the user know that the game isn't stuck.
render.StartBeam( number segmentCount )
This is a rendering function that requires a 3d rendering context. This means that it will only work in 3d Rendering Hooks. Begin drawing a multi-segment Beam. For more detailed information, including usage examples, see the Beams Rendering Reference
Returns whether the player's hardware supports HDR. (High Dynamic Range) HDR can still be disabled by the mat_hdr_level console variable or just not be supported by the map.
Returns if the current settings and the system allow the usage of pixel shaders 1. 4.
Returns if the current settings and the system allow the usage of pixel shaders 2. 0.
Returns if the current settings and the system allow the usage of vertex shaders 2. 0.
render.SuppressEngineLighting( boolean suppressLighting )
Suppresses or enables any engine lighting for any upcoming render operation. This does not affect IMeshes. Issue Tracker: 4070
Enables HDR tone mapping which influences the brightness.
Updates the texture returned by render. GetFullScreenDepthTexture. Silently fails if render. SupportsPixelShaders_2_0 returns false.
Updates the power of two texture.
Pretty much alias of render. UpdatePowerOfTwoTexture but does not return the texture.
render.UpdateScreenEffectTexture( number textureIndex = 0 )
Copies the entire screen to the screen effect texture, which can be acquired via render. GetScreenEffectTexture. This function is mainly intended to be used in GM:RenderScreenspaceEffects
render.WorldMaterialOverride( IMaterial mat = nil )
This function overrides all map materials for one frame.