Required Changes To Plug-In Textures

3DS Max Plug-In SDK

Required Changes To Textures Plug-In

See Also: What's New in the MAX 3.0 SDK, Required Changes to MAX 2.0 Plug-Ins for MAX 3.0.

Using an XYZGen or UVGen

All 2D textures that use UVGen or otherwise select mapping channels need to implement the method MtlBase::LocalMappingsRequired()

Here is a typical implementation:

void LocalMappingsRequired(int subMtlNum, BitArray & mapreq, BitArray &bumpreq) {

 uvGen->MappingsRequired(subMtlNum,mapreq,bumpreq);

 }

All 3D Textures that use the XYZGen to put up a coordinates rollup must now implement the new MtlBase::LocalMappingsRequired() method

An example is shown below:

void LocalMappingsRequired(int subMtlNum, BitArray & mapreq,BitArray &bumpreq) {

xyzGen->MappingsRequired(subMtlNum,mapreq,bumpreq);

}

Materials that need bump mapping for certain channels also need to implement this function so they can set the bits in bumpreq for those channels.

GetUVWSource Return Values

The method Texmap::GetUVWSource() returns a value indicating where to get the texture verticies. One of the options has changed meaning. The value UVWSRC_EXPLICIT2 has been changed to always mean the vertex color channel.

New GetMapChannel Method

There is a new method in Texmap related to the new mapping channels, GetMapChannel(). This method returns the map channel being used when GetUVWSource() returns UVWSRC_EXPLICIT.

List of Material Requirement Flags

The old material requirement flags returned from the MtlBase::Requirements() method MTLREQ_UV, MTLREQ_UV2, MTLREQ_BUMPUV, and MTLREQ_BUMPUV2 are still recognized by the renderer for backwards compatibility, but they will probably go away at some time. See Class MtlBase for details.

Maximum Pixel Size

The maximum pixel size preference has been removed from the UI and thus the following methods were removed from the Interface class.

virtual float GetRendMaxPixelSize()=0;

virtual void SetRendMaxPixelSize(float s)=0;

There are new methods in Class RenderGlobalContext to retrieve the filter and the filter size. These are GetAAFilterKernel() and GetAAFilterSize().

API Modifications to Handle 3D Bump Maps

The following changes are needed to correct a problem with 3D bump maps when objects in the scene are scaled. This scaling results in a very noticeable inappropriate change in the bumping effect.

The problem is occurring when the bump perturbation vectors must be transformed from object space to camera space, so they are oriented correctly as the object rotates. If the object has been scaled, this transformation causes the perturbation vectors to be scale also, which amplifies the bump effect. What is needed is a way to rotate the perturbation vectors so they are correctly oriented in space, without scaling them. To do a new method has been added to Class ShadeContext.

ShadeContext::VectorFromNoScale(const Point3& p, RefFrame ifrom);

There is also a complimentary new method VectorToNoScale() added for completeness.

ShadeContext::VectorToNoScale(const Point3& p, RefFrame ito);

The coding ramifications of this are as follows:

All 3D Textures need to replace calls to ShadeContext::VectorFrom() with calls to ShadeContext::VectorFromNoScale().

Here's an example of the use of VectorFromNoScale() in an EvalNormalPerturb() function:

Point3 Marble::EvalNormalPerturb(ShadeContext& sc) {

 float del,d;

 Point3 p,dp;

 if (!sc.doMaps) return Point3(0,0,0);

 if (gbufID) sc.SetGBufferID(gbufID);

 xyzGen->GetXYZ(sc,p,dp);

 if (size==0.0f) size=.0001f;

 p *= FACT/size;

 

 d = MarbleFunc(p);

 del = 20.0f;

 Point3 np;

 

 Point3 M[3];

 xyzGen->GetBumpDP(sc,M);

np.x = (MarbleFunc(p+del*M[0]) - d)/del;

 np.y = (MarbleFunc(p+del*M[1]) - d)/del;

 np.z = (MarbleFunc(p+del*M[2]) - d)/del;

 

 np *= 100.0f;

 return sc.VectorFromNoScale(np,REF_OBJECT);

 }