Skip to main content
GameDev.net gamedev.net
🔒 Locked

Color Theory: Is RGB realistic?

Started by Tubos Jan 11, 2010 at 6:51 AM 31 replies 10.6k views
Original Post
Tubos
Tubos
Hi, I'm drawing glowing particles with additive blending. Suppose you blend many red particles with R = 1, G = 0, B = 0 over each other: Note that the particles are _only_ red, no matter how bright the particles are. But when the particles are yellow (R = 1, G = 0.5, B = 0.1) the color becomes white. Of course it does, because we're doing additive blending. As I understand it, Red/Green/Blue is just an arbitrary construct that allows us to recreate most colors. With additive blending, some light colors (yellow) add up to white, but other colors (red) do not. That sounds wrong. Is that how light works in reality?
Antheus
Antheus
Yes. Think of red laser vs. incandescent light bulb (yellow glow, white light).

Lasers emit very narrow spectrum, so increasing intensity will not change the color. Other light sources might contain some dominant color, but entire spectrum will be represented. Increasing the intensity will eventually result in white-ish color.

Unfortunately, computer displays are not calibrated, so the scale will be off. Some things will appear brighter when they shouldn't. The screen also isn't capable of displaying high intensity variations.

HDR achieves better perceptual results by emulating how eye perceives the light and displays such effect on regular screen.
UltimaX
UltimaX
I may be wrong, but...

Additive Blending
FinalColor = (SourceColor * SourceBlend) + (DestinationColor * DestinationBlend)

On the red one you have no other colors components as they are 0. If you do additive blending on those they will stay zero. Because of that the components will never equal white (max RGB).

On your other one each component has a value that can accumulate. Add enough of them up and it will eventually turn white when all of the components max out.

Without doing actual tests it's hard to say, but I would try different ones. Try all green or all blue. Perhaps even try two components?
Ezbez
Ezbez
Is it that RGB isn't realistic or is it the maximum values we place on the colors that isn't realistic? Either way, our monitors have a limited ability to reproduce colors and brightness, so no model of colors will translate perfectly to images in all cases. Using a larger color spectrum for HDR is one attempt to circumvent this.
phresnel
phresnel
Quote:
Original post by Antheus
Yes.


Uhm, no.

For many applications, RGB is realistic enough, but it is not realitistic in the absolute sense.

In RGB color space, there is just one unique representation for every color (e.g. rgb(1,0,0)), but this nice quote tells how reality is more like:

Quote:
Manuel
Colored paint can also be different things: yellow paint could be paint that removes blue from the light, leaving light that is a sum of green to red (starting from white light), but yellow paint can also be paint that removes all colors but yellow, leaving only yellow.

Now consider monochromatic green light that falls on yellow paint of the second type: you will be left with no light whatsoever. But consider monochromatic green light that falls on yellow paint of the first type: the blue is removed but there was no blue and so the light stays as green as it was...


So for exampe, a perfect red is always rgb(1,0,0), but has infinitely many representations in reality (which is all but insignificant if you have to do with realistic image synthesis).

See also wikipedia; but anyways, RGB is in most cases good enough, and where it isn't, you can temporarily switch to other color spaces like yuv or sRGB, like for nicely blending rgb(1,0,0) to rgb(0,0,1) or so.
samoth
samoth
Quote:
Original post by Ezbez
Is it that RGB isn't realistic or is it the maximum values we place on the colors that isn't realistic?
The latter.

Although pedantically speaking RGB isn't 100% realistic either, it is perfectly realistic for you, assuming you are a normal, average person with normal eyesight. You don't see red, green, and blue, anyway. And yet, you probably never noticed or knew the difference.
What you really see is a mix of 3 colour mixes of mainly violet-blue, green-yellow, yellow-red and with less intensity cyan-green (from the retracted but nevertheless lit rod cells). I say "mainly", because the receptors have roughly bell-shaped sensitivity curves which are quite wide and overlap each other a fair bit. The brain turns that mess into whatever you think is green or red or any other colour.

