当前位置:网站首页>[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);
}
边栏推荐
- js4day(DOM开始:获取DOM元素内容,修改元素样式,修改表单元素属性,setInterval定时器,轮播图案例)
- 国产免费数据仓库ETL调度自动化运维专家—TASKCTL
- Unity skframework framework (XVIII), roamcameracontroller roaming perspective camera control script
- Jerry's watch reads the alarm clock [chapter]
- net share
- 屠榜多目标跟踪!BoT-SORT:稳健的关联多行人跟踪
- JS generates 4-digit verification code
- [opencv learning] [moving object detection]
- Unity skframework framework (XVI), package manager development kit Manager
- Jerry's watch time synchronization [chapter]
猜你喜欢
挥发性有机物TVOC、VOC、VOCS气体检测+解决方案
js4day(DOM开始:获取DOM元素内容,修改元素样式,修改表单元素属性,setInterval定时器,轮播图案例)
自主可控三维云CAD:CrownCAD赋能企业创新设计
Modular commonjs es module
(7) Web security | penetration testing | how does network security determine whether CND exists, and how to bypass CND to find the real IP
VIM super practical guide collection of this one is enough
Linear DP acwing 899 Edit distance
Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures in detail! A little six
移动式布局(流式布局)
【OpenGL】笔记二十九、高级光照(镜面高光)
随机推荐
Js1day (syntaxe d'entrée / sortie, type de données, conversion de type de données, Var et let différenciés)
nohup命令
能自动更新的万能周报模板,有手就会用!
Async/await asynchronous function
Structured data, semi-structured data and unstructured data
Browser storage scheme
无向图的桥
[opencv learning] [image filtering]
Obtain file copyright information
Unity SKFramework框架(十六)、Package Manager 開發工具包管理器
Ali was killed by two programming problems at the beginning, pushed inward again, and finally landed (he has taken an electronic offer)
阿里初面被两道编程题给干掉,再次内推终上岸(已拿电子offer)
Jerry's watch ringtone audition [article]
net share
Redis数据库持久化
Jerry's watch time synchronization [chapter]
Linear DP acwing 896 Longest ascending subsequence II
机器学习基础(二)——训练集和测试集的划分
Package management tools
js1day(輸入輸出語法,數據類型,數據類型轉換,var和let區別)