Garry's Mod Wiki

Revision Difference

render.OverrideBlendFunc#513062

<function name="OverrideBlendFunc" parent="render" type="libraryfunc">⤶ <description>⤶ <deprecated>Use <page>render.OverrideBlend</page> instead.</deprecated>⤶ ⤶ Overrides the internal graphical functions used to determine the final color and alpha of a rendered texture.⤶ ⤶ See also <page>render.OverrideAlphaWriteEnable</page>.⤶ ⤶ <note>Doing <page>surface</page> draw calls with alpha set to 0 is a no-op and will never have any effect.</note>⤶ </description>⤶ <realm>Client</realm>⤶ <args>⤶ <arg name="enabled" type="boolean">true to enable, false to disable. No other arguments are required when disabling.</arg>⤶ <arg name="srcBlend" type="number">The source color blend function &lt;page&gt;BLEND&lt;/page&gt;. Determines how a rendered texture&#x27;s final color should be calculated.</arg>⤶ <arg name="destBlend" type="number"></arg>⤶ <arg name="srcBlendAlpha" type="number" default="nil">The source alpha blend function &lt;page&gt;BLEND&lt;/page&gt;. Determines how a rendered texture&#x27;s final alpha should be calculated.</arg>⤶ <arg name="destBlendAlpha" type="number" default="nil"></arg>⤶ </args>⤶ </function>⤶ ⤶ <example>⤶ <description>⤶ In this example we draw a lightning bolt over our player's head.⤶ ⤶ We shouldn't really draw the lightning in the PreDrawTranslucentRenderables hook as this causes issues rendering transparent objects behind the lightning, but it's a quick example of how the function works. Normally it should be drawn in a custom lua effect's <page>EFFECT:Render</page>.⤶ </description>⤶ <code>⤶ -- Our sprite texture to render. Rendering this texture without⤶ -- render.OverrideBlendFunc will result in black borders around the lightning beam.⤶ local lightningMaterial = Material("sprites/lgtning")⤶ ⤶ function GM:PreDrawTranslucentRenderables(isDrawingDepth, isDrawingSkybox)⤶ ⤶ if isDrawingDepth or isDrawSkybox then return end⤶ ⤶ local ply = Entity(1)⤶ ⤶ if !IsValid(ply) then return end⤶ ⤶ -- Calculate a random UV to use for the lightning to give it some movement⤶ local uv = math.Rand(0, 1)⤶ ⤶ -- Enable blend override to interpret the color and alpha from the texture.⤶ render.OverrideBlendFunc( true, BLEND_SRC_COLOR, BLEND_SRC_ALPHA, BLEND_ONE, BLEND_ZERO)⤶ ⤶ render.SetMaterial(lightningMaterial)⤶ ⤶ -- Render a lightning beam along points randomly offset from a line above the player.⤶ render.StartBeam(5)⤶ render.AddBeam(ply:GetPos() + Vector(0,0,035), 20, uv, Color(255,255,255,255))⤶ render.AddBeam(ply:GetPos() + Vector(0,0,135) + Vector(math.Rand(-20,20),math.Rand(-20,20),0), 20, uv*2, Color(255,255,255,255))⤶ render.AddBeam(ply:GetPos() + Vector(0,0,235) + Vector(math.Rand(-20,20),math.Rand(-20,20),0), 20, uv*3, Color(255,255,255,255))⤶ render.AddBeam(ply:GetPos() + Vector(0,0,335) + Vector(math.Rand(-20,20),math.Rand(-20,20),0), 20, uv*4, Color(255,255,255,255))⤶ render.AddBeam(ply:GetPos() + Vector(0,0,435) + Vector(math.Rand(-20,20),math.Rand(-20,20),0), 20, uv*5, Color(255,255,255,255))⤶ render.EndBeam()⤶ ⤶ -- Disable blend override⤶ render.OverrideBlendFunc( false )⤶ ⤶ end⤶ </code>⤶ <output></output>⤶ ⤶ </example>