Home » 3D, Download, XSI


15 February 2007 91,009 views 3 Comments

The Post Light caching system

When rendering lights (and especially area lights) with shadows, render times can sometimes get too long to maintain an interactive workflow.

To overcome this problem, I added a special mode to Post Light so that it saves out just the lighting information in a special format that can either be cached in memory or to a file.

If you want to know more about this specially encoded image, read the quick bit of theory below. Otherwise feel free to skip past it.

A Quick Bit of Theory

When rendering basic lighting with a phong shader, you can split the shading process into two components:

  • Diffuse
  • Specular

This however ignores the fact that we may have reflections happening as well. So to generalise further, we can re-categorise this into:

  • Multiplicative
  • Additive

The multiplicative component of lighting is multiplied by the surface color to produce the final appearance. So, for example, if we have a light with color:

(0.0, 0.5, 1.0)

and the surface has a color of:

(0.5, 0.5, 0.5)

then the final illuminated color will be:

(0.0, 0.25, 0.5)

assuming that the surface is pointing directly at the light.

The additive component of lighting is added directly to the final result of the multiplicative component of lighting. This means that our final equation of lighting (again, assuming that the surface is pointing directly at the light) is:

Result = (Multiplicative Component)  x  (Surface Color)
         + (Additive Component)

"So what?" I hear you say. Well, this means that if we want to store lighting and recombine it with other lighting later, it means that we have to separate it into two channels. Then, later, we can recombine it like this:

Result = (Mult. Comp. + Cached Mult. Comp.)  x  (Surface Color)
         + (Add. Comp. + Cached Add. Comp.)

This is why Post Light has to use a special encoded image. The image contains both channels of lighting stored in the one image. We have to do this, since nodes in the FX Tree are only allowed a single output.

Caching to your hard-drive

Once you have enabled Post Light’s cache mode (in the settings tab), you can save this output to disk. You must make sure, however, that you use an image format that supports floating point values. A good choice for this, is the “Mental Ray Color Texture” file format, which uses the extensions *.ct, *.ct16, and *.ctfp.

Simply use a File Output node to save the cache output to a file of your choice. Once this has been saved, you can reload it in with a File Input node. However, you must make sure that the File Input node type is set to &quotRGBA&quot and its bit depth is set to &quotfloat&quot, as otherwise the cache format will not be passed on correctly.

Caching to memory

If you are lucky enough to have enough memory, then saving the cache to file becomes unneccesary. You simply plug the output of the Post Light into the cache input of another Post Light node, and the FX Tree will only recalculate the cache if something changes further up the node tree.

If you try to use memory caching and you find that some or all of the Post Light nodes in your tree are recalculating, then you don’t have enough memory to use this approach (sorry!). You must use disk caching instead.

Note that you can manually refresh the upstream memory cache by clicking on the Post Light Monitor’s "Update Cache" button. This button has no effect if you are caching to disk.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)


  • Adam Seeley said:

    Hi, Any idea if this works in Xp 64 bit Soft 2010/2011/2011 sp1.



  • AndyN (author) said:

    Hi Adam,
    That’s a good question. I can’t see a reason why not, but it would need to be recompiled and I’m afraid I don’t have access to a Windows 64bit machine.

    It could only support phong based lighting models so it didn’t catch on as it probably wasn’t flexible enough for most pipelines. Anyway, as a result, I haven’t kept it up to date.


  • Moykul said:

    Brilliant tool! Thank you so much!

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.