Queries with mi_query

mi_query
miBoolean mi_query(
    miQ_type    query,
    miState *   state,
    miTag       tag,
    void *      result,
    ...)

Return various pieces of information about the current state of mental ray. query is the request code specifying what piece of information to query; state is the shader state, tag is the tag of the DB element to query, if any, and result is a pointer to the variable to store the results in. Some queries do not require a tag; in this case miNULLTAG must be passed as tag. Some queries require extra arguments in addition to the four standard arguments. mi_query returns miFALSE if the queried value is not available or an unknown type code is used. The following query codes are available:

query code st. tag result, ... purpose
miQ_DATA_DECL miTag user data declaration if any, or 0
miQ_DATA_LABEL miUint translator-defined user data label
miQ_DATA_NEEDSWAP miBoolean requires byte-swapping by shader
miQ_DATA_NEXT miTag next user data block in chain, or 0
miQ_DATA_PARAM char * user data contents
miQ_DATA_PARAM_SIZE int size of user data block in bytes
miQ_DATE char * mental ray compilation date
miQ_DECL_LOCK 1

miLock * shared by all shader instances
miQ_DECL_NAME 1

char * shader name
miQ_DECL_PARAM 1

char * ascii-encoded parameter declaration
miQ_DECL_RESULT_SIZE 1

int result size, 4 unless struct
miQ_DECL_TYPE 1

int miTYPE_* result type
miQ_DECL_VERSION 1

int shader declaration version
miQ_FINALGATHER_STATE int 0=not a finalgather ray (grand)child,
1=finalgather ray (grand)child in tile rendering,
2=finalgather ray (grand)child in FG precompute
miQ_SAMPLE_MOVING int Not zero if mental ray has detected geometry motion for the current raster sample.
miQ_FUNC_CALLTYPE int one of miSHADER_*, as specified by the calling mi_call_shader
miQ_FUNC_DECL 1

miTag tag of shader declaration
miQ_FUNC_INDIRECT 1

miTag take params from this shader
miQ_FUNC_LOCK 1

miLock * local shader instance lock
miQ_FUNC_NEXT 1

miTag next shader in shader list
miQ_FUNC_PARAM 1

void * shader parameters
miQ_FUNC_PARAM_SIZE 1

int size of shader parameters in bytes
miQ_FUNC_PARAM_VALUE 1

type, char *, miParam_type value of shader input parameter with given name and type
miQ_FUNC_RESULT_SIZE 1

int shader result size in bytes
miQ_FUNC_TAG miTag tag of the currently running shader
miQ_FUNC_TLS_GET void * retrieve thread-local shader data pointer
miQ_FUNC_TLS_GETALL 2 void *, int * array of all valid thread-local shader data pointers, return array size in extra parameter
miQ_FUNC_TLS_SET void * set thread-local shader data pointer (see thread-local storage)
miQ_FUNC_TYPE 1

int 0=C/C++, 1=phen., 2=output file
miQ_FUNC_USERPTR 1

