• You should first have the colored-texture. The bumpmap can be often derived from it using an average paint-program and converting it to grey-scale.
• The bumpmap should be "sharper" and higher in contrast than the color-texture. This is usually done by applying a "sharpening filter" to the texture and might look strange at first, but believe me: you can sharpen it A LOT in order to get first class visual appearance.
• The bumpmap should be centered around 50%-grey (RGB=127,127,127), since this means "no bump at all", brighter values represent ing bumps and lower "scratches". This can be achieved using "histogram" functions in some paint-programs.
• The bumpmap can be one fourth in size of the color-texture without "killing" visual appearance, though you'll definitely see the difference. Now you should at least have a basic understanding of the issued covered in this tutorial. I hope you have enjoyed reading it.
If you have questions and / or suggestions regarding this lesson, you can just mail me, since I have not yet a web page.
This is my current project and will follow soon.
Thanks must go to:
• Michael I. Gold for his Bump Mapping Documentation
• Diego Tártara for his example code
• NVidia for putting great examples on the WWW
• And last but not least to NeHe who helped me learn a lot about OpenGL.
* DOWNLOAD Visual C++ Code For This Lesson.
* DOWNLOAD Borland C++ Builder 5.0 Code For This Lesson. (Conversion by Michael Friedl)
* DOWNLOAD Delphi Code For This Lesson. (Conversion by Marc Aarts)
* DOWNLOAD Java Code For This Lesson. (Conversion by Jeff Kirby)
* DOWNLOAD Linux Code For This Lesson. (Conversion by Luca Rizzuti)
* DOWNLOAD Linux/SDL Code For This Lesson. (Conversion by Ti Leggett)
* DOWNLOAD Mac OS Code For This Lesson. (Conversion by Morgan Aldridge)
* DOWNLOAD Mac OS X/Cocoa Code For This Lesson. (Conversion by Bryan Blackburn)
* DOWNLOAD Visual C++ / OpenIL Code For This Lesson. (Conversion by Denton Woods)
Lesson 23
Sphere Environment Mapping is a quick way to add a reflection to a metallic or reflective object in your scene. Although it is not as accurate as real life or as a Cube Environment Map, it is a whole lot faster! We'll be using the code from lesson eighteen (Quadrics) for the base of this tutorial. Also we're not using any of the same texture maps, we're going to use one sphere map, and one background image.
Before we start… The "red book" defines a Sphere map as a picture of the scene on a metal ball from infinite distance away and infinite focal point. Well that is impossible to do in real life. The best way I have found to create a good sphere map image without using a Fish eye lens is to use Adobe's Photoshop program.
Creating a Sphere Map In Photoshop:
First you will need a picture of the environment you want to map onto the sphere. Open the picture in Adobe Photoshop and select the entire image. Copy the image and create a new PSD (Photoshop Format) the new image should be the same size as the image we just copied. Paste a copy of the image into the new window we've created. The reason we make a copy is so Photoshop can apply its filters. Instead of copying the image you can select mode from the drop down menu and choose RGB mode. All of the filters should then be available.
Next we need to resize the image so that the image dimensions are a power of 2. Remember that in order to use an image as a texture the image needs to be 128×128, 256×256, etc. Under the image menu, select image size, uncheck the constraint proportions checkbox, and resize the image to a valid texture size. If your image is 100×90, it's better to make the image 128×128 than 64×64. Making the image smaller will lose alot of detail.
The last thing we do is select the filter menu, select distort and apply a spherize modifier. You should see that the center of the picture is blown up like a balloon, now in normal sphere maps the outer area will be blackened out, but it doesn't really matter. Save a copy of the image as a .BMP and you're ready to code!
We don't add any new global variables this time but we do modify the texture array to hold 6 textures.
GLuint texture[6]; // Storage For 6 Textures
The next thing I did was modify the LoadGLTextures() function so we can load in 2 bitmaps and create 3 filters. (Like we did in the original texturing tutorials). Basically we loop through twice and create 3 textures each time using a different filtering mode. Almost all of this code is new or modified.
int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
int Status=FALSE; // Status Indicator
AUX_RGBImageRec *TextureImage[2]; // Create Storage Space For The Texture
memset(TextureImage,0,sizeof(void *)*2); // Set The Pointer To NULL
// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
if ((TextureImage[0]=LoadBMP("Data/BG.bmp")) && // Background Texture
(TextureImage[1]=LoadBMP("Data/Reflect.bmp"))) // Reflection Texture (Spheremap)
{
Status=TRUE; // Set The Status To TRUE
glGenTextures(6, &texture[0]); // Create Three Textures
for (int loop=0; loop<=1; loop++) {
// Create Nearest Filtered Texture
glBindTexture(GL_TEXTURE_2D, texture[loop]); // Gen Tex 0 And 1
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[loop]->sizeX, TextureImage[loop]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[loop]->data);
// Create Linear Filtered Texture
glBindTexture(GL_TEXTURE_2D, texture[loop+2]); // Gen Tex 2, 3 And 4
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[loop]->sizeX, TextureImage[loop]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[loop]->data);