The following article gives me a new understanding of the light in OpenGL.
The generation of model colors in an OpenGL scene is roughly described by the following flow chart:
(1) When the lighting is not turned on, the vertex color is used to generate the color of the entire surface.
The glShadeModel can be used to set the color of the interior pixel of the surface. GL_FLAT/GL_SMOOTH.
(2) In general, after lighting is turned on, at least one light source is required in the scene (GL_LIGHT0...GL_LIGHT7)
The specified light source is turned on and off with glEnable(GL_LIGHT0) glDisable(GL_LIGHT0).
--- Global Ambient Light ---
GLfloat gAmbient[] = {0.6, 0,6, 0,6, 1.0};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, gAmbient);
(3) Set the light component of the light source--ambient light/diffuse light/mirror light
By default, GL_LIGHT0. The GL_AMBIENT value of .GL_LIGHT7 is (0.0, 0.0, 0.0, 1.0);
The GL_DIFFUSE and GL_SPECULAR values ​​of GL_LIGHT0 are (1.0, 1.0, 1.0, 1.0).
GL_LIGHT1.. The GL_DIFFUSE and GL_SPECULAR values ​​for .GL_LIGHT7 are (0.0, 0.0, 0.0, 0.0).
GLfloat lightAmbient[] = {1.0, 1.0, 1.0, 1.0};
GLfloat lightDiffuse[] = {1.0, 1.0, 1.0, 1.0};
GLfloat lightSpecular[] = {0.5, 0.5, 0.5, 1.0};
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular);
(4) Set the position and direction of the light source
-- Parallel light - no position only direction
GLfloat lightPosiTIon[] = {8.5, 5.0, -2.0, 0.0}; // w=0.0
glLightfv(GL_LIGHT0, GL_POSITION, lightPosiTIon);
-- Point Lights -- There are no directions
GLfloat lightPosiTIon[] = {8.5, 5.0, -2.0, 1.0}; // w is not 0
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
-- Spotlights -- There are directions
GLfloat lightPosition[] = {-6.0, 1.0, 3.0, 1.0}; // w is not 0
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
GLfloat lightDirection[] = {1.0, 1.0, 0.0};
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, lightDirection); // spotlight spindle direction spot direction
glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 45.0); // cutoff angle spot cutoff
** Parallel light does not attenuate as distance d increases, but point light sources and spotlights decay.
The attenuation is the decay coefficient. The larger the coefficient, the faster the decay.
By default, c=1.0, l=0.0, q=0.0
glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 2.0); // c coefficient
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 1.0); // l coefficient
glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.5); // q coefficient
++
(5) Set the material properties
Ambient light and scattered light are not affected by the position of the viewpoint. What color the object looks like is largely affected by scattered light, and ambient light reflection also has a certain influence on the color of the object.
Because when the light is directed at the object, the scattered light is the strongest; when it is not in direct sunlight, the effect of the ambient light is obvious. For objects in the real world, the scattered light is usually the same color as the ambient light.
The specular reflection of the object creates a highlight on the surface of the object. The specular reflection seen by the observer depends on the position of the viewpoint - the highest brightness along the direction of the reflected light.
By default, the material's GL_AMBIENT value is (0.2, 0.2, 0.2, 1.0); the GL_DIFFUSE value is (0.8, 0.8, 0.8, 1.0);
GL_SPECULAR value is (0.0, 0.0, 0.0, 1.0); GL_SHININESS value is 0.0 [value range is [0.0, 128.0], the larger the value, the smaller the highlight area, the higher the brightness];
GL_GL_EMISSION value is (0.0, 0.0, 0.0, 1.0)
GLfloat matAmbient[] = {0.6, 0.6, 0.6, 1.0};
GLfloat matDiffuse[] = {0.35, 0.35, 0.35, 1.0};
GLfloat matAmbDif[] = {0.5, 0.5, 0.5, 1.0};
GLfloat matSpecular[] = {0.2, 0.2, 0.2, 1.0};
GLfloat shine[] = {5.0};
GLfloat matEmission[] = {0.3, 0.1, 0.1, 1.0};
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, matAmbient);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, matDiffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, matAmbDif); // Set the background color and the scattering color to the same color
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, matSpecular);
glMaterialfv(GL_FRONT, GL_SHININESS, shine);
glMaterialfv(GL_FRONT, GL_EMISSION, matEmission); // Used to simulate the glow of an object, but this is not a light source
(6) Color material mode
Using a color material can quickly change the color of the model in the scene at a small cost. Its specific usage is as follows:
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_DIFFUSE);
glColor3f(0.2, 0.5, 0.8);
/*** Draw some objects ***/
glColorMaterial(GL_FRONT, GL_SPECULAR);
glColor3f(0.9, 0.1, 0.3);
/*** draw some other objects***/
glDisable(GL_COLOR_MATERIAL);
We provide wire harness manufacturing services for cable harnesses and built-to-print cables used in many industries, such as computer, game machine, POS machine, ATM , audio/video, electro-mechanical, data communications, telecommunications, medical, etc.
Related Products:speaker cable,customized cable assemblies,electrical cable assemblies.
We have developed a tradition of high-tech engineering, prototyping, and quality custom cable manufacturing at very competitive pricing. Also with professional flow chart (wire cutting-stripping-copper twisting-crimping-crimping 100% inspection-soldering-molding-asssembling-testing-FQC100% -OQC1-OQC2) , which can help us support customers with stable quality.
Custom Wire Harness Assembly
- Electrified dimensional build boards with 100% continuity test
- Capabilities to test for fuse,diode,resistor, and relay presence
- Mating test fixtures for lower production wire harnesses
- Ability to free hand build harnesses for prototypes and design validation
- Separate layout boards for addition of fir tree clips, rosebuds, clamps,and labels after coverings added
- Capabilities to add board interlocks and test markings to harness as needed
Speaker Cable,Straight Bnc Cable Assembly,Idc Red Custom Cable Assembly,Customized Cable Assemblies,EV Cable Assemblies,Cable Assembly,Custom Cable,Customized Cable Assemblies
ETOP WIREHARNESS LIMITED , https://www.wireharnessetop.com