Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Teaching Handbook for Topology Graphics Engineers (Lecture 7) | OpenGL Learning course typed out word by word

Shulou Source: shulou.com Published: 2022-06-03 08:08:06 09月28日 Update

This article continues the previous section.

5.3 OpenGL built-in Illumination Model

There are three types of OpenGL lighting: Ambient (ambient light), Diffuse (diffuse light) and Specular (specular light).

Ambient does not depend on the direction of the light source. The light spreads evenly on the surface of the object in all directions, and all the objects in the scene will flood the light, which in turn will shine on other objects and continue to be flooded until the photon energy is exhausted, so that such floodlight is scattered throughout the scene. Ambient light can be represented by setting a color constant. Ambient = a constant.

Diffuse depends only on the direction of the light source and the direction of the normal. Therefore, it is only related to the angle between the surface and the incident light. We can see an object because it reflects the incident light in all directions (so it's called diffuse reflection). The diffuse material property of an object plays a decisive role in the color of the object. Diffuse = I*cos, theta is the angle of incidence, that is, the angle between the direction of light and the normal.

Specular depends on the direction of the light source, the direction of the normal and the direction of the viewing angle. It is not only related to the angle between the surface and the incident light, but also related to the viewing angle, and according to the smoothness of the surface, it presents different brightness, the smoother it is, the easier it is to produce highlight area. In OpenGL, the intensity of specular light can be adjusted by smoothness (shininess).

Specular = I*coss φ, where the exponent s is the smoothness. 1max s is the Roughness.

Take a look at the effect picture:

Let's introduce three different light sources.

Directional Light directional light (directional light), which can change the angle. You can think of the sun.

Point Light point light source (emitting light from a point around), you can change the position. You can think of a light bulb.

Spot Light spotlight (spot / cone). It is more resource-consuming and can change the position and angle. You can think of a flashlight.

Take another look at the different effects caused by different light source positions:

On the left is the point light source in the human eye position, and on the right is the point light source at the coordinate origin.

5.4 use OpenGL lighting

Teach you a simple code that uses lighting:

Then set the global illumination information:

One advantage of this is that you can easily control the intensity of light, such as 0.3f here.

Set the material:

Set the lighting properties:

You can integrate this code into the following code and put it into the method body:

Specific how to use, you also need to see Github our source code and then the actual combat. In order to really understand the use of light.

Tags: Light source direction object light light different smooth position that is surface angle reflection code angle normal correlation smoothness scene intensity effect Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Microsoft Shulou Technology Shulou Tech Info MariaDB