Hardware Rendered Materials
 
 
 

3ds Max supports hardware rendering of materials using DirectX. The main interface to use is the IDX9DataBridge interface. This interface provides the communication between the materials and the Direct3D graphics layer. The graphics layer will query for this interface to make sure the material supports a “hardware†interface. The graphics layer will then continue to query for the DX9_VERTEX_SHADER_INTERFACE_ID. This interface is derived from IDX9VertexShader.

IDX9VertexShader provides the direct drawing communication between the graphics layer and the material. The material can simply create an instance of the class that implements this interface and use this in the communication to the graphics layer.

A typical InterfaceServer::GetInterface() and would look like (example taken from \samples\hardwareshaders\MetalBump9):

class MaxVertexShader : public IDX9VertexShader, public IStdDualVSCallback
{
  // ...
}
 
class MaxShader : public  ReferenceTarget, public IDX9DataBridge,  TimeChangeCallback
{
    MaxVertexShader *m_VS;
 
    BaseInterface* GetInterface(Interface_ID id)
    {
       if (id ==  VIEWPORT_SHADER_CLIENT_INTERFACE) {
           return static_cast< IDXDataBridge*>(this);
       }
       else if (id==  VIEWPORT_SHADER9_CLIENT_INTERFACE)
       {
           return static_cast< IDX9DataBridge*>(this);
       }
       else if(id ==  DX9_VERTEX_SHADER_INTERFACE_ID)
       {
           return(( IDX9VertexShader *)m_VS);
       }
       else
       {
           return( BaseInterface::GetInterface(id));
       }
    }
 
    //...
}

The method IDX9VertexShader::DrawMeshStrips() is used if you want a hardware vertex shader to draw the mesh. If this method return returns true it is assumed that the material will draw the mesh and 3ds Max will not continue any further drawing of the object. The developer can make use of the IRenderMesh interface to assist in creating a Hardware version of the 3ds Max mesh. If you want 3ds Max to do the drawing, then you are restricted to the vertex format being sent to the vertex buffer. In particular no Tangent or Binormal vectors are generated by the base mesh classes. An example of allowing max to perform the drawing can be seen in \samples\hardwareshaders\Membrane.

To receive information about the validity of the mesh, you can use the IStdDualVS and IStdDualVSCallback. The callback will inform the material that something about the mesh has changed - usually a topological change - and the InitValid method is called. Using InitValid, you can rebuild any internal structures or mesh data ready for the next draw call. To execute your custom draw routines, assuming that IDX9VertexShader::DrawMeshStrips returns True, initiate them from IDX9VertexShader::Initialize(), which is called for each render pass for each material.