Keywords: main

Next: 3.3 Shader Type Overview Up: 3. Using and Writing Previous: 3.1 Dynamic Linking of

# 3.2 Coordinate Systems

Internal space is the coordinate system mental ray uses to present intersection points and other points and vectors to shaders. All points and vectors in the state except bump basis vectors (which are in object space) are presented in internal space, namely, `org`, `dir`, `point`, `normal`, `normal_geom`, `motion` and `derivs`. The actual meaning of internal space is left undefined, it varies between different versions of mental ray and depends on the `space` statement in the `options` block in the .mi file. A shader must not assume that internal space is identical to world space, even though this is true in most scenes.

World space is the coordinate system in which modeling and animation takes place.

Object space is a coordinate system relative to the object's origin. The modeler that created the scene defines the object's origin. Most translators use the center of the bounding box of the object as the object origin.

Camera space is a coordinate system in which the camera is at the coordinate origin (0, 0, 0) with an up vector of (0, 1, 0)and looking down the negative Z axis.

In addition to these 3D coordinate spaces, raster space is a two-dimensional pixel location on the screen bounded by (0, 0) in the lower left corner of the image, and the rendered image resolution. The center of the pixel in the lower left corner of raster space has the coordinates (0.5, 0.5).

Screen space is defined such that (- 1, - 1/a) is in the lower left corner of the screen and (1, 1/a) is in the the upper right, where a is the aspect ratio of the screen (the relation between its width and height).

Most shaders never need to transform between spaces. Texture shaders frequently need to operate in object space; for example, in order to apply bump basis vectors to state- >normal, the normal must be transformed to object space before the bump basis vectors are applied, and back to internal space before the result is passed to any mental ray function such as mi_trace_reflection. mental ray offers 18 functions to convert points, vectors and normals between coordinate spaces:

function | operation
mi_point_to_world(s,pr,p) | internal point to world space
mi_point_to_camera(s,pr,p) | internal point to camera space
mi_point_to_object(s,pr,p) | internal point to object space
mi_point_from_world(s,pr,p) | world point to internal space
mi_point_from_camera(s,pr,p) | camera point to internal space
mi_point_from_object(s,pr,p) | object point to internal space
mi_vector_to_world(s,vr,v) | internal vector to world space
mi_vector_to_camera(s,vr,v) | internal vector to camera space
mi_vector_to_object(s,vr,v) | internal vector to object space
mi_vector_from_world(s,vr,v) | world vector to internal space
mi_vector_from_camera(s,vr,v) | camera vector to internal space
mi_vector_from_object(s,vr,v) | object vector to internal space
mi_normal_to_world(s,vr,v) | internal normal to world space
mi_normal_to_camera(s,vr,v) | internal normal to camera space
mi_normal_to_object(s,vr,v) | internal normal to object space
mi_normal_from_world(s,vr,v) | world normal to internal space
mi_normal_from_camera(s,vr,v) | camera normal to internal space
mi_normal_from_object(s,vr,v) | object normal to internal space

Point and vector transformations are similar, except that the vector versions ignore the translation part of the matrix. Normal transformations are similar to vector transformations, except that the transpose of the inverse transformation matrix is used. In this way it is ensured that if a vector and a normal are orthogonal in one coordinate system they remain orthogonal after they have been transformed to a different coordinate system. This holds for arbitrary, not necessarily orthogonal transformations.

The length of vectors is preserved only if the transformation matrix does not scale. The mi_point_transform and mi_vector_transform functions are also available to transform points and vectors between arbitrary coordinate systems given by a transformation matrix. mi_vector_transform_T transforms with the transpose of the matrix and can be used for the transformation of normals.

Next: 3.3 Shader Type Overview Up: 3. Using and Writing Previous: 3.1 Dynamic Linking of