Page 1 of 1

RGB and transparency

PostPosted: Mon Nov 09, 2009 6:17 pm
by zygoth
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

Re: RGB and transparency

PostPosted: Mon Nov 09, 2009 9:01 pm
by skydereign
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.

Re: RGB and transparency

PostPosted: Mon Nov 09, 2009 9:43 pm
by zygoth
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?

Re: RGB and transparency

PostPosted: Tue Nov 10, 2009 12:48 am
by Hblade
I'm going to be sharing a "Mega Functions" pack that i'll be working on soon. It it insane :D

Re: RGB and transparency

PostPosted: Tue Nov 10, 2009 7:27 am
by skydereign
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?

Re: RGB and transparency

PostPosted: Tue Nov 10, 2009 10:27 pm
by zygoth
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.