From BlenderWiki

About

Scenario

Consider you wanted to add surface details to a model without changing the actual geometry but by using the paint tools that are already present in Blender.

Problem

There are several approaches to add "fake" geometrical detail to a model by applying a normal map. This normal map is then read by the visualization program to manipulate how the light bounces off the model's surface. With this approach you can for instance, sculpt a high-res model, bake a normal map, then switch back to a low-res version of the model and apply the normal map. This way you get lesser polygons to calculate but the surface detail remains nearly the same with the low-res model.

No normal mapping already works in blender as can be seen in the following pictures:

Normal Map of Suzanne

Render of the Normal Map applied to a plane, perpendicular to the surface.

Even though the rendered result with the normal map applied looks very promising there is one drawback: It is hard to manipulate a normal map by hand. This is exactly where bump map painting comes in.

A bump map is much less complex compared to a normal map. It is usually a grayscale image and the result when applied to a flat surface looks not as good as a normal map applied to a flat surface:

Bump Map of Suzanne

Render of the Bump Map applied to a plane.

As you can see, the bump map applied looks somehow flattened.

Current state in Blender

Currently, Blender can render normal map previews in the 3D view by using OpenGL Shaders, but there is no way to preview a bump map in such a way.

Idea

I want enable artists to paint and PREVIEW bump maps by using the normal paint tools. This way artists can paint directly onto the model in the viewport and see their strokes influencing how light bounces off the surface.

Video

Solution

How to visualize a bump map in the 3D view?

Since normal mapping already works, the easiest way to visualize a bump map in the 3D view is to convert the bump map into a normal map and use normal mapping as the technique to achieve the bump effect.

You might say that a color conversion for a complete image takes too long, but in fact it doesn't if you use the GPU do the computation for you. I've looked into the source code for The GIMP normalmap plugin and streamlined the explicit C code to an OpenGL shader that implicitly calculates a normal value based on four texture lookups around each pixel.

Screen shot

Screen shot of GLSL bump map preview and the final render

End-User Documentation

How to set up a model for bump map painting?

Open Blender with the default cube scene.

Create another space and set it to be an UV/Image Editor. Create a new image with the default settings and call it "bumpmap".

Unwrap the cube using seams. Press "w" in the 3D view and select unwrap. Now in the UV/Image Editor select the bump map image.

Set the texture mode to "Textured"

Go to the "Texture Paint" mode.

Press "n" and scroll down to the "Display" section of the view properties and under "Shading" select "GLSL". (You might also wanna check the "Only Render" box to have a nice looking preview without disturbing grids.)

Go to the "Texture" settings and make these modifications to the current texture slot:

Under "Mapping" set "Coordinates" to "UV".

Under "Type" select "Image or Movie"

Under "Image" select the "bumpmap" image we created earlier.

Under "Influence->Geometry" check "Normal". You can use this value slider to adjust the height of the bumps. Negative values invert the bumps.

In the UV/Image Editor under "Image" you can check "Image Painting" if you want to painting in the UV/Image Editor.

Now you've set up Blender to preview and paint Bump Maps.

What colors to use when painting?

I need to figure out how the Blender renderer interprets bump maps, but currently my shader maps dark to high/bumpy and white to low/flat.

To control the overall height of the bumps, you can use the "Normal" slider control under the texture influence group.

Bugs

Lately, Brecht reported two more errors I made when coding:

When there's no image, a division by zero can cause a crash. (Fixed locally but patch in tracker not updated).

I'm doing tangent space normals where the renderer uses something else; it probably uses UV. I need to look into this. Brecht reported that the Bump Mapping looks not good at UV seams.

Older bugs:

Currently there are some issues but I think they can be fixed quickly.

For instance if I'm not mistaken the texture seems to be projected upside down on the model.

Another issue to look at is the integration into Blender's normal render pipeline. Currently my patch only allows bump map preview through GLSL in the 3D view. The render output when hitting F12 still uses the height map as a color texture. It's strange though because I turned the color influence for the image texture to zero and my patch shouldn't affect the render pipeline.

I've used a Shader Model 4 function in the OpenGL Shader, namely textureSize2D() which seem to make problems with many graphics cards.

I am happy that the previewing is at least working the way I've planned it.

If you modify the GLSL code

Don't forget to generate a new "gpu_shader_material.glsl.c" file if you modified the "gpu_shader_material.glsl". You can do this by typing: