Class RenderGlobalContext

3DS Max Plug-In SDK

Class RenderGlobalContext

See Also: Class ShadeContext, Class Renderer, Class RenderInstance, Class Texmap, Class Atmospheric, Class Matrix3, Class Point2, Class Point3, Class AColor, Class Color, Class IRenderElementMgr, Class IRenderElement.

class RenderGlobalContext : public BaseInterfaceServer

Description:

A pointer to an instance of this class is a data member of the ShadeContext (RenderGlobalContext *globContext;). This can be used by materials, texmaps, etc. to retireve information about the global rendering enviornment. This is information such as the renderer in use, the project type for rendering, the output device width and height, several matrices for transforming between camera and world coordinates, the environment map, the atmospheric effects, the current time, field rendering information, and motion blur information.

Note that raytracing (and all shading calculations in the default renderer) take place in camera space.

When a ray intersects on the face edge it can happen that no intersection is returned. One way to handle this situation is to perturb the ray minimally so it will point in a slightly different direction. This presumes that you are fairly sure that the no intersection is probably not what you’re looking for. IntersectRay() is linear in the number of faces so NUM_ATTEMPTS should be kept small.

for (perturb=0; perturb < NUM_ATTEMPTS; perturb++)

{

 Matrix3 ptb;

 float prop = ((float)rand()) / ((float) RAND_MAX); 

// gets random rotation of up to half a degree.

 float ang = PI*prop/360.0f;

 switch (perturb%3) {

  case 0: ptb = RotateXMatrix (ang); break;

 case 1: ptb = RotateYMatrix (ang); break;

 case 2: ptb = RotateZMatrix (ang); break;

 }

 ray.dir = ptb*ray.dir;

 // try IntersectRay() again, see if you get a hit.

}

Data Members:

public:

Renderer *renderer;

A pointer to the active renderer.

int projType;

Returns the type of projection used during rendering. One of the following values:

PROJ_PERSPECTIVE

PROJ_PARALLEL

int devWidth;

The width in pixels of the output device.

int devHeight;

The height in pixels of the output device.

float xscale;

The X scale factor for mapping from world space to screen space.

float yscale;

The Y scale factor for mapping from world space to screen space.

float xc;

The X center point used in mapping from world space to screen space.

float yc;

The Y center point used in mapping from world space to screen space.

BOOL antialias;

TRUE if antialiasing is enabled; otherwise FALSE.

Matrix3 camToWorld;

This matrix may be used to transform coordinates from camera space to world space.

Matrix3 worldToCam;

This matrix may be used to transform coordinates from world space to camera space.

float nearRange;

The near range setting of the camera.

float farRange;

The far range setting of the camera.

float devAspect;

The pixel aspect ratio of a device pixel. This is the height / width.

float frameDur;

This defines the duration of one frame in floating point units. This is used, for example, by video post rendering where the user can stretch time. A video post frame might be 1/2 a frame long for instance.

Texmap *envMap;

The environment map (which may be NULL).

Color globalLightLevel;

This parameter is available in release 3.0 and later only.

This is the global light level.

Atmospheric *atmos;

The atmosphere effects (which may be NULL).

ToneOperator* pToneOp;

This data member is available in release 4.0 and later only.

The tone operator, may be NULL

TimeValue time;

The current time.

BOOL wireMode;

This parameter is available in release 3.0 and later only.

TRUE if rendering in wire frame mode; otherwise FALSE.

float wire_thick;

This parameter is available in release 3.0 and later only.

The global wire thickness.

BOOL force2Side;

TRUE if force two-sided rendering enabled; otherwise FALSE.

BOOL inMtlEdit;

TRUE if the rendering is being done in the materials editor; otherwise FALSE.

BOOL fieldRender;

TRUE if field rendering is being done; otherwise FALSE.

BOOL first_field;

TRUE if this is the first field; FALSE if it's the second.

BOOL field_order;

Determines which field is first. 0 if the even first; 1 if odd first.

BOOL objMotBlur;

This is used for handling object motion blur in ray-trace maps and materials. TRUE if object motion blur is enabled; FALSE if it's disabled.

int nBlurFrames;

This is used for handling object motion blur in ray-trace maps and materials. The number of object motion blur time slices. See Class RenderInstance.

Methods:

Prototype:

IRenderElementMgr *GetRenderElementMgr();

Remarks:

This method is available in release 4.0 and later only.

Returns a pointer to the Render Element Manager. See Class IRenderElementMgr.

Prototype:

void SetRenderElementMgr(IRenderElementMgr *pIRenderElementMgr);

Remarks:

This method is available in release 4.0 and later only.

Sets the render element manager being used.

Parameters:

IRenderElementMgr *pIRenderElementMgr

Points to the render element manager to set.

Prototype:

int NRenderElements();

Remarks:

This method is available in release 4.0 and later only.

Returns the number of render elements.

Prototype:

IRenderElement* GetRenderElement(int n);

Remarks:

This method is available in release 4.0 and later only.

Returns a pointer to the specified render element (or NULL if not found).