void * user pointer in shader instance
miQ_FUNC_IS_ROOT miBoolean shader is root of material/light
miQ_GEO_DATA miTag user data block of current object
miQ_GEO_HAS_DERIVS miBoolean state has valid derivatives
miQ_GEO_HAS_DERIVS2 miBoolean state has valid second derivatives
miQ_GEO_LABEL miUint translator-defined triangle label
miQ_GLOBAL_LIGHTS miTag * array with global light tags
miQ_GROUP_DATA miTag user data block
miQ_GROUP_KID miTag nth child (n is fifth argument)
miQ_GROUP_LABEL miUint translator-defined group label
miQ_GROUP_MERGE_GROUP miBoolean miTRUE if connected
miQ_GROUP_NKIDS int number of child instances
miQ_HAIR_NUM_TEXTURES int number of texture scalars per hair
miQ_HAIR_NUM_USERS int number of user scalars per hair
miQ_HAIR_USERS miScalar * array of user scalars per hair
miQ_HAIR_RADIUS miScalar hair radius at the the current hit point
miQ_IMAGE_BITS int number of bits per component (8,16,32)
miQ_IMAGE_COLORCLIP miBoolean color frame buffer color clipping mode
miQ_IMAGE_COMP int number of components (1,2,3,4)
miQ_IMAGE_DESATURATE miBoolean color frame buffer desaturation mode
miQ_IMAGE_DITHER miBoolean color frame buffer dithering mode
miQ_IMAGE_FILTER miBoolean image allows filtering
miQ_IMAGE_GAMMA double color frame buffer gamma factor
miQ_IMAGE_HEIGHT int height of image in pixels
miQ_IMAGE_NOPREMULT miBoolean color frame buffer premultiplication mode
miQ_IMAGE_WIDTH int width of image in pixels
miQ_INST_AREA miScalar light instances only: area of area light
miQ_INST_CAUSTIC miUint bitmap:
bit 1=enable casting,
bit 2=enable receiving,
bit 3=disable casting,
bit 4=disable receiving
miQ_INST_DATA miTag user data block
miQ_INST_DECL miTag inherited parameter declaration
miQ_INST_FUNCTION miTag optional procedural transformation
miQ_INST_GLOBAL_TO_LOCAL miMatrix * instance transformation
miQ_INST_GLOBILLUM miUint bitmap:
bit 1=enable casting,
bit 2=enable receiving,
bit 3=disable casting,
bit 4=disable receiving
miQ_INST_HIDE miBoolean instance is inactive
miQ_INST_IDENTITY miBoolean miTRUE if identity transformation
miQ_INST_ITEM miTag instanced scene element
miQ_INST_LABEL miUint translator-defined instance label
miQ_INST_LOCAL_TO_GLOBAL miMatrix * inverse instance transformation
miQ_INST_MATERIAL miTag inherited material
miQ_INST_PARAM void * inherited parameters
miQ_INST_PARAM_SIZE int inherited parameter size
miQ_INST_PARENT miTag leaf instance parent, miNULLTAG otherwise
miQ_INST_PLACEHOLDER_ITEM miTag content of placeholder instances
miQ_INST_SHADOW miUint invisible to shadow rays
miQ_INST_TRACE miUint visible to secondary rays
miQ_INST_VISIBLE miUint visible to primary rays
miQ_LIGHT_AREA int area light type:
0=none, 1=rectangle, 2=disc, 3=sphere
miQ_LIGHT_AREA_C_AXIS miVector axis of cylinder area light
miQ_LIGHT_AREA_C_RADIUS miScalar radius of cylinder area light
miQ_LIGHT_AREA_R_EDGE_U miVector U size of rectangular area light
miQ_LIGHT_AREA_R_EDGE_V miVector V size of rectangular area light
miQ_LIGHT_AREA_D_NORMAL miVector normal vector of disc area light
miQ_LIGHT_AREA_D_RADIUS miScalar radius of disc area light
miQ_LIGHT_AREA_S_RADIUS miScalar radius of spherical area light
miQ_LIGHT_AREA_SAMPLES_U int number of samples in U direction
miQ_LIGHT_AREA_SAMPLES_V int number of samples in V direction
miQ_LIGHT_CAUSTIC_PHOTONS int number of caustic photons to store
miQ_LIGHT_CAUSTIC_PHOTONS_EMIT int number of caustic photons to emit
miQ_LIGHT_DATA miTag user data block
miQ_LIGHT_DIRECTION miVector light direction
miQ_LIGHT_EMITTER miVector tag of light photon emitter shader
miQ_LIGHT_ENERGY miTag energy for caustics and globillum
miQ_LIGHT_EXPONENT miScalar distance falloff, n in 1 / r^n
miQ_LIGHT_GLOBAL_PHOTONS miColor number of globillum photons to store
miQ_LIGHT_GLOBAL_PHOTONS_EMIT miColor number of globillum photons to emit
miQ_LIGHT_LABEL int light label
miQ_LIGHT_NORMAL miVector normal vector at light surface in world space
miQ_LIGHT_ORIGIN miVector light position
miQ_LIGHT_SHADER miTag tag of light shader
miQ_LIGHT_SPREAD miScalar outer cone angle of spot light
miQ_LIGHT_TANGENT_SPACE miVector[3] normal, tangent, bi-tangent (in that order) at light surface in world space
miQ_LIGHT_TYPE int light source type:
0=point, 1=directional, 2=spot
miQ_LIGHT_USE_SHADOWMAP miBoolean light has a shadow map
miQ_LIGHTPROFILE_COSTHETA_MAX miScalar largest possible value of the cosine of the profile vertical angle
miQ_LIGHTPROFILE_COSTHETA_MIN miScalar smallest value of the cosine of the profile vertical angle.
miQ_LIGHTPROFILE_INTENSITY_MAX miScalar largest intensity value of the profile
miQ_LIGHTPROFILE_PHI_MAX miScalar horizontal angle where the light profile ends
miQ_LIGHTPROFILE_PHI_MIN miScalar horizontal angle where the light profile starts
miQ_LIGHTPROFILE_PHI_RES int number of interpolation points in the horizontal direction
miQ_LIGHTPROFILE_THETA_RES int number of interpolation points in the vertical direction
miQ_MTL_CONTOUR miTag contour shader
miQ_MTL_DISPLACE miTag displacement shader
miQ_MTL_ENVIRONMENT miTag environment shader
miQ_MTL_OPAQUE miBoolean material is opaque to shadow rays
miQ_MTL_PHOTON miTag photon shader
miQ_MTL_PHOTONVOL miTag photon volume shader
miQ_MTL_SHADER miTag material shader
miQ_MTL_SHADOW miTag shadow shader
miQ_MTL_VOLUME miTag volume shader
miQ_NUM_BUMPS int * number of bumps in state x, y bump lists
miQ_NUM_GLOBAL_LIGHTS int number of global lights
miQ_NUM_TEXTURES int * number of textures in state->tex_list
miQ_OBJ_CAUSTIC miUint 0=none, 1=casts, 2=receives, 3=both
miQ_OBJ_DATA miTag user data block
miQ_OBJ_GLOBILLUM miUint 0=none, 1=casts, 2=receives, 3=both
miQ_OBJ_LABEL miUint translator-defined object label
miQ_OBJ_SHADOW miBoolean invisible to shadow rays
miQ_OBJ_TRACE miBoolean visible to secondary rays
miQ_OBJ_TYPE int object type:
0=polygons, 1=surfaces, 2=boxes, 3=spacecurves, 4=subdiv, 6=placeholder, 7=hair, 9=particles
miQ_OBJ_VIEW_DEPENDENT miBoolean contains view-dependent surfaces
miQ_OBJ_VISIBLE miBoolean visible to primary rays
miQ_PIXEL_SAMPLE miScalar[2] set up QMC sequences for sampling, and return a jitter value for lightmap shaders. See query pixel sample example.
miQ_PRI_ASSEMBLY_INST_TAG miTag for geometry from assemblies, leaf instance tag of the hit primitive
miQ_PRI_BBOX_MAX miVector object-space bounding box of intersected primitive
miQ_PRI_BBOX_MIN miVector object-space bounding box of intersected primitive
miQ_PRI_DATA miPri_data the per-primitive data of the current primitive in the state
miQ_PRI_INDEX miUint current primitive index
miQ_PRI_NUM_MOTIONS miUint number of motion vectors per vertex
miQ_PRI_NUM_VERTICES miUint number of vertices of primitive
miQ_PRI_VERTICES_POINTS miVector * vertex positions of primitive
miQ_PRI_VERTICES_NORMALS miVector * vertex normals of primitive
miQ_PRI_VERTICES_MOTION 2 miVector *, int vertex motion vectors of primitive, given motion step
miQ_PRI_VERTICES_TEX 2 miVector *, int vertex texture vectors of primitive, given texture space
miQ_PRI_VERTICES_USER 2 miVector *, int vertex user vectors of primitive, given user space
miQ_PRI_VERTICES_BUMPS_U miVector * vertex bump basis U vectors of primitive
miQ_PRI_VERTICES_BUMPS_V miVector * vertex bump basis V vectors of primitive
miQ_PRI_VERTICES_DERIVS_U miVector * vertex first order derivative vectors of primitive
miQ_PRI_VERTICES_DERIVS_V miVector * vertex first order derivative U vectors of primitive
miQ_PRI_VERTICES_DERIVS_UU miVector * vertex second order derivative UU vectors of primitive
miQ_PRI_VERTICES_DERIVS_VV miVector * vertex second order derivative VV vectors of primitive
miQ_PRI_VERTICES_DERIVS_UV
miQ_PRI_VERTICES_DERIVS_VU
miVector * vertex second order derivative UV vectors of primitive
miQ_PRI_PARTICLE_INDEX miUint current particle index
miQ_PRI_PARTICLE_TYPE int current particle type:
0=spheres, 1=tubes
miQ_PRI_PARTICLE_UV miScalar[2] current particle intersection coordinates
miQ_RAY_INTERFACE MI::RAY:Interface * pointer to C++ interface class
miQ_SCENE_BBOX_ALL miVector[2] world-space bounding box of all geometry
miQ_SCENE_BBOX_CAUSTIC_G miVector[2] bounding box of all caustic-casting geometry
miQ_SCENE_BBOX_CAUSTIC_R miVector[2] bounding box of all caustic-receiving geometry
miQ_SCENE_BBOX_GLOBILLUM_G miVector[2] bounding box of all globillum-casting geometry
miQ_SCENE_BBOX_GLOBILLUM_R miVector[2] bounding box of all globillum-receiving geometry
miQ_SCENE_BBOX_SHADOW miVector[2] bounding box of all shadow-casting geometry
miQ_SCENE_ROOT_GROUP miTag the root group of the scene from the render statement; useful for custom scene traversals
miQ_STAGE miStage current rendering stage
miQ_TEXTURE_DIM miUint dimension of nth texture space of intersected primitive (n is fifth argument)
miQ_TILE_PIXELS int[4] lower left and upper right tile pixel coord
miQ_TILE_SAMPLES int[4] same but including filter source margin
miQ_TRANS_CAMERA_TO_INTERNAL miMatrix * camera to internal space transformation
miQ_TRANS_CAMERA_TO_WORLD miMatrix * camera to world space transformation
miQ_TRANS_INTERNAL_TO_CAMERA miMatrix * internal to camera space transformation
miQ_TRANS_INTERNAL_TO_OBJECT miMatrix * internal to object space transformation
miQ_TRANS_INTERNAL_TO_WORLD miMatrix * internal to world space transformation
miQ_TRANS_OBJECT_TO_INTERNAL miMatrix * object to internal space transformation
miQ_TRANS_OBJECT_TO_WORLD miMatrix * object to world space transformation
miQ_TRANS_WORLD_TO_CAMERA miMatrix * world to camera space transformation
miQ_TRANS_WORLD_TO_INTERNAL miMatrix * world to internal space transformation
miQ_TRANS_WORLD_TO_OBJECT miMatrix * internal to world space transformation
miQ_VERSION char * mental ray version string

