openGL系列文章目录

前言

我们在openGL中绘制球体,或者圆环体的时候,经常可以到法线、切线、副切线这几个词,一脸疑惑,特别是副切线,这时什么鬼?

一、法线(normal)

物体模型由成百上千个平坦的三角形围成.三角形上附加纹理的方式来增加额外细节. 提升真实感.
但是近看时,就有问题了.变成平面.缺乏细节.原因:
物体表面并非平坦的. 而是表示出无数(凹凸不平的)细节.如果以光的视角来看这个问题:是什么使表面被视为完全平坦的表面来照亮?
这时就需要法线

法线定义

三维平面的法线是垂直于该平面的三维向量。曲面在某点P处的法线为垂直于该点切平面的向量。

二、切线(tangent)

切线定义

几何上,切线指的是一条刚好触碰到曲线上某一点的直线。更准确地说,当切线经过曲线上的某点(即切点)时,切线的方向与曲线上该点的方向是相同的。平面几何中,将和圆只有一个公共交点的直线叫做圆的切线。

副切线(bitangent)

副切线(Bitangent)有时也被叫作副法线(Binormal),不管怎样,说的都是同一个东西。
副切线是同时垂直于由法线与切线的向量,所以可以由法线与切线的叉积计算得出。
但是这样的向量有两条,那到底哪一条才是真正的副切线呢?
经过计算后的副切线向量(蓝色的线)。

在着色器中的描述和计算

vec3 tangent;
vec3 binormal;vec3 c1 = cross(a_normal, vec3(0.0, 0.0, 1.0));
vec3 c2 = cross(a_normal, vec3(0.0, 1.0, 0.0));if (length(c1)>length(c2))
{tangent = c1;
}
else
{tangent = c2;
}tangent = normalize(tangent);binormal = cross(v_nglNormal, tangent);
binormal = normalize(binormal);

法线,切线,副切线函数实现

Vector3 Math::calculateTangentSpaceVector(const Vector3& position1, const Vector3& position2, const Vector3& position3,Real u1, Real v1, Real u2, Real v2, Real u3, Real v3){//side0 is the vector along one side of the triangle of vertices passed in,//and side1 is the vector along another side. Taking the cross product of these returns the normal.Vector3 side0 = position1 - position2;Vector3 side1 = position3 - position1;//Calculate face normalVector3 normal = side1.crossProduct(side0);normal.normalise();//Now we use a formula to calculate the tangent.Real deltaV0 = v1 - v2;Real deltaV1 = v3 - v1;Vector3 tangent = deltaV1 * side0 - deltaV0 * side1;tangent.normalise();//Calculate binormalReal deltaU0 = u1 - u2;Real deltaU1 = u3 - u1;Vector3 binormal = deltaU1 * side0 - deltaU0 * side1;binormal.normalise();//Now, we take the cross product of the tangents to get a vector which//should point in the same direction as our normal calculated above.//If it points in the opposite direction (the dot product between the normals is less than zero),//then we need to reverse the s and t tangents.//This is because the triangle has been mirrored when going from tangent space to object space.//reverse tangents if necessaryVector3 tangentCross = tangent.crossProduct(binormal);if (tangentCross.dotProduct(normal) < 0.0f){tangent = -tangent;binormal = -binormal;}return tangent;}

openGL中关于顶点的法线、切线、副切线相关推荐

  1. Win32 OpenGL编程 5 顶点数组详细介绍

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! Win3 ...

  2. Opengl中的TBN矩阵的计算和使用

    TBN矩阵 T:切线向量 B:副切线向量 N:法线向量 法线向量不用我们计算,我们的主要任务是根据三角形的坐标计算出T和B向量. 公式推导 如图,E2向量与纹理坐标的差ΔU2.ΔV2构成一个三角形.Δ ...

  3. Unity3D 法线转换与切线空间总结

    在Shader编程中经常会使用一些矩阵变换函数接口,其实它就是把固定流水线中的矩阵变换转移到了可编程流水线或者说GPU中,先看下面的函数语句: // Transform the normal from ...

  4. OpenGL中着色器,渲染管线,光栅化

    https://www.zhihu.com/question/29163054 光栅(shan一声)化(Rasterize/rasteriztion). 这个词儿Adobe官方翻译成栅格化或者像素化. ...

  5. OPenGL中的缓冲区对象

    引自:http://blog.csdn.net/mzyang272/article/details/7655464 在许多OpenGL操作中,我们都向OpenGL发送一大块数据,例如向它传递需要处理的 ...

  6. 新手向:如何理解OpenGL中着色器,渲染管线,光栅化等概念

    首先,光栅化(Rasterize/rasteriztion).  这个词儿Adobe官方翻译成栅格化或者像素化.没错,就是把矢量图形转化成像素点儿的过程.我们屏幕上显示的画面都是由像素组成,而三维物体 ...

  7. Learn OpenGL(七)——OpenGL中使用着色器的基本步骤及GLSL渲染简单示例

    OpenGL着色语言(OpenGL Shading Language,GLSL)是用来在OpenGL中着色编程的语言,是一种具有C/C++风格的高级过程语言,同样也以main函数开始,只不过执行过程是 ...

  8. 在OpenGL中实现Geometry Instancing

    声明:本文仅供个人学习交流使用,版权归原作者所有. 译者:tyxxy Emial:tyxxyhm@hotmail.com. 如需转载请注明出处:http://tyxxy.spaces.live.com ...

  9. 3ds模型在OpenGL中的读取和重绘

    关键字: OpenGL 3ds模型文件格式 读取与重绘  对OpenGL做了基本的介绍,并详细介绍了3ds模型的文件格式.在VC+十下的OpenGL编程中完成了3ds模型的读取与重绘.并例举了一个3d ...

最新文章

  1. 中文输入法切换ubuntu_切换到 Linux 工作,体验暴增 100 倍!
  2. oracle10g_vista_,Vista系统 安装Oracle10g 不成功?
  3. 短信验证码、图形验证码、邮件验证的自动化测试
  4. 使用log4net记录日志到MySQL中 (转)
  5. JSON(1)--- 语法
  6. 靠打麻将赢来800万!开家烂店天天跟顾客对着干,年赚569亿!
  7. 如何证明CPU缓存行cacheline的存在?
  8. eureka 服务注册与发现
  9. 【图像去噪】基于matlab最佳加权双边滤波图像去噪【含Matlab源码 459期】
  10. Java对接圆通电子面单下单接口
  11. js 查找html中的%3c%3e,Web前端攻防,一不小心就中招了
  12. hadoop2.x学习01
  13. Java POI合并多个word文件
  14. 路由之HSRP热备份
  15. 动手学深度学习番外篇 01.为什么from d2l import torch as d2l
  16. 单页面应用——SPA
  17. wifi 的几种加密方式
  18. Python实验数据处理
  19. 腾讯大王卡免流手机投屏电视看春晚
  20. 湖南科技大学研究生院计算机学院,湖南科技大学计算机科学与工程学院

热门文章

  1. 干货 | API开放提升效率和安全性攻略
  2. python编码用什么软件_彻底解决Python编码问题
  3. linux查看GCC版本
  4. Python自动化问卷填写-问卷星(含完整代码)
  5. 欢迎加入QQ群(63503492)讨论技术
  6. split()方法的使用及要点
  7. 2021电赛国一智能送药小车(F题)设计报告
  8. android atmel32u4 键盘,Mini 身材 Arduino 机器键盘设计(原理图、主要代码)
  9. 杭电————青年歌手大赛,评委会打分(C语言)
  10. 查询仅仅选修了指定的两门课程的学生学号