What's wrong is clamping the color values to some fixed, arbitrary value (255 or 1.0 in this case). The value 255/1.0 represents "maximum" intensity, which doesn't exist in nature (not within reasonable bounds, anyway). A computer screen, however, does have a *quite* finite maximum intensity.

As Antheus said, HDR does address this problem by allowing values greater than 1.0 during composition and then scaling the whole image according to some function ("tone mapping") before showing the final image. This is still not realistic of course, but as good as you can get.
Pto
Pto
Quote:
Original post by Tubos
With additive blending, some light colors (yellow) add up to white, but other colors (red) do not.


Firstly - as everyone else said its a limited approximation, but it does the trick most of the time. However as for blending, in my head that seems right ... but I've been working with RGB and additive blending for so long I might be biased.

Its real easy to test thought, get 2+ torches, some red cellophane and some yellow cellophane and see what happens if you shine them at the same point. From school plays I'm sure that 2 red lights stay red, they don't add together to white. But I've never actually tried 2 yellow spotlights to see if they really do turn out white (with enough layers). I THINK it will, but like I said, I'm used to thinking that so might just be opengl overload :P
Emergent
Emergent
Light has a power spectrum.

Your eye has three kinds of cone cells, each with a different response spectrum.

The total power that a given kind of cone cell sees (which we assume is the quantity that matters) is given by the L2 dot product of the power spectrum of the light with that of the given kind of cone.

What this means is that, even though the power spectrum is infinite dimensional, it is only its projection onto a particular three-dimensional subspace that matters in terms of perception.

Each pixel of your monitor contains red, green, and blue light sources, each with its own power spectrum. These span a different three-dimensional subspace of the space of power spectra. Neglecting output intensity limits, the monitor can produce any spectrum in this subspace.

Now, so long as the subspace that the monitor can output is not orthogonal to the subspace the projection onto which matters for perception, then the monitor can produce every perceived color. Computationally, orthogonality can be tested by making sure that the Grammian matrix for the two sets of power spectra (cones and monitor light sources) has full rank.