1 This query can be performed in two ways: for an arbitrary tag, or with the current state. In the latter case mi_query will take the current shader from the state (state→shader) to fulfill the query. This is slightly faster than passing a tag.

2 This query uses additional parameters to pass or return extra information.

The  ◊  symbol in the state column indicates that the state is not used. The  ◊  symbol in the tag column means that miNULLTAG must be passed.

The result type in the table indicates the type of the variable that mi_query accepts a pointer to. For example, to obtain an integer result from mi_query the table will list an int, but a pointer to an integer must be passed as the fourth argument (int *). For mi_query, "function" is synonymous with "shader".

Note The return type of miMatrix * means that the address of a pointer must be passed, not the address of a matrix. This reduces the number of bytes that mi_query has to copy from 64 (sixteen floats) to only four (or eight, on some CPU architectures).

miQ_FUNC_PARAM_VALUE
This query can be used to retrieve the value of a shader input parameter that is not connected. The result should point to a variable of sufficient size to hold a value of the specified parameter type. Here is an example which retrieves an "intensity" parameter value of a shader:
miScalar    intensity = 0.0;
if (mi_query(miQ_FUNC_PARAM_VALUE, 0, tag,
             &intensity, "intensity", miTYPE_SCALAR) == miTRUE) {
    ... /* use valid intensity value */
    }
