Class IHardwareMaterial

3DS Max Plug-In SDK

Class IHardwareMaterial

See Also: Class IDXDataBridge

 

class IHardwareMaterial: public BaseInterface

Description:

This class is only available in release 5 or later.

A pointer to this class is provided by IDXDataBridge::SetDXData(). The GFX layer will implement all these methods. Most of the methods are direct replicas of the DirectX API for SetRenderState and SetTextureStageState.

The reason for this is that only one thread can access the graphics hardware at any one time. Using this interface means that the GFX driver can have its database initialized with the DirectX states required for this object, when it comes to access the graphics device.

To use this class good knowledge of DirectX is needed, a copy of the DirectX documentation is also recommended.

For an example usage of this class see MAXSDK\SAMPLES\HardwareShaders\LightMap\Lightmap.cpp

 

Methods:

Prototype:

virtual Interface_ID  GetID()

Remarks:

The returns the unique ID for this interface. By default it will return IHARDWARE_MATERIAL_INTERFACE_ID

 

Prototype:

virtual void SetFillMode(DWORD mode) = 0

Remarks:

This is equivalent to the DirectX method SetRenderState(FILLMODE,mode)

 

Parameters:

DWORD mode

A member of D3DFILLMODE

 

Prototype:

virtual void SetShadeMode(DWORD mode) = 0

Remarks:

This is equivalent to DirectX method SetRenderState(SHADEMODE,mode)

 

Parameters:

DWORD mode

A member of D3DSHADEMODE

 

Prototype:

virtual void SetMaterial(LPD3DXMATERIAL pMtl) = 0

Remarks:

Please see the DirectX documentation for more information on this method

 

Prototype:

virtual void SetDiffuseColor(LPD3DXCOLOR pClr) = 0

 

Remarks:

Specifies Diffuse color to be set by using the DirectX data structure LPD3DXCOLOR.

 

Prototype:

virtual void SetDiffuseColor(Color c, float alpha = 1.0f) = 0

Remarks:

Allows the Diffuse color to be set

 

Parameters:

Color c

The diffuse color

float alpha

The colors alpha

 

Prototype:

virtual void SetDiffuseColor(Point3 c, float alpha = 1.0f) = 0

Remarks:

Allows the Diffuse color to be set

 

Parameters:

Point3 c

The diffuse color

float alpha

The colors alpha

Prototype:

virtual void SetAmbientColor(LPD3DXCOLOR pClr) = 0

 

Remarks:

Specifies the Ambient color to set by using a DirectX data structure.

 

Prototype:

virtual void SetAmbientColor(Color c, float alpha = 1.0f) = 0

 

Remarks:

Allows the Ambient color to be set

Parameters:

Color c

The ambient color

float alpha

The colors alpha

 

Prototype:

virtual void SetAmbientColor(Point3 c, float alpha = 1.0f) = 0

 

Remarks:

Allows the Ambient color to set

Parameters:

Point3 c

The ambient color

float alpha

The colors alpha

 

Prototype:

virtual void SetSpecularColor(LPD3DXCOLOR pClr) = 0

 

Remarks:

Specifies the Specular color to set by using a DirectX data structure.

 

Prototype:

virtual void SetSpecularColor(Color c, float alpha = 1.0f) = 0

 

Remarks:

Allows the Specular color to be set

Parameters:

Color c

The specular color

float alpha

The colors alpha

 

Prototype:

virtual void SetSpecularColor(Point3 c, float alpha = 1.0f) = 0

 

Remarks:

Allows the Specular color to set

Parameters:

Point3 c

The specular color

float alpha

The colors alpha

 

Prototype:

virtual void SetEmissiveColor(LPD3DXCOLOR pClr) = 0

 

Remarks:

Allows the Emissive color to set by using a DirectX data structure.

 

Prototype:

virtual void SetEmissiveColor(Color c, float alpha = 1.0f) = 0

 

Remarks:

Allows the Emissive color to be set

 

Parameters:

Color c

The emissive color

float alpha

The colors alpha

 

Prototype:

virtual void SetEmissiveColor(Point3 c, float alpha = 1.0f) = 0

 

Remarks:

Allows the Emissive color to be set

 

Parameters:

Point3 c

The emissive color

float alpha

The colors alpha

 

Prototype:

virtual void SetSpecularPower(float power) = 0

 

Remarks:

Allows the specular exponent of the material to be set

Parameters:

float power

The specular amount

 

Prototype:

virtual void SetNumTexStages(DWORD numStages)= 0

 

Remarks:

This sets the internal size for the table that will hold the Texture information for the material. If you are not using any Texture stages then this should be set to zero, otherwise it should match exactly the number of textures being used.

Parameters:

DWORD numStages

The number of Texture stages

Prototype:

virtual bool SetTexture(DWORD stage, DWORD_PTR pTexture) = 0

Remarks:

This allows a texture to be loaded to the graphics device. In this case the texture is loaded/created by the GFX via calls to IHardwareRenderer::BuildTexture() which will return a DWORD_PTR, which is an internal representation of the texture. The texture was allocated it will return true.

 

Parameters:

DWORD stage

The stage to hold the texture

DWORD_PTR pTexture

A texture pointer returned by IHardwareRenderer::BuildTexture()

Prototype:

virtual bool SetTexture(DWORD stage, LPCSTR filename) = 0

Remarks:

This allows a texture to be loaded to the graphics device. The file is assumed to exist. If successful it will return true.

Parameters:

DWORD stage