What I have neglected here is output intensity limits. What results is that the colors which can be produced by the monitor are actually the points of a 3-cube 3-simplex (tetrahedron)[EDIT: Duh; the coefficients are individually in [0,1]; they don't need to add to 1], which is only a subset of an entire linear subspace.

But hopefully you see the point that, in principle, there's nothing limiting at all about reproducing colors by adding up red, green, and blue lights; so long as you can make the intensities large enough, this can produce any color.

[EDIT: I now appreciate that this cube cannot contain the entire set of visible colors; the fact that the coefficients cannot be negative matters more than I'd thought. For instance, as alvaro hints later in this thread, there is no way to stimulate just the green cones while using only positive coefficients on your sources.]

[Edited by - Emergent on January 12, 2010 7:37:30 AM]
Spa8nky
Spa8nky
Quote:
Original post by Tubos
I'm drawing glowing particles with additive blending.


Those glowing particles look great. What technique are you using to make them glow? Im intrigued, is just a bloom post processing technique or is there more to it than that. Are the particles just single pixels?

Thanks Tubos.
Fiddler
Fiddler
In nature, white is the synthesis of all waveforms. This means that monochromatic color cannot turn into white by increasing its intensity, if you ignore potentional sensory overload of the recipient.

In RGB space, monochromatic yellow is (approximately) represented by a mix of R + G. Additive blending will *not* turn such yellow into white. However, non-monochromatic shades of yellow (represented by the addition of a B component) *will* turn into white in the end.

One last thing to recall is that RGB space is just an approximation of the linear light spectrum in nature. It is not the only one, or even the most common one (printers use CMYK, for example, while traditional color theory uses RYB). Being an approximation, there are shades of color that it cannot reproduce 100% correctly: cyan (100% G + B) is a good example (compare a cyan printout with what you see on a calibrated monitor). Yellow is another example, albeit to a far lesser extent: there are few people, primarily women, who can distinguish between "real" yellow shades (as seen on celuloid) and shades produced by RGB monitors.
[OpenTK: C# OpenGL 4.4, OpenGL ES 3.0 and OpenAL 1.1. Now with Linux/KMS support!]
remigius
remigius

Aside from the insights above, I couldn't help but notice this:

Quote:
Original post by Tubos
red particles with R = 1, G = 0, B = 0 over each other:

the particles are yellow (R = 1, G = 0.5, B = 0.1)

As I understand it, Red/Green/Blue is just an arbitrary construct that allows us to recreate most colors. With additive blending, some light colors (yellow) add up to white, but other colors (red) do not.

That sounds wrong. Is that how light works in reality?


Here it might help to note that you quite arbitrarily include a non-zero B component in your RGB color for yellow. Pure yellow -if there is such a thing- would be (R = 1, G = 1, B = 0), which would not add up to form white light either but remain yellow instead. If you were to pick the red color as (R = 1, G = 0.1, B = 0.1), you'd end up with white light when doing additive blending on the red particles as well.

So although light itself is indeed a lot more complex and RGB is only a crude approximation, the observed difference here between red and yellow is not so much a limitation of RGB but rather a consequence of your choices in colors and the way additive blending is implemented.
phresnel
phresnel
Quote:
Original post by Emergent
But hopefully you see the point that, in principle, there's nothing limiting at all about reproducing colors by adding up red, green, and blue lights; so long as you can make the intensities large enough, this can produce any color.


This is all good, but don't forget that when letting colors interact (let it be the simples lerp), RGB is only an approximation, and will eventually yield wrong (yet possibly plausible) results.

This is really not an offense, but your post can give the impression that RGB is valid to be the one true color space as long as it's for computer screens. But then, your post only handles the O of the Input, Processing, Output (IPO)-model, for which RGB is indeed saturating and virtually the one true model, but for the P part, it is not.

Quote:
Original post by remigius

Aside from the insights above, I couldn't help but notice this:

Quote:
Original post by Tubos
red particles with R = 1, G = 0, B = 0 over each other:

the particles are yellow (R = 1, G = 0.5, B = 0.1)

As I understand it, Red/Green/Blue is just an arbitrary construct that allows us to recreate most colors. With additive blending, some light colors (yellow) add up to white, but other colors (red) do not.

That sounds wrong. Is that how light works in reality?


Here it might help to note that you quite arbitrarily include a non-zero B component in your RGB color for yellow.


I used that hack once. Alternatively, one can temporarily switch to another lightweight color space, e.g. yuv/srgb.

edit: Uh, I already said the latter in my first post :/
haegarr
haegarr
[Edit: During writing this comment on Emergents post, there came up a half dozen other posts; maybe this comment is already handled]

It is not true that all colors a human can see can be reproduced by combining just 3 primary colors. When looking at a chromaticity diagram you'll notice the well known shape where all colors of a particular wavelength from red to blue build up the curved border.

All colors inside (including the purple line) are not mono-chromatic. E.g. if you pick up a color inside and draw a straight line through that point, and the line hits with its ends the border curve, then you got 2 mono-chromatic colors (those at the hit points, of course) that can be mixed to get the source color. Instead of the mono-chromatic colors you can use any mixed colors to mix them further; the principle remains the same. As can be seen from this imagination, there is an infinite amount of possibilities to yield in a specific color inside the curve (but not on the curve!).

Now think of 2 fixed, already mixed colors (called "primaries") that are mixed together. You cannot decrease the amount of any of those primaries below 0, and you cannot increase its amount above total. That means you can yield in only those colors on the line between the 2 primaries, but you cannot go behind them. You are restricted to the formula
A * k + ( 1 - k ) * B with 0 <= k <= 1
Using 3 primaries instead of 2 changes the area of covered colors from a line to a triangle just due to the reasoning told above.

Now, even if the primaries of computer monitors were mono-chromatic (they are not in reality), it is not possible to construct a triangle that covers the "horseshoe" of chromaticity. Hence, it is not possible to reproduce all colors by mixing 3 primaries. Moreover, the primaries R, G, B of computer monitors are far from being close to mono-chromatic, especially the green primary. That means that the gamut of a monitor is a more-or-less small subset of human visible colors.
phresnel
phresnel
Quote:
Original post by szecs
Quote:
Original post by phresnel
Fake it. Though you have to hack around anyways in rasterisation, as those are effects of indirect illumination.
Thanks! I'll look into it.


Oh that link was just to show that even in a non-spectral ray tracer you have to somehow hack around to get dispersion effects.
alvaro
alvaro
Quote:
Original post by haegarr
Now, even if the primaries of computer monitors were mono-chromatic (they are not in reality), it is not possible to construct a triangle that covers the "horseshoe" of chromaticity. Hence, it is not possible to reproduce all colors by mixing 3 primaries. Moreover, the primaries R, G, B of computer monitors are far from being close to mono-chromatic, especially the green primary. That means that the gamut of a monitor is a more-or-less small subset of human visible colors.


I've seen a graph on Wikipedia that indicates what you are saying, but I don't really understand it. You and Wikipedia are both saying that there are colors that cannot be represented as a combination of red, blue and green, but I don't think I've ever seen them. Can you point out at an object whose color is not well captured by a TV camera, for instance?

I am mostly in Emergent's camp, except for the part where he says that it is enough to have linearly independent primary colors to be able to generate all the colors: He seems to forget that we cannot use negative coefficients in the linear combinations.
Sneftel
Sneftel
Quote:
Original post by alvaro
I've seen a graph on Wikipedia that indicates what you are saying, but I don't really understand it.
The reason that chart is confusing is that it's not shown in 3D.

Consider a light source varying in frequency, from near-infrared to red to orange ... to violet, to near-ultraviolet. Chart, in 3D, how much each of your three receptors is activated by the wavelengths. What you will end up with is a vaguely spiraling curve in 3D space, describing how receptor responses change as the frequency smoothly changes.

Now consider a second curve drawn in the same space, from the same light source but with slightly lower intensity (that is, we just turned down the brightness). Obviously this will look a lot like the previous curve, but scaled down slightly towards the origin.

Now imagine that we graph ALL possible intensities. What we will end up with looks like a cone that's open on one side: change the frequency and we go around the side of the cone, change the intensity and we move towards or away from the apex (the apex, of course, being black -- zero intensity, zero response).

If you want to get the chart from the wikipedia page, just slice through your cone thing in the XY plane at some reasonable Z value.

Quote:
You and Wikipedia are both saying that there are colors that cannot be represented as a combination of red, blue and green, but I don't think I've ever seen them. Can you point out at an object whose color is not well captured by a TV camera, for instance?
Next time you have cause to go outside in the springtime, bring your laptop. Pick a few leaves from different plants, and try to replicate that color on your screen. What you will notice is that (a) there are a LOT of different kinds of green, and (b) very few of them are representable on your screen.
alvaro
alvaro
Quote:
Original post by Sneftel
Quote:
Original post by alvaro
You and Wikipedia are both saying that there are colors that cannot be represented as a combination of red, blue and green, but I don't think I've ever seen them. Can you point out at an object whose color is not well captured by a TV camera, for instance?
Next time you have cause to go outside in the springtime, bring your laptop. Pick a few leaves from different plants, and try to replicate that color on your screen. What you will notice is that (a) there are a LOT of different kinds of green, and (b) very few of them are representable on your screen.



Looking at the curves that describe the mapping from wavelength to excitement of the red, green and blue receptors, it's pretty clear that one green won't do the job. I guess I now understand what the problem is. I live in a very green area, so I will make sure to try your experiment.

In any case, this limitation has never been a huge impediment to the success of the movie and TV industries, so I am sure it won't be a practical problem for games either.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.