惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
Stack Overflow Blog
Stack Overflow Blog
L
LINUX DO - 最新话题
Google Online Security Blog
Google Online Security Blog
Schneier on Security
Schneier on Security
Spread Privacy
Spread Privacy
www.infosecurity-magazine.com
www.infosecurity-magazine.com
雷峰网
雷峰网
Google DeepMind News
Google DeepMind News
Microsoft Azure Blog
Microsoft Azure Blog
IT之家
IT之家
V
Vulnerabilities – Threatpost
K
Kaspersky official blog
S
Schneier on Security
B
Blog
The Register - Security
The Register - Security
SecWiki News
SecWiki News
Hacker News: Ask HN
Hacker News: Ask HN
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security Affairs
T
The Blog of Author Tim Ferriss
G
Google Developers Blog
T
Tenable Blog
P
Proofpoint News Feed
Apple Machine Learning Research
Apple Machine Learning Research
D
DataBreaches.Net
S
Secure Thoughts
Security Latest
Security Latest
H
Heimdal Security Blog
The Hacker News
The Hacker News
O
OpenAI News
AWS News Blog
AWS News Blog
量子位
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
腾讯CDC
U
Unit 42
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
L
LangChain Blog
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Hugging Face - Blog
Hugging Face - Blog
The Last Watchdog
The Last Watchdog
Recorded Future
Recorded Future
V2EX - 技术
V2EX - 技术
爱范儿
爱范儿
F
Full Disclosure

博客园 - 夏天/isummer

vcpkg的安装,配置vs2022, 全局使用,清单使用 wsGLCanvas中的OnPaint和OnSize的调用顺序 Visual Studio 2022中配置Eigen.Natvis文件,实现Debug查看:Eigen库查看矩阵与向量的值 python 用control库绘制自动控制原理中的根轨迹: C++ 无法从“const char [ ]”转换为“char *” 根据文件内存字节数,返回文件占用内存大小:单位:T,G,M,K,B 泛洪算法(Flood fill Algorithm):符号洪水填充算法 opengl中的glDrawElements 用法和glDrawArray opengl中的VBO,IBO,VAO,EBO总结: OpenGL着色器Shader小结 VS2022 在编译大型项目出现:c/c++ intellance 操作-优化VS2022,提高Intellance速度 用VS2022创建空桌面程序【Empty】运行wxWidgets应用,报错:MSVCRTD.lib(exe_main.obj) : error LNK2019: 无法解析的外部符号 main VS下使用全局配置的方式使用VCPKG vcpkg 安装过程中install的参数: ApriTags应用 【/MT、/MTd、/MD、/MDd】C++ 出现异常“.... \debug_heap.cpp Line:980 Expression:__acrt_first_block==header"【已解决】 - 夏天/isummer QString的tostdstring问题-提示堆栈内存溢出(2024.12) vsftpd和FileZiler配置:本地登录,支持上传-下载-删除文件和目录-添加文件和目录 PyQt开发-mkvirtualenv虚拟环境 线程池ThreadPool, C++ github 命令git下载失败: Failed to connect to github.com port 443 解决方案,解决CMAKE中下载其他库失败的问题
“模型法线到视图法线”的变换矩阵(normal matrix)的计算和作用
夏天/isummer · 2025-11-06 · via 博客园 - 夏天/isummer

“模型法线到视图法线”的变换矩阵(normal matrix)
作用:用于在 光照计算(lighting) 中,将 模型空间中的法线方向 正确地转换到 视图空间(或摄像机空间),以便与光照方向、视点方向等在同一坐标系下进行正确的光照计算

 实际使用:三角面片的法向量n,用NormalMatrix矩阵左乘n,则得到的是在:视图空间(摄像机坐标系)中的法向量表示。

1.  为什么要转换法线方向?

  在3D渲染中,每个顶点(或片元)都会进行光照计算,例如:

diffuse = max(dot(N, L), 0.0)
specular = pow(max(dot(R, V), 0.0), shininess)

其中:

  • N = 法线向量,(例如:三角面片的发现向量)

  • L = 光源方向

  • V = 视线方向

  • 这些向量必须在 同一个坐标系中计算(通常是视图空间)。

2 问题:模型空间中的法线不能直接用

模型经过各种变换(旋转、平移、缩放、剪切)后:

  • 模型的顶点位置会改变。

  • 法线方向也会被扭曲,尤其是当模型有 非均匀缩放

例如:如果模型在X方向缩放2倍,法线也会被“压扁”,导致光照变暗或错误。

  所以法线(模型三角面片的法线)需要用专门的矩阵变换来保持正确的方向。

3. 解决方法:使用 NormalMatrix(法向量矩阵:作用专门用于三角面片法向量的变换)

  法线矩阵的计算,需要看转化后的“操作空间”。

  (1)如果目标是世界坐标系:就是希望得到在世界坐标系下的三角面片的法向量。

  NormalMatrix=模型变换矩阵M的逆矩阵的转置。

  (2)如果目标是在视图坐标系(相机坐标系下):希望得到在视图坐标系下的三角面片的法向量。

  NormalMatrix=视图变换V * 模型变换矩阵M的逆矩阵的转置。

如下:

image

 Nword:表示的意思。如果模型到世界坐标系存在:模型矩阵,则模型坐标系中的法向量,转化为世界坐标系中的法向量表示,就是用: 

代码实现:

view_normal_matrix = view3x3 * model3x3.inverse().transpose();

4. 用途总结(重点)

image

 在着色器中使用:

// uniform matrices
uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
uniform mat3 normalMatrix; // (viewMatrix * modelMatrix⁻¹)ᵀ 的前3x3部分

in vec3 normal_model;//模型坐标系中的法向量
out vec3 normal_view;

void main() {
    normal_view = normalize(normalMatrix * normal_model);//计算后,得到视图空间(相机空间)的对应的法向量表示
}

endl;