bart
August 26th, 2006, 06:44
I thought this had been mentioned in this forum, by me or Zap, but I didn't find it in a search. It is a bit tricky to detect whether you are in the FG preprocessing phase. Basically, it is encoded in the answer to whether or not a material shader is in tile rendering phase.
Remember that the FG phase happens before the tile rendering phase, but may call material shaders at each FG point that is being processed.
To detect, use the miQ_TILE_* queries. It is hard to find, but if you look hard enough, it is actually in the manual. From the doc, under the description of mi_query:
The miQ_TILE_* codes are supported by mental ray 2.1.34.107 or later. They describe the location and size of the currently rendered image tile. The returned values are in the order xlow~~xhigh~~ylow~~yhigh. The sampled area may be larger than the tile due to filtering and jittering. These codes may be used to detect if a shader is called in the finalgather precomputing stage: for finalgather precomputing the return value is miFALSE as no tile exist.
So, for example you check the condition
!(mi_query(miQ_TILE_PIXELS, state, 0, &dummyint)) to see that the material shader is in FG preprocessing.
So why not use the miQ_FINALGATHER_STATE? Well, because it only says whether or not this material shader calculation is a result of an FG ray, in a secondary FG ray, ie a child or grandchild of an FG ray. Since FG rays are put out by the mi_compute_avg_radiance/mi_compute_irradiance functions in your material, there are times one may wish to detect this phase before the FG ray is sent out.
So if one really wanted to optimize during FG preprocessing, detect the FG preprocessing phase and don't do any direct lighting loop or ray trace reflection or refractions, and only call the mi_compute_avg_radiance/mi_compute_irradiance function.
There are also a couple other advanced tricks one can do with FG when detecting this phase.
For example, one could use this phase to store a custom kd-tree holding a glossy cache. A cache of any glossy reflections sent out by the shader.[/b]
Remember that the FG phase happens before the tile rendering phase, but may call material shaders at each FG point that is being processed.
To detect, use the miQ_TILE_* queries. It is hard to find, but if you look hard enough, it is actually in the manual. From the doc, under the description of mi_query:
The miQ_TILE_* codes are supported by mental ray 2.1.34.107 or later. They describe the location and size of the currently rendered image tile. The returned values are in the order xlow~~xhigh~~ylow~~yhigh. The sampled area may be larger than the tile due to filtering and jittering. These codes may be used to detect if a shader is called in the finalgather precomputing stage: for finalgather precomputing the return value is miFALSE as no tile exist.
So, for example you check the condition
!(mi_query(miQ_TILE_PIXELS, state, 0, &dummyint)) to see that the material shader is in FG preprocessing.
So why not use the miQ_FINALGATHER_STATE? Well, because it only says whether or not this material shader calculation is a result of an FG ray, in a secondary FG ray, ie a child or grandchild of an FG ray. Since FG rays are put out by the mi_compute_avg_radiance/mi_compute_irradiance functions in your material, there are times one may wish to detect this phase before the FG ray is sent out.
So if one really wanted to optimize during FG preprocessing, detect the FG preprocessing phase and don't do any direct lighting loop or ray trace reflection or refractions, and only call the mi_compute_avg_radiance/mi_compute_irradiance function.
There are also a couple other advanced tricks one can do with FG when detecting this phase.
For example, one could use this phase to store a custom kd-tree holding a glossy cache. A cache of any glossy reflections sent out by the shader.[/b]