The stage to hold the texture

LPCSTR filename

A string containing the filename of the texture to load 

 

Prototype:

virtual bool SetTextureUVWSource(DWORD stage, DWORD type) = 0

Remarks:

This specifies where the Texture Coordinates will be retrieved. Most of the time the mesh will supply them so the type would be UVSOURCE_HWGEN. However a Viewport Shader could create them dynamically so would supply. If successful it will return true.

Parameters:

DWORD stage

The stage to set

DWORD type

The UVW Source. It can be any of the following :- 

UVSOURCE_MESH

UVSOURCE_XYZ

UVSOURCE_MESH2

UVSOURCE_WORLDXYZ

UVSOURCE_FACEMAP

UVSOURCE_HWGEN

 

Prototype:

virtual bool SetTextureMapChannel(DWORD stage, DWORD numChan) = 0

Remarks:

This specifies what mapping channel from the mesh the Texture Coordinates will be retrieved. This is used in the stripping code so that the VertexBuffer is populated with the correct TVs. If successful it will return true.

Parameters:

DWORD stage

The stage to set

DWORD type

The mapping channel to use 

 

Prototype:

virtual bool SetTextureCoordIndex(DWORD stage, DWORD index) = 0

Remarks:

This specifies what texture coordinate the stage will use. This value is used in the DirectX call SetTextureStageState(stage, D3DTSS_TEXCOORDINDEX, index). If successful it will return true.

Parameters:

DWORD stage

The stage to set

DWORD index

The texture coordinate index to use

 

Prototype:

virtual bool SetTextureTransformFlag(DWORD stage, DWORD flag) = 0

 

Remarks:

This specifies what texture flag the stage will use. This value is used in the DirectX call SetTextureStageState(stage, D3DTSS_TEXTURETRANSFORMFLAGS, flag). If successful it will return true.

Parameters:

DWORD stage

The stage to set

DWORD flag

The DirectX flag to set

 

Prototype:

virtual bool SetTextureTransform(DWORD stage, LPD3DXMATRIX pTransform)= 0

 

Remarks:

This specifies what texture flag the stage will use. This value is used in the DirectX call SetTransform((D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0+stage), pTransform). If successful it will return true.

Parameters:

DWORD stage

The stage to set

LPD3DXMATRIX pTransform

The DirectX matrix to set 

 

Prototype:

virtual bool SetTextureColorOp(DWORD stage, DWORD colorOp)= 0

Remarks:

This method is a direct replica if the DirectX color operators used with D3DTSS_COLOROP. Please refer to the DirectX documentation for further information

Parameters:

DWORD stage

The stage to set

DWORD colorOp

A member of the DirectX enumerated type D3DTEXTUREOP

 

Prototype:

virtual bool SetTextureColorOpArg(DWORD stage, DWORD argNum, DWORD colorArg) = 0

Remarks:

This method is a direct replica if the DirectX Texture Argument flag used with D3DTSS_COLOROPARG. The argNum defines which argument to set. Please refer to the DirectX documentation for further information

 

Parameters:

DWORD stage

The stage to set

DWORD argNum

The argument index to set. If this is set to 1 then D3DTSS_COLORPARG1 will be addressed

DWORD colorArg

The Argument to set. 

 

Prototype:

virtual bool SetTextureAlphaOp (DWORD stage, DWORD alphaArg)= 0

Remarks:

This method is a direct replica if the DirectX alpha blending operators used with D3DTSS_ALPHAOP. Please refer to the DirectX documentation for further information

Parameters:

DWORD stage

The stage to set

DWORD alphaArg

A member of the DirectX enumerated type D3DTEXTUREOP

 

Prototype:

virtual bool SetTextureAlphaArg(DWORD stage, DWORD argNum, DWORD AlphaArg) = 0

Remarks:

This method is a direct replica if the DirectX Texture Alpha Argument flag used with D3DTSS_APLHAPARG. The argNum defines which argument to set. Please refer to the DirectX documentation for further information

 

Parameters:

DWORD stage

The stage to set

DWORD argNum

The alpha argument index to set. If this is set to 1 then D3DTSS_ALPHAARG1 will be addressed

DWORD colorArg

The Alpha Argument to set.

 

 

Prototype:

virtual bool SetVertexShader(DWORD_PTR pVertexShader)=0

Remarks:

This method allows a DirectX vertex shader to be loaded. It is used in conjunction with IHardwareRenderer::LoadVertexShader which will return a DWORD_PTR of internal storage for the shader. There are methods in IHardwareRenderer that provide a means to supply the constants used in the shader.

 

Parameters:

DWORD_PTR pVertexShader

The vertex shader to load.

 

Prototype:

virtual bool SetPixelShader(DWORD_PTR pPixelShader)=0

Remarks:

This method allows a DirectX pixel shader to be loaded. It is used in conjunction with IHardwareRenderer::LoadPixelShader which will return a DWORD_PTR of internal storage for the shader. There are methods IHardwareRenderer that provide a means to supply the constants used in the shader.

 

Parameters:

DWORD_PTR pPixelShader

The vertex shader to load

 

Prototype:

virtual bool SetEffect(DWORD_PTR pEffect)=0

Remarks:

This method allows a DirectX effect. It is used in conjunction with IHardwareRenderer::LoadEffectFile which will return a DWORD_PTR of internal storage for the file. There are methods in IHardwareRenderer that provide a means to connect the application to the effects file.

 

Parameters:

DWORD_PTR pEffect

The effect file to load