Computing Normals
来源:互联网 发布:优化人力资源配置 编辑:程序博客网 时间:2024/06/05 05:34
Terrain Tutorial
Computing Normals
To apply lighting to a terrain, either using OpenGL lights, or simulating them, it is necessary to first compute normals. A normal is a vector that defines how a surface responds to lighting, i.e. how it is lit. The amount of light reflected by a surface is proportional to the angle between the lights direction and the normal. The smaller the angle the brighter the surface will look.Normals in OpenGL can be defined per face or per vertex. If defining a normal per face then the normal is commonly defined as a vector which is perpendicular to the surface. In order to find a perpendicular vector to a face, two vectors coplanar with the face are needed. Afterwards the cross product will provide the normal vector, i.e. a perpendicular vector to the face.So the first step is to compute two vectors coplanar to a face. Assuming the the faces are triangles defined by points t1,t2,t3, then two possible vectors are:
v = v1 x v2v = [vx,vy,vz] where,vx = v1y * v2z - v1z * v2yvy = v1z * v2x - v1x * v2zvz = v1x * v2y - v1y * v2x
Another necessary step to obtain proper lighting is to normalise the vector, i.e. make it unit length. OpenGL takes into consideration the length of the normal vector when computing lighting. Normalisation implies first computing the lenght of the vector, and then dividing each component by the vectors length.The length of a vector is computed as:
nv = [nvx,nvy,nvz] where,nvx = vx / lnvy = vy / lnvz = vz / l
The main problem with assigning a normal per face is that the terrain looks faceted, i.e. the brightness of each face is constant, and there is a clear difference between faces with differen orientations. In order to get a smoother look normals should be computed per vertex, and not per face. When computing normals per vertex it is necessary to take into account the faces that share the vertex. So for instance if using quads, each vertex (excluding the corner and border vertices), is shared by four polygons. The normal at a vertex should be computed as the normalised sum of all the unit length normals for each face the vertex shares. Consider the following image:
v = normalised(sum(v12, v23, v34, v41))wherevij = normalised(vi x vj) // normalised cross product
It is also posible to consider the eight neighbour vertices, instead of only four. This latter option will probably look smoother in the general case.
- Computing Normals
- Terrain Tutorial/Computing Normals
- Three ways of Computing Surface Normals
- The Mysterious Normals Property
- vertex normals 顶点向量
- BGL_polyhedron_3/normals.cpp analysis
- Ubiquitous Computing / Pervasive Computing
- 生成点法线(Generating Vertex Normals)
- MeshGeometry3D中的Normals和TextureCoordinates属性
- Granular Computing
- Autonomic Computing
- Grid Computing
- Cloud Computing
- Southbridge (computing)
- Northbridge (computing)
- Surface Computing
- Cloud computing
- Cloud computing
- 16-3 指针单步调试
- 分析HM代码,首先必须把class TComDataCU完全搞明白!
- 简单dp
- 信号的传递方式:连续系统和离散系统
- hdu 2159 FATE(二维费用完全背包)
- Computing Normals
- V4L2视频采集以及使用libjpeg 用yuv转JPEG
- AppWidget的使用
- 实现strcpy函数
- netty的源码学习(一)
- gson简单使用及下载地址
- CArray的原理(数据的动态处理)
- eclipse快捷键
- 密码学基础知识