In the upcoming chapters we'll be creating interesting visuals by simulating real-world lighting making extensive use of colors. It's not hard to get creative with colors.īut enough about colors, let's start building a scene where we can experiment in. Glm::vec3 result = lightColor * to圜olor // = (0.33f, 0.21f, 0.06f) Īs you can see, we can get interesting colors from objects using different light colors. Let's try one more example with a dark olive-green light: As a result the coral object suddenly becomes a dark-greenish object. We can see that if we use a green light, only the green color components can be reflected and thus perceived no red and blue colors are perceived. The toy's color we perceive would then be a dark-greenish color. The toy also absorbs half of the light's green value, but also reflects half of the light's green value. Glm::vec3 result = lightColor * to圜olor // = (0.0f, 0.5f, 0.0f) Īs we can see, the toy has no red and blue light to absorb and/or reflect. Now what would happen if we used a green light? We can thus define an object's color as the amount of each color component it reflects from a light source. This is a representation of how colors would work in real life. We can see that the toy's color absorbs a large portion of the white light, but reflects several red, green and blue values based on its own color value. We get the resulting color vector by doing a component-wise multiplication between the light and object color vectors: Let's revisit our toy (this time with a coral value) and see how we would calculate its perceived color in graphics-land. If we would then multiply the light source's color with an object's color value, the resulting color would be the reflected color of the object (and thus its perceived color). In the previous paragraph we had a white color so we'll give the light source a white color as well. When we define a light source in OpenGL we want to give this light source a color. These rules of color reflection apply directly in graphics-land. Technically it's a bit more complicated, but we'll get to that in the PBR chapters. It only reflects those colors that represent the object's color and the combination of those is what we perceive (in this case a coral color). ![]() You can see that the white sunlight is a collection of all the visible colors and the object absorbs a large portion of those colors. ![]() The following image shows this for a coral colored toy where it reflects several colors with varying intensity: This reflected light enters our eye, making it look like the toy has a blue color. Since the toy does not absorb the blue color part, it is reflected. If we would shine this white light on a blue toy, it would absorb all the white color's sub-colors except the blue color. As an example, the light of the sun is perceived as a white light that is the combined sum of many different colors (as you can see in the image). The colors that aren't absorbed (rejected) by the object is the color we perceive of it. The color of an object we see in real life is not the color it actually has, but is the color reflected from the object. ![]() For example, to get a coral color, we define a color vector as: Using different combinations of just those 3 values, within a range of, we can represent almost any color there is. Colors are digitally represented using a red, green and blue component commonly abbreviated as RGB. In the digital world we need to map the (infinite) real colors to (limited) digital values and therefore not all real-world colors can be represented digitally. In the real world, colors can take any known color value with each object having its own color(s). Here we'll discuss what colors are and start building the scene for the upcoming Lighting chapters. We briefly used and manipulated colors in the previous chapters, but never defined them properly.
0 Comments
Leave a Reply. |