Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-02-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report