Garry's Mod Wiki

render.SetBlend

  render.SetBlend( number blending )

Description

Sets the alpha blending (or transparency) for upcoming render operations.

See render.SetColorModulation for the function to affect RGB color channels.

By itself, this will cause visible overlapping on parts of a model that are in front of other parts of the same model.
For a solution to this, see the examples below.

This does not affect non-model render.Draw* functions.

Issue Tracker: 3166
If a material has the $alphatest flag enabled then this function might not behave as expected because alpha will be binary, this has a default cutoff of 0.7.

Arguments

1 number blending
The alpha (transparency) for upcoming draw operations.
A value in the range (0-1) where 0 is fully transparent, 0.5 is 50% visible, and 1 is fully opaque.

Example: Basic Usage (With overlaps)

This example demonstrates the basic usage of render.SetBlend and the overlapping effect mentioned above.

-- Draw at a 75% opacity, so it's mostly opaque. render.SetBlend( 0.75 ) -- Draw the model using the blend we just set. self:DrawModel() -- Draw at a normal opacity again. render.SetBlend( 1 )
Output:

Example: Avoiding Overlap Issues

This example demonstrates how the overlapping effect can be avoided with the use of render.OverrideColorWriteEnable

-- Prevent drawing to the Color Channel of the currently active Render Target so -- that when we draw the model, it only sets the Depth Buffer values. render.OverrideColorWriteEnable( true, false ) -- Draw the model to set the Depth Buffer values self:DrawModel() -- Start drawing normally again render.OverrideColorWriteEnable( false, false ) -- Draw at a 75% opacity, so it's mostly opaque. render.SetBlend( 0.75 ) -- Draw the model using the blend we just set. -- Because we previously set the Depth Buffer values by drawing the model, and -- because pixels are only drawn when the pixel's current Depth Buffer value is -- less-than or equal-to the draw operation's new Depth value, only the parts of -- the model that are closest to the player's view will be drawn. -- This will prevent the overlapping that normally happens. self:DrawModel() -- Draw at a normal opacity again. render.SetBlend( 1 )
Output: