Render Elements

3DS Max Plug-In SDK

Render Elements

See Also: Class IRenderElementMgr , Class IRenderElement, Class IRenderElementCompatible, Class MaxRenderElement

Overview

Render Elements allow renderers to output to separate bitmaps portions of the final shaded image so that they can be manipulated/composited at a later time, without re-rendering.

Render Elements are specific to a given renderer. 3ds max defines both a general interface that all render elements must support & an interface specific to elements supporting the max default renderer. Mental Ray specific elements will support the general interface, but probably define their own specific interface. Part of the general interface allows the system to figure out which installed render elements belong to which renderer, & to only list those compatible elements.

3ds max render elements are supported by code in each material. After shading each active render element’s PostIllum method is called in turn. It is provided with;

  • ·   the full shade context used to do the shading

  • ·   pointers to the material & (if there is one) shader used to do the computation

  • ·   textured inputs to the shader (e.g. diffuse color blended w/ diffuse texture color by the amount spinner)

  • ·   component-wise output from the shading process (diffuse term, reflection term…)

  • ·   there is provision for extending the component-wise outputs to include arbitrary name-matched channels (this allows materials w/ special components, e.g. flourescence in ray material, to be communicated to an element. The element must of course be looking for the special component. The component-wise outputs maybe computed either with or without shadows, depending on a query on the element interface.

Essentially, this is all of the information that is passed to 3ds max Shaders, plus the shadowed or unshadowed component-wise output from the materials shading process. This means that each render element may in fact be a complete, alternate, special-purpose shader. This is intentional, of course, so that any wacky thing might be created. Most current render elements don’t take advantage of this, tho, they merely process the component-wise output from the materials shading process, but the potential is very powerful.

3ds max Render elements then store their computed shade in an extended ShadeOutput class (imtl.h) that is part of the ShadeContext. The ShadeOutput has an array of element output values, one per element & each max render element is given an index into the array to use. The ShadeOutput will follow the fragments being shaded all through the compositing process, so that transparency & partial coverage is properly resolved.

Atmosphere cannot be properly computed at shading time since the object may be covered by a transparent object, dividing the needed calculation into two: atmosphere from the eye to the transparent object, composited over atmosphere between the two objects & the final objects color. Hence there is a second, optional call to each render element after the atmosphere is computed. The general interface tells the system whether to apply atmosphere to the render elements color, does so if desired & calls the PostAtmosphere call on the max render element.

Finally, a last query on the general interface determines whether to apply the AA filter when outputting the element to its bitmap, or merely blending with other elements in the pixel.

A sample plugin of a Render Element can be found in the SDK samples; \MAXSDK\SAMPLES\RENDER\RENDERELEMENTS.