The query will fail by returning miFALSE under the following conditions:
miQ_INST_VISIBLE
miQ_INST_SHADOW
miQ_INST_TRACE
miQ_INST_CAUSTIC
miQ_INST_GLOBILLUM
The result of these queries depend on whether a scene DAG or leaf instance tag is passed. A scene DAG instance contains the flags specified by the scene description language when the instance was created. A leaf instance contains the effective instance flags for rendering, that is, with instance inheritance and object flags taken into account.
Note For a scene DAG instance, the visibility etc. flags should be interpreted as: unset (0), off (1), on (2). For a leaf instance, the flags should be interpreted as: off (0), on (1). See also the description of the instance data structure.
The miQ_INST_ modes should be used instead of the miQ_OBJ_ modes because they return the same modes that mental ray uses when rendering.
miQ_LIGHT_ORIGIN
miQ_LIGHT_DIRECTION
The result vectors of these queries are defined in internal space if the light instance tag is passed, otherwise the vectors are defined in local space.
miQ_TILE_PIXELS
miQ_TILE_SAMPLES
These codes retrieve the location and size of the currently rendered image tile. The returned values are in the order xlow xhigh ylow yhigh. The sampled area may be larger than the tile due to filtering and jittering. These codes may be used to detect if a shader is called in the finalgather pre-computing stage: for finalgather pre-computing the return value is miFALSE since no tile exist.
miQ_SAMPLE_MOVING
This mode can be used by an environment shader to detect if taking several samples of a moving environment texture at different shutter times would be advantageous. If the queried value is not zero, mental ray does such oversampling automatically.

