当前位置:网站首页>[OpenGL] notes 29. Advanced lighting (specular highlights)
[OpenGL] notes 29. Advanced lighting (specular highlights)
2022-07-02 13:13:00 【ycrsw】
1. technological process
In the traditional Feng's illumination model , The algorithm of specular illumination can achieve better results :

But the illumination model also has limitations , You can see , An obvious fault appears at the edge of the specular highlight area in the figure below . The reason for this problem is that the angle between the observation vector and the reflection vector cannot be greater than 90 degree . If the result of the dot product is negative , The specular component becomes 0.0.
When calculating diffuse illumination , The angle between the illumination direction and the normal vector exceeds 90° It means that the light comes from the back , It is correct not to show the light at this time , But the calculation of specular light must not be like this , Because the angle between the incident angle of light and the angle of view is greater than 90° It's not against common sense to see specular highlights , Even if the angle of view is far from the direction of reflection , As long as the specular reflection coefficient is small enough , Then its reflection component cannot be ignored , As shown above , To solve this part of the lighting defects , We need to think of another way to approximate :
That is, as shown in the above figure , The half range vector obtained by adding the angle vector and the incident vector and the normal vector are point multiplied , So the included angle is greater than 90° The light is really invisible , give the result as follows , The edges of the visible mirror light are indeed much smoother :
Here is a simple example of shader illumination calculation :
vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir)
{
vec3 lightDir = normalize(-light.direction);
// Diffuse shading
float diff = max(dot(normal, lightDir), 0.0);
// Specular shading
vec3 halfDir = normalize(lightDir + viewDir);
float spec = pow(max(dot(halfDir, normal), 0.0), material.shininess);
// Consolidated results
vec3 ambient = light.ambient * vec3(texture(material.diffuse, TexCoords));
vec3 diffuse = light.diffuse * diff * vec3(texture(material.diffuse, TexCoords));
vec3 specular = light.specular * spec * vec3(texture(material.specular, TexCoords));
return (ambient + diffuse + specular);
}
边栏推荐
- Japan bet on national luck: Web3.0, anyway, is not the first time to fail!
- [opencv learning] [common image convolution kernel]
- spfa AcWing 852. SPFA judgement negative ring
- Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures in detail! A little six
- Jerry's watch gets the default ringtone selection list [article]
- Oracle from entry to mastery (4th Edition)
- 三面阿里,有惊无险成功拿到offer定级P7,只能说是真的难
- Structured data, semi-structured data and unstructured data
- Analog to digital converter (ADC) ade7913ariz is specially designed for three-phase energy metering applications
- nohup命令
猜你喜欢

Linear DP acwing 899 Edit distance

Variable, "+" sign, data type

Japan bet on national luck: Web3.0, anyway, is not the first time to fail!

Unity SKFramework框架(十五)、Singleton 单例

二、帧模式 MPLS 操作

Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?

js1day(輸入輸出語法,數據類型,數據類型轉換,var和let區別)

Sensor adxl335bcpz-rl7 3-axis accelerometer complies with rohs/weee

Analog to digital converter (ADC) ade7913ariz is specially designed for three-phase energy metering applications

自主可控三维云CAD:CrownCAD赋能企业创新设计
随机推荐
【笔耕不辍勋章活动】生命不止,写作不息
linux下清理系统缓存并释放内存
Hundreds of web page special effects can be used. Don't you come and have a look?
OpenApi-Generator:简化RESTful API开发流程
Should I have a separate interface assembly- Should I have a separate assembly for interfaces?
阿里初面被两道编程题给干掉,再次内推终上岸(已拿电子offer)
Unity SKFramework框架(十八)、RoamCameraController 漫游视角相机控制脚本
Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
Analog to digital converter (ADC) ade7913ariz is specially designed for three-phase energy metering applications
SAP MM 因物料有负库存导致MMPV开账期失败问题之对策
三翼鸟两周年:羽翼渐丰,腾飞指日可待
JS逆向之行行查data解密
运维必备——ELK日志分析系统
OLED screen driver based on stm32
C operator
Ltc3307ahv meets EMI standard, step-down converter qca7005-al33 phy
Linear DP acwing 902 Shortest editing distance
nohup命令
国内首款、完全自主、基于云架构的三维CAD平台——CrownCAD(皇冠CAD)
Linear DP acwing 896 Longest ascending subsequence II