This page describes a task during my Google Summer of Code project.
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.
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:
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:
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.
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.
This video demonstrates the current state of this approach: http://vimeo.com/13639081
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.
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.
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.
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:
cd source/blender/gpu/intern/ ../../../../release/datafiles/datatoc.py gpu_shader_material.glsl
You should then see an output like this:
Making C file <gpu_shader_material.glsl.c> 35002
Here's the patch you can apply to your trunk source code and have bump map painting working: http://www.pasteall.org/14580/diff
With the help of Fredrik H. I was able to simplify and fix the GLSL shader code and the new patch can be found here: http://www.pasteall.org/14593/diff .
I submitted a modified patch to the Patch Tracker: http://projects.blender.org/tracker/index.php?func=detail&aid=23084&group_id=9&atid=127 This patch fixes issues with graphics cards that have a Shader Model < 4 and it also simplifies the setup because the "Height to Normal" check box has been removed completely. Thanks again to Fredrik H., Tom M., Sam V. and all the friendly BlenderArtists.org users!
You can download a patched build from here:
- Linux: http://www.graphicall.org/builds/builds/showbuild.php?action=show&id=1508
- Windows: http://www.graphicall.org/builds/builds/showbuild.php?action=show&id=1510
- MacOSX: http://www.graphicall.org/builds/builds/showbuild.php?action=show&id=1511
About my GSoC branch
Currently my GSoC branch "soc-2010-kwk" is not the recommended way to test Bump Map Painting as there recently occurred some strange bugs with the paint tools.
If you want to try out Bump Map Painting, checkout the trunk and apply the patch linked above. Another opportunity is to try out the pre-patched build on graphicall.org. See above for the builds.
Example .blend file
If you want to try out painting a bump map yourself you can use this .blend file I've set up for direct painting. Either paint directly onto the model or onto the image in the UV/Image Editor.
Thanks to Sam V. who started the thread there is also a discussion going on in the BlenderArtists.org Forum: http://blenderartists.org/forum/showthread.php?t=192874
I really hope you like this feature! I would really appreciate every feedback or bug reports I can get. Please use the blender developers mailing list or add a comment to the video!