miQ_NUM_TEXTURES
miQ_GEO_LABEL
These query codes may only be used if state→pri has not been modified by the shader or calling shader. Ray-marching volume shaders sometimes clear this state variable. The miQ_GEO_LABEL query also returns miFALSE if the object is not marked tagged and no polygon/surface labels exist.
miQ_PRI_ASSEMBLY_INST_TAG
For a valid intersection state, the assembly leaf instance for the hit primitive is returned. If the geometry does not belong to an assembly, the miNULLTAG is returned. This query mode may be used by shaders to implement custom attribute inheritance from the main scene file.
miQ_PRI_DATA
This query mode returns an miPri_data structure which is defined as follows:
typedef struct miPri_data {
    miUint          info_size;      /* size of info */
    const miUint    *info;          /* info: data layout */
    miUint          data_size;      /* size of triangle data */
    const miUint    *data;          /* primitive (triangle) data */
} miPri_data;
All fields in this structure are specific to the current intersected object. The field info_size specifies the size of the per-face userdata information block for the current intersection, in multiples of 32 bit. The address of this block is given in info if info_size is not zero. The per-face data of the hit primitive is returned in data, the length of the data block in multiples of 32 bit is given in data_size. Per face data can be present even if the information block is not specified. The caller must pass a pointer to such a structure which is then filled out by mi_query.
miQ_PRI_NUM_VERTICES
miQ_PRI_VERTICES_POINTS
miQ_PRI_VERTICES_NORMALS
miQ_PRI_VERTICES_MOTION
miQ_PRI_VERTICES_TEX
miQ_PRI_VERTICES_USER
miQ_PRI_VERTICES_BUMPS_*
miQ_PRI_VERTICES_DERIVS_*
These query modes return per-vertex data of the current primitive, as delivered with the source geometry, or computed by mental ray during approximation and tessellation. It is the callers responsibility to pass sufficiently large memory which will be filled by the function. The query code miQ_PRI_NUM_VERTICES allows to determine how many vertices the current primitive has. For a tessellated surface, this number will be 3 for the vertices of the currently rendered triangle. Other primitives like hair may return an arbitrary number of values. Here is an example how to retrieve the normals and the texture vectors of the second texture space for a triangle :
miUint  num = 0;
/* we like to deal with triangles only, like in mi_tri_vectors() */
if (mi_query(miQ_PRI_NUM_VERTICES, state, 0, &num) && num == 3) {
    miVector    n[3], t[3];
    miUint      tex_space = 2;

    if (mi_query(miQ_PRI_VERTICES_NORMALS, state, 0, &n)
    &&  mi_query(miQ_PRI_VERTICES_TEX, state, 0, &t, tex_space) {

        /* use the values */
    }
}
This functionality is the recommended replacement for the function mi_tri_vectors.
miQ_PRI_PARTICLE_INDEX
miQ_PRI_PARTICLE_TYPE
miQ_PRI_PARTICLE_UV
These query modes return data of the currently hit particle of a particle object. The function call returns miFALSE if no particle was hit. The intersection coordinates returned for the particles shapes are as follows:
Spheres
the first value U is the azimuth angle in the range [0,1] around the Z axis, and the second value V is the elevation angle in the range [-1,1] from the XZ plane (in object space).
Tubes
the first value U is the azimuth in the range [0,1] around the tube axis (in object space), and the second value V is a number in the range [0,1] representing the position of the intersection point along the tube axis relative to the base, with 0.0 at the base and 1.0 at the tip.

Copyright © 1986, 2015 NVIDIA ARC GmbH. All rights reserved.