Implementing Advanced Material and Texture Map Plug-ins with Nitrous

Advanced Material and Texture Map Display API

NOTE:MetaSL is no longer supported in 3ds Max 2016. You can use HLSL shaders instead.

Use HLSL to Customize the Viewport Display in Realistic Mode

Materials can use programmable shaders to describe their appearance when displayed in the Nitrous viewport and rendered with Quicksilver. 3ds Max 2014 supports HLSL shader. This enables the material plug-ins to use a DirectX effect to control how the material displays when Show realistic material in viewport (for this material) is selected.

IHLSLMaterialTranslator

IHLSLMaterialTranslator provides a chance in its UpdateHLSLMaterial() to update the parameters of HLSLMaterialHandle, such as parameter values and map channel values. See HLSLMaterialHandle for more details. Plug-ins derive from IHLSLMaterialTranslator. They rather need to create instances of HLSLMaterialHandle. 3ds Max queries the plug-in for its IHLSLMaterialTranslator through a request for the interface identified by IHLSL_MATERIAL_TRANSLATOR_INTERFACE_ID. Then, gets HLSLMaterialHandle using GetHLSLMaterialHandle() of IHLSLMaterialTranslator. Typically, a plug-in implements GetHLSLMaterialHandle() of IHLSLMaterialTranslator in response to this request, and its override of Animatable::GetInterface(Interface_ID) for IHLSLMaterialTranslator.

The following code snippet shows how a material plug-in might implement IHLSLMaterialTranslator:

#include <./graphics/IHLSLMaterialTranslator.h>

// A material plug-in has HLSLMaterialHandle and needs to update HLSLMaterial parameters.
class MyMtlPlugin : public MtlBase, public MaxSDK::Graphics::IHLSLMaterialTranslator {
    // omitted for brevity
private:
    HLSLMaterialHandle mHLSLMaterialHandle;
public:
    virtual bool UpdateHLSLMaterial(
        const TimeValue t, 
        GraphicFeatureLevel featureLevel)
    {
        mHLSLMaterialHandle.SetFloatParameter(
            _M("myFloatShaderParam"),
            floatValue);
        mHLSLMaterialHandle.SetIntParameter(
            _M("myIntShaderParam"), 
            intValue);
        return true;
    }

    virtual const HLSLMaterialHandle& GetHLSLMaterialHandle(
        GraphicFeatureLevel featureLevel)
    {
        return mHLSLMaterialHandle;
    }

    BaseInterface* GetInterface(Interface_ID iid)
    {

        if (IHLSL_MATERIAL_TRANSLATOR_INTERFACE_ID == iid)
            return static_cast<IHLSLMaterialTranslator*>(this);
        else
            return MtlBase::GetInterface(iid);
    }
}

HLSLMaterialHandle

HLSLMaterialHandle is a class to support HLSL custom material. This class is used for viewport display and Quicksilver. It is used by RenderItemHandle::SetCustomMaterial() to describe HLSL custom material. It can also be used for realistic material display. See IHLSLMaterialTranslator for more information.

The following code snippet shows how to use HLSLMaterialHandle:

HLSLMaterialHandle hMaterial;
hMaterial.Initialize(shaderFileName);
hMaterial.SetFloatParameter(_M("myFloatShaderParam"), floatValue);

Transparency Hints

The Nitrous viewport display system and the Quicksilver renderer optimize the display lists to work with transparency. A new MtlBase::GetTransparencyHint() method is used to get a boolean value that indicates whether transparency is supported at a certain time (a transparency "hint"), and to provide the validity interval for it. The validity of this hint is checked by 3ds Max in each frame.

Once it becomes invalid, MtlBase::GetTransparencyHint() is called again. By default, this method returns TRUE. If the material does not support transparency in any form, then the plug-in's override of this method must return FALSE. This is particularly important for custom materials that use shading languages. Only the shader or the host material knows what is happening internally and whether transparency is affected. Supporting this method helps optimize their drawing and rendering.