Parameters:

int n

The zero based index of the render element.

Prototype:

Point2 MapToScreen(Point3 p);

Remarks:

Computes the screen space coordinates of the point passed in world coordinates. This is implemented as:

Parameters:

Point3 p

The point to map to screen space.

Prototype:

virtual FilterKernel* GetAAFilterKernel();

Remarks:

Returns a pointer to the current anti-aliasing filter from the renderer. See Class FilterKernel.

Prototype:

virtual float GetAAFilterSize();

Remarks:

Returns the filter size of the current anti-aliasing filter.

Prototype:

virtual int NumRenderInstances();

Remarks:

Returns the number of RenderInstances.

Prototype:

virtual RenderInstance* GetRenderInstance(int i);

Remarks:

Returns a pointer to the 'i-th' RenderInstance.

Parameters:

int i

Specifies which RenderInstance to return (0 through NumRenderInstances()-1).

Prototype:

virtual AColor EvalGlobalEnvironMap(ShadeContext &sc, Ray &r, BOOL applyAtmos);

Remarks:

This method evaluates the global environment map using the specified ray as a point of view, and returns the resulting color.

Parameters:

ShadeContext &sc

The shade context.

Ray &r

Defines the direction of view of the enviornment. See Class Ray.

BOOL applyAtmos

TRUE if atmospheric effects should be considered; otherwise FALSE.

Default Implementation:

{ return AColor(0.0f,0.0f,0.0f,1.0f); }

Prototype:

virtual void IntersectRay(RenderInstance *inst, Ray& ray, ISect &isct, ISectList &xpList, BOOL findExit);

Remarks:

This method takes the specified ray and intersects it with the single RenderInstance inst.

Parameters:

RenderInstance *inst

The render instance to intersect. The Mesh may be retrieved via Mesh& m = *(inst->mesh);

Ray& ray

Defines the direction to check. This is the point to look from, and a normal vector specifying the direction to look. See Class Ray.

ISect &isct

The information about the first opaque object hit by the ray is returned here. See Structure ISect.

ISectList &xpList

The list of transparent objects that are intersected on the way to the opaque one are returned here. See Class ISectList.

BOOL findExit

TRUE to compute the exit point; FALSE to not compute it. Once a ray has been instersected with a transparent object and you want to find out where the refracted ray leaves the object, this parameter may be set to TRUE. This allows the ray to look at the inside faces of the object and compute the intersection point at exit.

Prototype:

virtual BOOL IntersectWorld(Ray &ray, int skipID, ISect &hit, ISectList &xplist, int blurFrame = NO_MOTBLUR);

Remarks:

This method takes the specified ray and intersects it with the entire 3ds max scene.

Parameters:

Ray &ray

Defines the direction to check. This is the point to look from, and a normal vector specifying the direction to look. See Class Ray.

int skipID

This specifies an ID (from RenderInstance::nodeID) that is skipped in the intersection computations. This is used to prevent self intersection.

ISect &hit

The information about the first opaque object hit by the ray is returned here. See Structure ISect.

ISectList &xplist

The list of transparent objects that are intersected on the way to the opaque one are returned here. See Class ISectList.

int blurFrame = NO_MOTBLUR

NO_MOTBLUR is used for non-motion blurred objects. If this is not equal to NO_MOTBLUR, it should be in the range 0 to nBlurFrames-1. In that case, this method will only consider blur objects corresponding to that blur sub-frame.

When object motion blur is turned on, for each object, several objects are generated. Each of these objects is given a number. This corresponds to the value RenderInstance::objMotBlurFrame.

This method will always intersect objects that aren't motion blurred. However, if this is set to a number other than NO_MOTBLUR, then when it comes to a motion blurred object, it will only look at the sub-object corresponding to the specified slice in time.

This may be used to do a kind of dither where for each of the sub-samples, this number is randomly selected. In this way the different motion blur slices will basically blur together and give a motion blurred ray trace result.

Prototype:

virtual ViewParams *GetViewParams();

Remarks:

This method is available in release 3.0 and later only.

Returns a pointer to a class which describes the properties of a view being rendered.. See Class ViewParams.

Prototype:

virtual INT_PTR Execute(int cmd, ULONG arg1=0, ULONG arg2=0, ULONG arg3=0);

Remarks:

This method is available in release 2.0 and later only.

This is a general purpose function that allows the API to be extended in the future. The 3ds max development team can assign new cmd numbers and continue to add functionality to this class without having to 'break' the API.

Parameters:

int cmd

The index of the command to execute.

ULONG arg1=0

Optional argument 1. See the documentation where the cmd option is discussed for more details on these parameters.

ULONG arg2=0

Optional argument 2.

ULONG arg3=0

Optional argument 3.

Return Value:

An integer return value. See the documentation where the cmd option is discussed for more details on the meaning of this value.

Default Implementation:

{ return 0; }

Prototype:

virtual FILE* DebugFile();

Remarks:

This method is used internally.

Default Implementation:

{ return NULL; };