Garry's Mod Wiki

Revision Difference

render_rendertargets#561269

<cat>Don'tListMePlease Dev</cat> <title>Render Reference - Render Targets</title> <note>This page is under active development and should not be read by anyone, let alone people other than the author</note> # Render Library References These pages seek to provide helpful insight into the groups of functions provided by the <page text="Render Library">render</page>. The major function groups are: * <page text="Beams">Beam_Rendering</page> * <page text="Minification and Magnification Texture Filters">render_min_mag_filters</page> * **Render Targets** # Render Targets **A Render Target is a special kind of image** that is created during gameplay via the game's code, rather than a pre-existing image that is loaded from the game's files. # What are Render Targets **A Render Target is a special kind of texture** that is created during gameplay via the game's code, rather than from a pre-existing image that is loaded from the game's files. **Render Targets have a fixed resolution, measured in pixels**, that is defined when they are first created. Unless your specific use-case has a reason not to, it's recommended to use the game's render resolution (Obtained via <page text="ScrW">Global.ScrW</page> and <page text="ScrH">Global.ScrH</page>.) ⤶ **Render Targets have 3 layers:**⤶ 1. The Color Channel (or simply "Color")⤶ * This is what will be seen when the Render Target is drawn onto the screen.⤶ 2. The Depth Buffer (or simply "Depth")⤶ * This layer keeps track of how far away from the camera each in the Render Target pixel is.⤶ 3. The Stencil Buffer (or simply "Stencils")⤶ * The Stencil layer controls whether or not each individual pixel in the Render Target is able to be drawn to.⤶ ⤶ # What are Practical Uses for Render Targets?⤶ While this is not a complete or exhaustive list, here are some examples of situations where a Render Target would be useful:⤶ * A rear-view mirror for a vehicle.⤶ * A security camera feed shown on a TV in a building's security room.⤶ * A painting canvas that players can draw on.⤶ ⤶ ⤶ ⤶ ⤶ ## Each Render Target is comprised of three layers: ## 1. The Color Channel The Color Channel (or simply "Color") is what is visible on the Render Target. This is what you would see if you drew the Render Target onto the screen. Generally speaking, each pixel in this layer contains 3 or 4 numbers representing the color (Red, green, and blue) and the alpha (or translucency/transparency.) The specific contents of each pixel in this layer will depend on the <page text="Image Format">Enums/IMAGE_FORMAT</page> used when the Render Target is created. By default each pixel of a Render Target's Color Channel contains 4 separate 8-bit whole, integer numbers containing values from 0-255 where each represents, in order, red, green, blue, and alpha. This is represented by the <page text="Image Format">Enums/IMAGE_FORMAT</page> enum `IMAGE_FORMAT_BGRA8888` ## 2. The Depth Buffer The Depth Buffer is an image the same ## 3. The Stencil Buffer ## How Render Targets are Used to Draw Frames Render Targets are used for anything that needs to be drawn dynamically, including the view you see while playing the game. Internally, the engine creates two two Render Targets (Called "Frame Buffers") when the game starts. At any given time, one of these two Render Targets is considered "in front" and the other is considered "in back". When your monitor asks for a frame to draw, the game sends it whatever is in the Front Render Target. Meanwhile, the game renders the next frame to the Back Render Target where it won't be seen by the player. When the next frame is finished, the two Render Targets are swapped (Called "Spinning") and the game starts sending the new Front Render Target to the monitor.