Occlusion that needs Forward Shading

Occlusion that needs Forward Shading

As mentioned in the last post, many materials out there need some kind of custom shading model to look correct. If you wanted to do all those materials with a fat G buffer, your G buffer would quickly become way too fat. So to get that kind of shader generality on todays GPUs you probably need forward shading.

But another way to greatly help shading in today’s games is with better kinds of occlusion. In games it’s pretty standard to have some kind of ambient occlusion affecting the characters. And there are many variations of occlusion that we can do to easily prevent light leaking and make objects seem like they belong in the scene.

1. Spherical Harmonic AO

One technique that I see huge potential in is Spherical Harmonic Ambient Occlusion. I mentioned this at my GDC talk. For each vertex you calculate spherical harmonics offline and when you render you project the light into spherical harmonics. With this technique you can figure out which directions light is not allowed to come from. The image on the left is using SHAO and the image on the right is not. That is why you see light leaking on the eyes, ears, etc.

To use this technique you need 9 channels. There is no way you can include 9 extra channels in your G buffer. The technique is too expensive to do everywhere, but for close ups of important objects it makes a big difference at minimal cost.

Also, the cost could be considered negative. It’s common to need many shadowed lights when lighting characters and the cost of those shadows adds up fast. With SHAO you would still want shadows on your key lights but SHAO lets you skip the shadow on your fill lights. Which is more expensive: An optimized deferred-only renderer with lots of shadows or a forward plus renderer with fewer shadows? As we all know, it depends.

2. Diffuse/Specular AO

For the same demo there was a baked, animated AO term that moved with the eyes. One thing I did not mention was that there is a different AO function for the diffuse and specular term.

Diffuse and specular light act very differently based on occlusion. Diffuse light leaves the surface in all directions but specular light is much more likely to leave at grazing angles (due to fresnel). So when we are in a cavity the specular term should be affected much more strongly by AO than the diffuse term. A small increase the amount of occlusion causes a much stronger effect on specular than diffuse light. Naturally, this means that you often want a stronger/different AO for diffuse and specular.

3. Analytic AO

In some situations you have a simply analytic formula for the occlusion affecting your surface based on the light direction. One of the more annoying artifacts is lights from behind the head lighting up the teeth and tongue. In fact, this problem is more common this generation than last generation because proper physically based specular will be much brighter at grazing angles and cause more artifacts than our bad, non-physically based lights of generations past.

One stupidly simple technique to minimize this problem is say that lighting inside the mouth can only come from the front. Let’s say you know the forward vector for the head, which we will call F. Then you can modulate the light brightness by saturate(dot(L,F)). It’s very cheap, very simple, and greatly helps. But it’s very difficult to do this with a G buffer.

4. Polynomial Texture Maps

One of the graphics techniques that games never adopted and could use another look is Polynomial Texture Maps. The key idea is to store a quadratic polynomial of the lighting function at every point on the texture.

This results in some really cool lighting effects. One of the main flaws of game lighting models is that local details don’t interact at all, but with PTMs each pixel knows which directions light can come from (or at least an approximation of that). It gives you the effect of each of the little bumps on a surface self-shadowing the other bumps.

There are several issues of course. The first problem is authoring. PTMs seem to be mainly used for imaging ancient artifacts. It’s much easier to scan a PTM than to physically send a 1000 year old vase found in Africa to an expert in South America. But if you wanted to scan a game texture you need authoring tools (like tiling) which is a major undertaking.

Another problem is memory. Instead of a single diffuse map you need 6 diffuse maps to properly recreate the PTM. The lighting function is cheap once you read those maps but memory is always tight so 6 maps is a bit much.

I think the interesting variation is only storing baked occlusion. If you have a high-res z-brush sculpt then you could bake a PTM of the occlusion so that all of the little bumps and crevices would self-shadow. That would cost you six channels, which would fit into two BC7 maps. I believe Turtle (from Illuminate Labs, before they were purchased by Autodesk) still supports these and it is included in Maya 2014 and later.

5. New Research? Finally, I’m sure there are new techniques out there to be discovered. I’ve already talked with several people doing interesting things that are improvements on these, but they aren’t released publicly so I can’t talk about them. The common thread is that there are a number of techniques for occlusion with the following properties:

  • Looks good.
  • Occludes based on light direction.
  • Has many parameters.
  • Is cheap enough to use in moderation, but too expensive to use everywhere.

For occlusion techniques fitting those four criteria you probably need forward shading, and I would expect to see more techniques like that in the future.

comments powered by Disqus