当前位置:网站首页>[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);
}
边栏推荐
- Lucky numbers in the [leetcode daily question] matrix
- 自主可控三维云CAD:CrownCAD赋能企业创新设计
- Browser storage scheme
- Jerry's watch stops ringing [article]
- West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials
- Rust language document Lite (Part 1) - cargo, output, basic syntax, data type, ownership, structure, enumeration and pattern matching
- C modifier
- js3day(数组操作,js冒泡排序,函数,调试窗口,作用域及作用域链,匿名函数,对象,Math对象)
- Linear DP acwing 896 Longest ascending subsequence II
- JS iterator generator asynchronous code processing promise+ generator - > await/async
猜你喜欢

The coloring method determines the bipartite graph acwing 860 Chromatic judgement bipartite graph

EasyDSS点播服务分享时间出错如何修改?

Finally, someone explained the supervised learning clearly

上海交大教授:何援军——包围盒(包容体/包围盒子)

Unity skframework framework (XIX), POI points of interest / information points

Unity SKFramework框架(十二)、Score 计分模块

Unity SKFramework框架(十六)、Package Manager 开发工具包管理器

Unity skframework framework (XVIII), roamcameracontroller roaming perspective camera control script

Day4 operator, self increasing, self decreasing, logical operator, bit operation, binary conversion decimal, ternary operator, package mechanism, document comment

Domestic free data warehouse ETL dispatching automation operation and maintenance expert taskctl
随机推荐
C modifier
numpy数组计算
JS generates 4-digit verification code
Record idea shortcut keys
研究表明“气味相投”更易成为朋友
Japan bet on national luck: Web3.0, anyway, is not the first time to fail!
ADB basic commands
操作教程:EasyDSS如何将MP4点播文件转化成RTSP视频流?
Independent and controllable 3D cloud CAD: crowncad enables innovative design of enterprises
Jerry's watch ringtone audition [article]
[opencv learning] [image filtering]
Js3day (array operation, JS bubble sort, function, debug window, scope and scope chain, anonymous function, object, Math object)
Unity SKFramework框架(十九)、POI 兴趣点/信息点
Unity SKFramework框架(十六)、Package Manager 开发工具包管理器
Domestic free data warehouse ETL dispatching automation operation and maintenance expert taskctl
运维必备——ELK日志分析系统
SAP MM 因物料有负库存导致MMPV开账期失败问题之对策
Unity skframework framework (XIV), extension extension function
国产免费数据仓库ETL调度自动化运维专家—TASKCTL
Unforgettable Ali, 4 skills, 5 hr additional written tests, it's really difficult and sad to walk