Team Spartan Cookies & Milk Forums
  • Issue Tracker
  • Donations
  • Search
  • Member List
  • Help

Register

Team Spartan Cookies & Milk Forums Garry's Mod Starfall v
1 2 3 4 5 … 18 Next »
Help required with overrideBlend
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threaded Mode
Help required with overrideBlend
29-11-2023, 09:24 PM,
#1
The17thDoctor Offline
TSCM Average Enjoyer
****
Posts: 1,100
Threads: 249
Joined: Oct 2015
Help required with overrideBlend
I must say render.overrideBlend gives me a real headache. Im having trouble seeing how this function behaves and neither the GMod Wiki nor the OpenGL docs are helping me.

What I want is to apply some color atop of a texture with varying alpha such as fully opaque parts of the texture will be e.g fully red and other parts just transparent red.

The17thDoctor: Server take me to the most handsome person
srcds_linux: I cant send people to themselves...
Website Find
Reply
01-12-2023, 04:50 PM,
#2
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: Help required with overrideBlend
Sounds like what you want is to use source colour, and destination alpha, so something like:
-- First draw your transparency mask.
drawYourTransparencyMaskHere()

-- Then set the blend mode overrides.
render.overrideBlend(
    true,
    -- Use 1 * source colour (i.e. all of the colour that's going to be drawn), and none of the existing colour, and add those together.
    render.BLEND_ONE, render.BLEND_ZERO, render.BLENDFUNC_ADD,
    -- Use none of the source alpha, and 1 * the destination alpha (i.e. take the alpha value that's already drawn), and add those together.
    render.BLEND_ZERO, render.BLEND_ONE, render.BLENDFUNC_ADD
)

-- Now draw your red colour over the top - this should end up colouring everything red with transparency.
render.setColor( 255, 0, 0 )
render.drawRect( 0, 0, 512, 512 )
This assumes you're rendering this to a render target, as setting colour/alpha values in screen space wouldn't apply the transparency part in a visible way.

Bear in mind also that rendering a transparent texture will itself blend with whatever it's rendering on top of, if you render a perfect alpha gradient on top of a black background you might get more colour than you originally expected.
Find
Reply
01-12-2023, 07:22 PM, (This post was last modified: 01-12-2023, 07:23 PM by The17thDoctor.)
#3
The17thDoctor Offline
TSCM Average Enjoyer
****
Posts: 1,100
Threads: 249
Joined: Oct 2015
RE: Help required with overrideBlend
Thanks for the explanation, I find the comments very useful to understand what's happening in reality.

My main confusion was that I thought that BLEND_ZERO and BLEND_ONE meant either fully black or fully white. This added to the fact that source and destinations were unclear to me made this whole ordeal take much more time than needed.

The17thDoctor: Server take me to the most handsome person
srcds_linux: I cant send people to themselves...
Website Find
Reply
« Next Oldest | Next Newest »


  • View a Printable Version
Forum Jump:


Users browsing this thread: 1 Guest(s)
Contact UsTeam Spartan Cookies & MilkReturn to TopLite (Archive) ModeMark all forums readRSS Syndication

Powered By MyBB, © 2002-2026 MyBB Group.