RGB and transparency

Non-platform specific questions.

RGB and transparency

Postby zygoth » Mon Nov 09, 2009 6:17 pm

How do transparency and zDepth affect the actual rgb values shown on the screen? For example, if I had a 255,0,0, .5 pixel over a 0,255,0, .5 pixel, where .5 is the transparency, what is the actual value displayed? Is there any way to tell the value of a particular pixel on the screen? Thanks for any help.

Zygo
Nova: 100% Vertigo/Mazeman: 100%
Visit my website to download them both! http://www.ketonegames.com
User avatar
zygoth
 
Posts: 140
Joined: Mon Jun 11, 2007 6:37 pm
Score: 5 Give a positive score

Re: RGB and transparency

Postby skydereign » Mon Nov 09, 2009 9:01 pm

Well, not directly within gameEditor. It also depends on what the background color is, though if you just take that as the bottom layer it is fine. It is a linear relationship, since at full transparent, 255 becomes 0. And at no transparency, it is 255, when the background is black.

Here is a more universal way of finding it the rgb.
Code: Select all
r = lowerR-[(lowerR-upperR)*upperTransp]

Same goes for green and blue. The lower layer is the one with the smaller zdepth, and if you were to stack this effect, you would work from the bottom layer up, though you can compound this equation to do multiple layers at a time.

To address your example, I will assume the background is black.

[top layer] (255, 0, 0) at 0.5
[mid layer] (0, 255, 0) at 0.5
[bg layer] (0, 0, 0) at 1

Then the mid layer and background layer make
(0, 128, 0) at 1

Combine this new layer with the top layer and you get
(128, 64, 0) at 1
which is the resulting rgb of that pixel.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: RGB and transparency

Postby zygoth » Mon Nov 09, 2009 9:43 pm

great, thanks. Although I'm still not sure how I'm going to implement what I want. Is there a way to simply combine the two rgb values of overlapping canvasses without an inordinate number of for loop iterations?
Nova: 100% Vertigo/Mazeman: 100%
Visit my website to download them both! http://www.ketonegames.com
User avatar
zygoth
 
Posts: 140
Joined: Mon Jun 11, 2007 6:37 pm
Score: 5 Give a positive score

Re: RGB and transparency

Postby Hblade » Tue Nov 10, 2009 12:48 am

I'm going to be sharing a "Mega Functions" pack that i'll be working on soon. It it insane :D
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: RGB and transparency

Postby skydereign » Tue Nov 10, 2009 7:27 am

Oh, so this does have to do with canvas. There might be a way, but it depends on what you are doing with the canvas, and how detailed the canvas itself is... Also, why would you need to get the combined value of two overlapping canvases, is it for an image editor?
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: RGB and transparency

Postby zygoth » Tue Nov 10, 2009 10:27 pm

It's a game that involves overlapping light sources...and I wanted the colors to just combine directly. If only I could set values higher than 255... I just hope I can make the game run fast and not lag from all the calculation.
Nova: 100% Vertigo/Mazeman: 100%
Visit my website to download them both! http://www.ketonegames.com
User avatar
zygoth
 
Posts: 140
Joined: Mon Jun 11, 2007 6:37 pm
Score: 5 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron