当前位置:网站首页>【OpenGL】笔记二十九、高级光照(镜面高光)
【OpenGL】笔记二十九、高级光照(镜面高光)
2022-07-02 09:54:00 【ycrsw】
1.流程
传统的冯氏光照模型中,镜面光照的算法能够取得比较好的效果:
但是该光照模型也有限制,可以看到,在下图镜面高光区域的边缘出现了一道很明显的断层。出现这个问题的原因是观察向量和反射向量间的夹角不能大于90度。如果点积的结果为负数,镜面光分量会变为0.0。
在进行漫反射光照计算时,光照方向与法向量夹角超过90°就代表着光照来自背面,这时不显示光照是正确的,但是镜面光的计算可一定不是这样,因为光照入射角和视角夹角大于90°能看到镜面高光可不是什么违背常理的事,哪怕视角离反射方向甚远,只要高光反射系数够小,那么它的反射分量也是不能够忽略的,就如上图那样,要解决这部分光照的缺陷,我们就要想另一种方式来进行近似:
那就是如上图所示,将视角向量和入射向量相加得到的半程向量与法向量进行点乘计算,这样夹角大于90°的光线才是真正看不到的,结果如下,可见镜面光照的边缘处的确平滑了许多:
下面是一个简单的着色器光照计算示例:
vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir)
{
vec3 lightDir = normalize(-light.direction);
// 漫反射着色
float diff = max(dot(normal, lightDir), 0.0);
// 镜面光着色
vec3 halfDir = normalize(lightDir + viewDir);
float spec = pow(max(dot(halfDir, normal), 0.0), material.shininess);
// 合并结果
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);
}
边栏推荐
- Structured data, semi-structured data and unstructured data
- Sensor adxl335bcpz-rl7 3-axis accelerometer complies with rohs/weee
- Std:: vector batch import fast de duplication method
- Linear DP acwing 899 Edit distance
- Js2day (also i++ and ++i, if statements, ternary operators, switch, while statements, for loop statements)
- JS generates 4-digit verification code
- Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures in detail! A little six
- Js1day (syntaxe d'entrée / sortie, type de données, conversion de type de données, Var et let différenciés)
- Explain in detail the process of realizing Chinese text classification by CNN
- moon
猜你喜欢
Interval DP acwing 282 Stone merging
[opencv learning] [image histogram and equalization]
JDBC prevent SQL injection problems and solutions [preparedstatement]
[opencv learning] [template matching]
[opencv learning] [image filtering]
Sensor adxl335bcpz-rl7 3-axis accelerometer complies with rohs/weee
JS iterator generator asynchronous code processing promise+ generator - > await/async
West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials
Floyd AcWing 854. Floyd finds the shortest path
TVOC, VOC, VOCs gas detection + Solution
随机推荐
Everyone wants to eat a broken buffet. It's almost cold
Unity skframework Framework (XVI), package manager Development Kit Manager
Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures in detail! A little six
Domestic free data warehouse ETL dispatching automation operation and maintenance expert taskctl
moon
Linear DP acwing 899 Edit distance
完全自主可控三维云CAD:CrownCAD便捷的命令搜索,快速定位所需命令具体位置。
(7) Web security | penetration testing | how does network security determine whether CND exists, and how to bypass CND to find the real IP
Ltc3307ahv meets EMI standard, step-down converter qca7005-al33 phy
Execute any method of any class through reflection
SAP MM 因物料有负库存导致MMPV开账期失败问题之对策
JS generates 4-digit verification code
js3day(数组操作,js冒泡排序,函数,调试窗口,作用域及作用域链,匿名函数,对象,Math对象)
Finally, someone explained the supervised learning clearly
上海交大教授:何援军——包围盒(包容体/包围盒子)
【云原生数据库】遇到慢SQL该怎么办(上)?
bellman-ford AcWing 853. Shortest path with side limit
js4day(DOM开始:获取DOM元素内容,修改元素样式,修改表单元素属性,setInterval定时器,轮播图案例)
互联网常见34个术语解释
Hash table acwing 841 String hash