About Me

Hi. I'm Josh Ols. Lead Graphics Developer for RUST LTD.

Contact:
crunchy.bytes.blog[at]gmail[dot]com

View Joshua Ols's profile on LinkedIn

Meta
« Project videos | Main | Cheap specular lighting »
Sunday
Feb072010

Self-Shadowed Bump maps

UPDATE:
Something I thought I should mention that I realized only recently. In the section "Usage tips", I realized I was in error by saying that you need to swap the green & blue channels to make it work with RH normals. It is actually much simpler to swap the bottom two vectors in the basis in the shader to get the same effect at no extra cost. This way, you can use readily available tools, without any need to modify their output and introduce another step in the content creation pipeline.

Other than that, forget to mention the bonus pictures I added to the end of the post. Check them out, if you haven't already. ;)

UPDATE2:
SashaRX was asking about reflection vectors from an SS Bump map, so I thought I'd add it up here where everyone can see. Basically, all you need to do is get a tangent-space normal back, and then apply standard techniques from there. This is achieved by applying an inverse transformation to the SS Bump value using the basis vectors. Using just the basis vectors, the result will be in tangent-space. If you concatenate the tangent2world matrix with the basis vectors, you can transform staight to world-space.

Hope that helps. ;)

Code:
tanNormal = bumpBasis[0] * bump.x + bumpBasis[1] * bump.y + bumpBasis[2] * bump.z;
tanNormal = normalize(tanNormal);

Original:

For those who don't know, Self-Shadowed Bump maps were originally developed by Valve for use with their Radiosity Normal Mapping technology. After I decided to make the switch to a renderer built around pre-computed data, this was one of the first things I decided to try out. If you wish to read more about the technique, the following links have provided me with most of my information on the subject.

Links:

[1] Efficient Self-Shadowed Radiosity Normal Mapping

[2] Surface Detail Maps with Soft Self-Shadowing

[3] Half-Life 2 / Source Shading

[4] Shading in Valve's Source Engine

[5] SSBump Generator (used to make the maps)

 

Overview:

During the course of my experiments, I have verified all the benefits that Valve described in their papers. However, I have also discovered a few drawbacks that they didn't mention. Keeping that in mind, I have pooled and summarized my findings from all the papers and my own experiments.

Benefits:

  1. Directional Occlusion

  2. Correct filtering

  3. Detail mapping

  4. Recovers bent normals

  5. Better use of byte precision

  6. Faster than tangent-space normal maps

    • NOTE: Only for RNM, not for general diffuse lighting

Drawbacks:

  1. Diffuse Lighting expense

    • In order to get dynamic lighting with directional occlusion, each light direction has to be projected onto the basis. This boils down to the same amount of math as a 3x3 matrix multiply, per light direction.

  2. Poor compression

    • DXTC causes artifacts at detail edges, and nasty blocky artifacts in specular/reflection

    • RGB5 is acceptable for diffuse lighting, but produces banding for specular/reflections. Also, this format is not supported by Direct3D 10/Xbox 360.

 

Visuals:

height normalMapRH bumpRH ss bumpRH (SS Bump) recovered tangent (SS Bump) no DO SS Bump (bumped) (SS Bump) reflection

Figure 1. 1, Height map; 2, Normal map; 3, SS Bump (no DO); 4, SS Bump (DO); 5, recovered tangent normals; 6, no DO; 7, DO; 8, reflection

 

Masking:

(10) Red,  Right (11) Green, Upper Left (12) Blue, Lower Left (13) Right (14) Upper Left (15) Lower Left (16) Right (17) Upper Left (18) Lower Left

Figure 2. 1-3, RGB channels; 4-6, lightmaps w/o masks; 7-9, lightmaps masked

I added these images to help visualize how these maps just store multiplicative masks for the lightmaps. Note how sides facing the light direction receive almost no darkening, while those that are occluded are darkened to give the impression of shadowing.

 

Detail Mapping:

(SS Bump) enhanced detail (SS Bump) detailed (9) Recovered normal 17 - VTF 2010-02-24 01-46-50-17

Figure 3. 1, SS Bump map; 2, Detail map; 3, combined with SS Bump; 4, recovered normal; 5, diffuse lighting

This trick works since an SS Bump map is just a series of masks that get multiplied with the lightmaps. Since the lightmap data will be multiplied with the diffuse texture, we can effectively multiply the diffuse texture by the detail map if we just apply the detail map evenly to each color channel in the SS Bump map. This even weighting of each channel is what ensures that the recovered tangent normals are unaffected by the detail map.

 

Compression Artifacts:

(SS Bump) DXT1 (SS Bump) DXT1 diffuse (SS Bump) DXT1 reflection

Figure 4. 1, DXT1 SS Bump map; 2, diffuse lighting; 3, reflection


(SS Bump) RGB5 diffuse (SS Bump) RGB5 reflection

Figure 5. 1, RGB5 diffuse lighting; 2, reflection

 

Usage Tips:

