当前位置:网站首页>【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);
}
边栏推荐
- Jerry's watch stops ringing [article]
- C operator
- Unity SKFramework框架(二十)、VFX Lab 特效库
- 三翼鸟两周年:羽翼渐丰,腾飞指日可待
- Word efficiency guide - word's own template
- [opencv learning] [contour detection]
- Heap acwing 838 Heap sort
- Unity SKFramework框架(十四)、Extension 扩展函数
- [error record] cannot open "XXX" because Apple cannot check whether it contains malware
- How can attribute mapping of entity classes be without it?
猜你喜欢

Modular commonjs es module

阿里发布的Redis开发文档,涵盖了所有的redis操作

Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
![JDBC prevent SQL injection problems and solutions [preparedstatement]](/img/32/f71f5a31cdf710704267ff100b85d7.png)
JDBC prevent SQL injection problems and solutions [preparedstatement]

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

net share

Unity SKFramework框架(二十一)、Texture Filter 贴图资源筛选工具

TVOC, VOC, VOCs gas detection + Solution

How can attribute mapping of entity classes be without it?

Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures in detail! A little six
随机推荐
net share
【蓝桥杯选拔赛真题43】Scratch航天飞行 少儿编程scratch蓝桥杯选拔赛真题讲解
C operator
Browser node event loop
js4day(DOM开始:获取DOM元素内容,修改元素样式,修改表单元素属性,setInterval定时器,轮播图案例)
Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))
Rust language document Lite (Part 1) - cargo, output, basic syntax, data type, ownership, structure, enumeration and pattern matching
The coloring method determines the bipartite graph acwing 860 Chromatic judgement bipartite graph
Apply lnk306gn-tl converter, non isolated power supply
Unity skframework framework (XXI), texture filter map resource filtering tool
Uniapp develops wechat applet Tencent map function and generates sig signature of location cloud
ADB basic commands
[200 opencv routines] 100 Adaptive local noise reduction filter
spfa AcWing 851. SPFA finding the shortest path
Independent and controllable 3D cloud CAD: crowncad enables innovative design of enterprises
Linear DP acwing 896 Longest ascending subsequence II
8A Synchronous Step-Down regulator tps568230rjer_ Specification information
Word efficiency guide - word's own template
Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
Interval DP acwing 282 Stone merging