# Transparency

5 replies to this topic

### #1 PetzI

PetzI

GMC Member

• GMC Member
• 1026 posts
• Version:GM8.1

Posted 20 July 2012 - 06:26 PM

Hi, I'm curious as to how transparency works internally. Specifically, I'd like to know about the math. I've been trying to implement transparency in Game Maker by hand, but it's not working properly. It's really basic, for now I'm just trying to calculate the intersection color of two overlapping rectangles, while also having "real" rectangles for reference. I did find some formulas, but I wasn't sure about how to implement them, so I figured out my own and applied to each channel:

`R3 = (0.5*R + 0.5*R2)`

R and R2 are the red channels of the two rectangles. My formula seems to make sense, but I'm not certain that it's correct. I also don't know how to handle the rectangles' alpha channels. So I was hoping someone could explain how it works, or take a look at my example and see what I did wrong. Thanks!

https://dl.dropbox.com/u/17269641/transparency_b.gm81
• 0

### #2 ramses12

ramses12

6

• GMC Member
• 5769 posts
• Version:GM8.1

Posted 20 July 2012 - 06:29 PM

Result color = Src color * Src alpha + Dest color * ( 1 - Src alpha )
That's how blend modes work.
• 0

### #3 PetzI

PetzI

GMC Member

• GMC Member
• 1026 posts
• Version:GM8.1

Posted 20 July 2012 - 06:42 PM

That formula gets repeated 3 times, one for each RGB channel, right?
• 0

### #4 ramses12

ramses12

6

• GMC Member
• 5769 posts
• Version:GM8.1

Posted 20 July 2012 - 06:44 PM

Exactly. And source means "what is being drawn", while dest means "what is there already". Also, if you're not drawing on a surface, dest alpha will always be 1.
• 0

### #5 PetzI

PetzI

GMC Member

• GMC Member
• 1026 posts
• Version:GM8.1

Posted 20 July 2012 - 06:48 PM

Neat, it works now. Thanks!
• 0

### #6 ramses12

ramses12

6

• GMC Member
• 5769 posts
• Version:GM8.1

Posted 20 July 2012 - 06:51 PM

You're welcome!
• 0

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users