NeHe OpenGL Lesson22 – Bump-Mapping, Multi-Texturing & Extensions

本文详细介绍如何使用OpenGL实现凹凸映射效果,通过近似漫反射光照来增强3D模型表面细节。文章探讨了凹凸映射的概念,介绍了如何通过纹理映射和技巧来模拟光照,特别提到了Windows下OpenGL的扩展应用。

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

screen_shot4-300x224 This sample shows how to do bump mapping with OpenGL. The bump mapping technology used here for approximating diffuse lighting.

 

The concept behind this article was Embossed bump mapping. The fragment diffuse lighting color  C could be evaluated like this:

Cf = (L•N)* Dl * Dm:
L is light direction;
N is vertex normal direction;
DI is light diffuse color;
Dm is material diffuse color; (DI * Dm could be combine into Ct usually)
(L·N) = (Fd + (H1-H0)) , instead of calculating lighting directly with light and normal, we could use some texture maps and other tricks to approximate such diffuse lighting – that is Embossed bump mapping. Fd is the diffuse factor, H1 is the bump map value sample with perturbed coordinates, and H0 is the bump texture value sample with usually coordinates.

The core of the bump mapping is to perturbing bump texture coordinates and do a subtraction between them. For full concept, you could refer to EmbossBumpMapping.ppt included in the downloaded package.

Considering the OpenGL API and hardware multiple texture blending feature support, this sample modify somewhere to make it more easy to implement:
•1) Because Cf = (Fd + (H1-H0)) * Ct
•2) Assume Fd = 1.0, we could get
•3) Cf = (H1+ (1.0-H0)) *  Ct
•4) H1 from bump texture and usually coordinates sampling
•5) (1.0 – H0) from inverse previous bump texture, and with perturbed coordinates
•6) GL_ADD H1 and (1.0 – H0)
•7) Add another rendering pass to blend with diffuse color
Because OpenGL texture stage combination result will be clamped into [0, 1]. So only half bump map texture will join the calculation. At the last step, we will store this by scaling with 2.0. To confirm with my thought, I will write a GLSL version to confirm later. The bump map texture usually is a gray scale texture. And the perturbed texture coordinates offsets based on the vertex to light direction, and project this normalized vector along S and T direction in it’s tangent space.

Bumping In & Bumping Out

One thing could be note is that, when you switch the bump texture and inverse texture bounding, you will see bumping effect still there. But the only difference is whether is bumping in or bumping out.

 

OpenGL Extension on Windows

Windows OS only OpenGL 1.1 supported, because they already had D3D. To access some more advanced features like multiple texture units, texture stage combination, you need to require extensions to GL 1.1. The texture stage combination appeared in GL 1.3, and deprecated in GL 3.0, and fully replace by GLSL in GL 3.1. Texture stage combination was a very useful technology that make you could blend and combine as more effect as possible. Some details document about the texture combination already provided in the downloaded zip file. Document “ogl_texture_gray.pdf” give you more details about how texture mapping going and also a dialog detail the texture stage combination well. Because the max size limitation, so I did not upload this file. You could find it on the web.
Be careful of the glext.h version when you need some extension features. Please make sure the correct version was there.

 

Another Bumping Sample

simplebump1-300x225 To get more information about the bump mapping technology, another sample also provided here. This sample used Normal map, per pixel diffuse lighting without GLSL. This sample compressed vertex to light direction into cube map, and do GL_DOT3_RGB_ARB between the normal map and cube map without no perturbing texture coordinates.

There was a parallax mapping example under the D3D sample directory. They used perturbed texture coordinates (based on the viewer position and vertex position) for the diffuse map and normal map, diffuse lighting and specular lighting could be calculated per pixel with HLSL. The whole effect is very cool.

 

The full source code could be downloaded from here.

转载于:https://www.cnblogs.com/open-coder/archive/2012/08/23/2653290.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值