在bump mapping中使用normalize cube map的原因

本文讨论了在Bump映射中如何处理光照方向的规范化问题,特别是在片段程序中使用单位长度光照方向的情况。文章介绍了通过顶点程序计算单位长度光照方向的方法及其存在的问题,并提出了使用规范化立方体贴图作为一种替代方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The bump mapping relies on modulation by a dot product of 
a unit-length light direction and a unit-length surface normal. 
So you want your fragment program to use unit-length light 
directions. 

The light directions are either data specified per vertex or 
generated per vertex. The typical example is having a 
point light. The vertex program computes P - V as the light 
direction, where P is the light position and V is the vertex 
position. You can normalize to U = (P-V)/Length(P-V) in the 
vertex program, but this costs you some GPU cycles. Moreover, 
the rasterizer will interpolate these per-vertex unit-length 
vectors, generating per-pixel directions that are usually not 
unit length. 

When the fragment program gets one of these light directions, 
you can normalize it (assuming a powerful enough shader model) 
using an inverse-sqrt operation. This is a per-pixel cost, which 
is expensive. The normalization cube map is a cheap alternative 
that instead uses a texture lookup to produce a unit-length light 
direction. [If you have bilinear filtering enabled for the cube map, 
there is an interpolation in the lookup, producing a non-unit-length 
vector, but for a sufficiently large resolution cube map, this is 
not really noticeable. With nearest filtering, you will get a 
unit-length result.] 

When using normalization cube maps, there is no need to do the 
normalization of P-V in the vertex program. So overall, you avoid 
the inverse-sqrt operations in both the vertex and fragment 

programs. 



http://www.groupsrv.com/computers/about300243.html

### Bump Mapping 基本概念 Bump Mapping 是一种用于模拟表面细节的技术,通过改变光照计算来创建视觉上的高度差异效果。这种方法并不会真正移动物体表面的几何位置,而是利用纹理影响法线方向,在不增加额外几何复杂度的情况下提供更丰富的材质表现[^3]。 ### 实现过程 为了在 GAMES101 的框架内实现 bump mapping 功能,主要涉及以下几个方面: #### 法线贴图生成 通常情况下,bump map 或者称为 normal map 是预先制作好的图像文件。这些图片存储了相对于切空间(tangent space)下的法向量信息。每个像素的颜色代表了一个特定的方向矢量,其中红色通道对应X轴分量,绿色通道对应Y轴分量,蓝色通道则表示Z轴分量[^4]。 #### 修改着色器代码 对于 fragment shader 来说,需要读取来自 texture sampler 的法线数据,并将其转换成世界坐标系中的实际法线值。这涉及到将 tangent, bitangent 和 normal 组合成矩阵,再乘以从切空间到视图空间或世界空间的变化矩阵[^2]。 ```glsl // GLSL Fragment Shader Code Snippet vec3 tangentSpaceNormal = texture(normalMap, TexCoords).rgb; tangentSpaceNormal = normalize(tangentSpaceNormal * 2.0 - 1.0); mat3 TBN = transpose(mat3(TBNMatrix)); normal = normalize(TBN * tangentSpaceNormal); ``` 上述片段展示了如何获取并处理法线贴图中的 RGB 数据,以及怎样构建TBN变换矩阵来进行正确的法线转换。 #### 更新光照计算 一旦得到了新的法线向量之后,就可以按照标准的 Phong/Blinn-Phong 模型或者其他任何所选的光照算法重新评估该fragment处的光照强度。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值