Most tools that generate SS Bump maps will format them for the Source Engine, so they assume a left-handed coordinate system. This will cause issues with any programs that use a right-handed coordinate system. Fortunately, this issue can easily be fixed in a decent image editing program (Photoshop, Gimp, etc).

Tangent-Space normals:

Here, you just need to invert the contents of the green channel to flip the Y-axis.

normalMapLH normalMapRH

Figure 6. 1, normal LH; 2, normal RH

 

Self-Shadowed Bump maps:

Here, you have to swap the contents of the green and blue channels.

SS BumpLH ss bumpRH

Figure 7. 1, SS Bump LH; 2, SS Bump RH

 

Other than that, I thought I'd mention a problem I encountered while writing shader code to use these maps. The order of the bump basis vectors as Valve listed them in the paper can be a bit confusing, and will produce incorrect results that will have you scratching your head for days. To save you that trouble, here is how they should appear:

Code:

static half3 bumpBasis[3] =
{
    half3(sqrt(2.0) / sqrt(3.0),              0.0, 1.0 / sqrt(3.0)),
    half3(     -1.0 / sqrt(6.0),  1.0 / sqrt(2.0), 1.0 / sqrt(3.0)),
    half3(     -1.0 / sqrt(6.0), -1.0 / sqrt(2.0), 1.0 / sqrt(3.0))
};

 

Final Thoughts:

Despite the added storage and lighting cost, the benefits from using this technique are too enticing for me to pass up. So I have decided to integrate this technology into my new renderer for handling static objects. Dynamic objects, or anything that needs detail normal mapping, will still use Partial Derivative Normal maps for efficiency & flexibility. Between these two solutions, I should have a sufficiently versatile system for generating pleasing visuals.

 

Bonus:

Something I should have added a long time ago, there are two screenshots that have been sitting the in the comments section for some time now. They use a, SS Bump map from Valve's wiki, and really shows just how much depth this technology can add to even a flat surface. Check them out! ;)

(SS Bump) detailed 1(SS Bump) detailed 2

SS Bump map from Valve's wiki, "$ssbump"

Figure 8. 1, 0 degrees; 2, 90 degrees


PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (12)

Dude thats pretty cool. it really enhances the feeling of depth/detail

where did you get that cornell box?

I've been meaning to make my own but haven't taken the time.
February 10, 2010 | Unregistered CommenterJoe
Thanks. Glad to see that the results are pleasing to others. ;)

I had an artist make the Cornell Box for me. He used Maya to make the geometry/textures, and Turtle to bake the lightmaps.

Now if you want to see something really impressive, check out these new shots using an SS Bump map I obtained from the Valve Developer's wiki.
http://www.flickr.com/photos/59194038@N00/4349566046/sizes/o/
http://www.flickr.com/photos/59194038@N00/4349566498/sizes/o/
http://developer.valvesoftware.com/wiki/$ssbump
February 11, 2010 | Registered Commentern00body
haha... i need to make a cornell box...

wow that wiki explenation is cool, and i saw the generator.

seems like this is an alternative to screen space ambient occulsion, and can look as good if not better... requires more texture space though.
February 11, 2010 | Unregistered CommenterJoe
This is not a substitute for any kind of ambient occlusion, and works best when used in conjunction with it. SS Bump maps are purely a means of enhancing the effect of normal mapping, to better integrate them with their lighting environment. In particular, this technique takes advantage of AO baked into a lightmap to further enhance its believability.
February 11, 2010 | Registered Commentern00body
Very interesting results. I think this is a good example of what SSbumps can and cannot do.

However, the example of adding a detail map to the ssbump map doesn't really show too much. It's hard to see the difference or usefulness. I would suggest using a darker detail map, it would also be interesting to see a 'crack' detail map applied to the ssbump map.

Interesting information.
February 23, 2010 | Unregistered Commenterthe_best_flash
I've replaced the old detail mapping example images with some fresh ones. The new detail map I used is much darker, has a crack pattern, and is visible in the minimized example image. Is that more to your liking? :p
February 24, 2010 | Registered Commentern00body
Took me awhile to discover this . . .. Very helpful, and very much appreciate your time and efforts.
January 15, 2011 | Unregistered Commenterlearning
That's why I do it! I hope both you and my other readers find this article most enlightening. ;)
January 22, 2011 | Registered Commentern00body
I apologize for my bad English, tell me how you do the reflection, how to find the world vector
April 3, 2011 | Unregistered CommenterSashaRX
No worries. I've added a second update to the top of this post explaining how to recover a normal from an SS Bump map. Hopefully you know how to work out the rest from there. ;)
April 5, 2011 | Registered Commentern00body
it would be too much to ask for the shader code? I just want to see how YOU did it,to see how diferent is from what i did.
January 15, 2013 | Unregistered Commenterpachesantiago
If you follow the links to the papers on Self-Shadowed Bump mapping, you will have your answer. I didn't do anything special with my shaders, I just followed what Valve outlined in their papers.
January 15, 2013 | Registered Commentern00body

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Hyperlinks will be created for URLs automatically.