Class MaxRenderElement

3DS Max Plug-In SDK

Class MaxRenderElement

See Also: Class IRenderElement, Class ShadeContext, Class IllumParams , Render Elements

class MaxRenderElement : public IRenderElement

Description:

This class is available in release 4.0 and later only.

This is the RenderElement base class for 3ds max’ default scanline renderer. RenderElement plugins that utilize ShadeContext and IllumParams should sub-class from here. . All render elements that support the max renderer should derive from this class. The class implements a handler for the ShadeOutputIndex of the elements value in the ShadeOutput array. Access to the elements value is accomplished within PostIllum or PostAtmosphere by:

 

AColor myColor;

// ... do some computation

sc.out.elementVals[ mShadeOutputIndex ] = myColor;

// ... or

sc.out.elementVals[ ShadeOutputIndex() ] = myColor;

 

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

Data Members:

protected:

int mShadeOutputIndex;

The index into element value array in shadeOutput class.

Methods:

public:

Prototype:

void SetShadeOutputIndex(int shadeOutputIndex);

Remarks:

This method sets the index into the element array in the ShadeOutput class. This method is implemented by this base class & need not be re-implemented by derivative classes. Derivative classes access the index either through the interface or directly as mShadeOutputIndex. Set is used by the system to assign an index to each element. This index persists throughout a single rendering.

Parameters:

int shadeOutputIndex

The shadeOutput index.

Prototype:

int ShadeOutputIndex();

Remarks:

This method gets the index into the element array in the ShadeOutput class. This method is implemented by this base class & need not be re-implemented by derivative classes. Derivative classes access the index either through the interface or directly as mShadeOutputIndex. Set is used by the system to assign an index to each element. This index persists throughout a single rendering.

Prototype:

virtual void Update(TimeValue timeValue)

Remarks:

This method will update the element to time timeValue. Note that most elements don’t care.

Update is called to communicate the time to the element. It will be called on each element before the call to PostIllum() is executed. No current render element uses this, but it could prove useful someday. This class provides a default stub implementation, so this need not be implemented unless needed.

Parameters:

TimeValue timeValue

The timevalue at which the update gets called.

Prototype:

virtual void PostIllum(ShadeContext& sc, IllumParams& ip)=0;

Remarks:

This method is used to compute the element and store the result in the ShadeContext's ShadeOutput.

This is the first of the actual computation methods for the render element. PostIllum() is called by the material just after an illumination is computed for a fragment. Some materials, like the multi-materials don’t compute illumination themselves but mix illuminations from other leaf materials. Such materials do not call PostIllum(), but need to consider the elements when blending the shadeoutputs from the leaf materials. The ShadeContext is the same shadecontext passed into the material’s shade method, & contains the member variable ‘out’, which is the current output from the full pixel shading and the storage place for renderElement values.

The other param, IllumParams, contains detailed information about the shading process. Specifically, the component-wise output from the shading process is available in the IllumParams. Also the illumParams passed in are dependent on whether the element has requested shadows or not. The standard material keeps two sets of these and supplies the one requested. This method must be implemented, tho some elements merely stub it out or clear the output element value. It should put it’s output is in sc.out.elementVals[ShadeOutputIndex() ]. Even if you do not need this function, it is a good idea to clear the element val.

Parameters:

ShadeContext& sc

A reference to the ShadeContext.

IllumParams& ip

A reference to the IllumParams.

Prototype:

virtual void PostAtmosphere(ShadeContext& sc, float z, float prevZ)=0;

Remarks:

This is the second computation method and is only called if the elements has atmospheres applied. If it is applied, then the element value is retrieved from the shadeContext, the atmosphere is applied to it & and the output from the atmosphere is left in sc.out.c and sc.out.t. Last, PostAtmosphere is called with the shadeContext, and the 2 z values used by the atmosphere to compute it. If the point is directly visible to the camera, then prevZ will be 0.0f, otherwise it is the z of the next closest obscuring transparent fragment in front of the fragment being shaded. It is up to the render element to process the output in sc.out.c and save the result in sc.out.elementVals[ShadeOutputIndex() ]. Note that when PostAtmosphere is called the original value set by PostIllum is saved in the element val. This can be overwritten or used in some computation. For example, to separate atmosphere from the composite color, sc.out.c and sc.out. elementVals[ShadeOutputIndex() ] can be differenced.

Parameters:

ShadeContext& sc

A reference to the ShadeContext.

float z

The first depth value.

float prevZ

The previous depth value.

Prototype:

virtual void* GetInterface(ULONG id)=0;

Remarks:

The renderer will call this method to see if IRenderElement is compatible with it This is used for future expansion in interface classes. When the 3ds max development team needs to add additional functionality to an interface class this method provides a way to do that without breaking the API. If the 3ds max developers would add methods to an existing class it would invalidate the plug-ins that used the class. Using thismethod allows additional functionality to be added to the interface class without breaking the API.

Parameters:

ULONG id

Currently this is not used and is reserved for future use.

Prototype:

virtual void ReleaseInterface(ULONG id, void *i)=0;

Remarks:

This method is not currently used. It is reserved for future use. Its purpose is for releasing an interface created with GetInterface().