当前位置:网站首页>[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);
}
边栏推荐
- 阿里初面被两道编程题给干掉,再次内推终上岸(已拿电子offer)
- Web基础
- Fundamentals of face recognition (facenet)
- Counting class DP acwing 900 Integer partition
- Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?
- Unity skframework framework (XX), VFX lab special effects library
- 自主可控三维云CAD:CrownCAD赋能企业创新设计
- 上海交大教授:何援军——包围盒(包容体/包围盒子)
- Structured data, semi-structured data and unstructured data
- Linear DP acwing 896 Longest ascending subsequence II
猜你喜欢
![Jerry's watch gets the default ringtone selection list [article]](/img/94/e469864fa6ab688dabe46f606efdbc.jpg)
Jerry's watch gets the default ringtone selection list [article]

Linear DP acwing 898 Number triangle

Unity SKFramework框架(二十)、VFX Lab 特效库

Dijkstra AcWing 850. Dijkstra finding the shortest circuit II

Apply lnk306gn-tl converter, non isolated power supply

JS iterator generator asynchronous code processing promise+ generator - > await/async
![Lucky numbers in the [leetcode daily question] matrix](/img/c8/47a22644bf8cc1f49c5668d72161b6.jpg)
Lucky numbers in the [leetcode daily question] matrix

Redis数据库持久化

研究表明“气味相投”更易成为朋友

C modifier
随机推荐
Analog to digital converter (ADC) ade7913ariz is specially designed for three-phase energy metering applications
3 a VTT terminal regulator ncp51200mntxg data
无向图的桥
Modular commonjs es module
Mobile layout (flow layout)
诚邀青年创作者,一起在元宇宙里与投资人、创业者交流人生如何做选择……...
How can attribute mapping of entity classes be without it?
[error record] cannot open "XXX" because Apple cannot check whether it contains malware
net share
The redis development document released by Alibaba covers all redis operations
国产免费数据仓库ETL调度自动化运维专家—TASKCTL
Unity SKFramework框架(十七)、FreeCameraController 上帝视角/自由视角相机控制脚本
Lucky numbers in the [leetcode daily question] matrix
Finally, someone explained the supervised learning clearly
【蓝桥杯选拔赛真题43】Scratch航天飞行 少儿编程scratch蓝桥杯选拔赛真题讲解
[opencv learning] [image histogram and equalization]
To bypass obregistercallbacks, you need to drive the signature method
JS逆向之行行查data解密
Jerry's weather code table [chapter]
Jerry's watch gets the default ringtone selection list [article]