UnityShader learning (2) understanding of the addition and multiplication of pixel color and color vector

First of all, a principle of computer graphics is that if it looks right, it is right. Therefore, for some computational models, the most important thing is the effect of the final fit. It doesn't necessarily correspond to physics, but usually calculations are based on physical considerations.

An understanding of pixel color and related operations

We often say that an object is of a certain color, as if the color is an inherent property of the object. In fact, this understanding is not correct. Color is a feeling given to us when light reflected from an object enters our eyes. That is to say, in addition to the properties of the object itself, lighting conditions are also one of the determinants of the final color seen. When we say that a piece of paper is white, we are actually saying that the piece of paper reflects all visible light. If we illuminate it with monochromatic light, such as red light, we see that the paper appears red. Because the input light is only red, the paper can only reflect red light. Therefore, if the concept of color is discussed alone, it should be the own property of light (depending on the wavelength), not the property of the object. The so-called color of an object is actually the characteristic it shows in the process of reflection.

Due to the characteristics of the human eye's sensitivity, we use red, green and blue as the three components of the color space, and the mixture of red, green and blue light in different proportions can get the human eye's perception of other colors. At the same time, under the premise of the agreed range, the numerical value of the component can represent the intensity of the light. Based on this color model, if there are several different beams of light entering the eye, we can consider it equal to the light entering the eye after the three components are superimposed. In fact, this is also in line with the intuition: the more visible light illuminates an object, the brighter the object will appear.

So, the above discussion explains what it means to add color vectors. In many lighting models, the light reflected from a point consists of several parts: e.g. emissive, diffuse, specular, ambient. Then the color feeling that the reflected light finally gives us is the result of adding the color of each component. To sum up, the starting point for this simulation is:

1. Think that there are three basic colors of light. The color perception formed by the human eye comes from the mixture of different proportions and intensities of the three basic lights.

2. Lights of different colors do not interfere with each other, and they are superimposed linearly.

In fact, it is obvious that there are many places that do not match the physical reality. For example, the wavelength of light should be continuously valued. When some mixed light enters the eye, when calculating the contribution to the visual effect after they are superimposed, the wavelength is integrated. The contribution of light of different wavelengths is different, and there should be an empirical coefficient. Obviously, reducing to three wavelengths of monochromatic light and then adding linearly is a simple process.

When calculating the reflection part in the lighting model, there is a property called reflection color. For example, to calculate the diffuse reflection part, we will define the diffuse reflection color property of a material. When calculating the color of the reflected light, the component of the diffuse color attribute is multiplied by the corresponding component of the incident light to obtain the final result. How should this operation be understood?

First of all, we noticed that the reflection part is the link that reflects the material's own properties. Assuming that we are all illuminated with standard white light, the color of the light reflected by the material can be used as a representation of its own properties. When light is reflected by the material, the intensity must not increase, because part of the light will be absorbed by the material. For example, a material that appears red under white light absorbs light other than red. Therefore, the diffuse color of the material should not be understood as a concept equivalent to the color of light, it is actually the reflection percentage of each component. Therefore its components are specified in the range [0,1]. For example, we define a material with a diffuse color of (0.8,0,0) meaning that it reflects 80% of red light and absorbs all green and blue light.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324892523&siteId=291194637