Manual Parameter Translation
 
 
 

The constraints for manual parameter translation are similar to those of automatic parameter translation. The names and parameter structures no longer have to match, but the types must still match.

The parameters must be translated into the parameter block of the shader. This parameter block is accessed through imrShader::GerParametersParamBlock(). The structure of this parameter block matches that of the mental ray shader as declared in the .mi file. The types of parameters contained in this parameter block are as follows:

Parameter type in .mi declaration

Type of parameter in the parameter block of the imrShader

boolean

TYPE_BOOL

integer

TYPE_INT

scalar

TYPE_FLOAT by default, TYPE_WORLD if GUI attribute <"units" "world"> is specified

vector

TYPE_POINT3

transform

TYPE_MATRIX3

color

TYPE_FRGBA by default, TYPE_RGBA if GUI attribute "noAlpha" is specified

shader

TYPE_TEXMAP by default, TYPE_REFTARG if GUI attribute "referenceTarget" is specified

colortexture, scalartexture, vectortexture

TYPE_FILENAME by default (should be the filename of a texture), TYPE_TEXMAP if GUI attribute <"textureInfo" "max_texmap"> is specified

light

TYPE_INODE with super class (SClassID) of LIGHT_CLASS_ID

string

TYPE_STRING

data

TYPE_TEXMAP by default, TYPE_REFTARG if GUI attribute "referenceTarget" is specified

lightprofile

TYPE_STRING (cannot be used)

geometry

TYPE_INODE with sclassID restriction of GEOMOBJECT_CLASS_ID

material

TYPE_MTL

struct*

TYPE_PBLOCK2

array

Tab of the appropriate parameter (e.g. TYPE_BOOL_TAB for "array boolean")

When doing manual translation, make sure you lookup the parameters by name and not by parameter ID, since the parameter IDs are not necessarily in order. To get a parameter ID from a parameter name, you may use the following function:

bool GetParamIDByName(ParamID& paramID, const TCHAR* name, IParamBlock2* pBlock) {
    DbgAssert(pBlock != NULL);
    int count = pBlock->NumParams();
    for(int i = 0; i < count; ++i) {
        ParamID id = pBlock->IndextoID(i);
        ParamDef& paramDef = pBlock->GetParamDef(id);
        if(_tcsicmp(name, paramDef.int_name) == 0) {
             paramID = id;
             return true;
        }
    }
    DbgAssert(false);
    return false;
}

The parameter ID will be returned through the "paramID" reference parameter. The function will return false if no parameter was found with the given name.