Public Member Functions | Public Attributes | Protected Attributes

RenderGlobalContext Class Reference

Search for all occurrences

Detailed Description

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.

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 retrieve information about the global rendering environment. 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:
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.

#include <imtl.h>

Inheritance diagram for RenderGlobalContext:
Inheritance graph
[legend]

List of all members.

Public Member Functions

  RenderGlobalContext ()
IRenderElementMgr GetRenderElementMgr ()
void  SetRenderElementMgr (IRenderElementMgr *pIRenderElementMgr)
int  NRenderElements ()
IRenderElement GetRenderElement (int n)
Point2  MapToScreen (Point3 p)
virtual FilterKernel GetAAFilterKernel ()
virtual float  GetAAFilterSize ()
virtual int  NumRenderInstances ()
virtual RenderInstance GetRenderInstance (int i)
virtual AColor  EvalGlobalEnvironMap (ShadeContext &sc, Ray &r, BOOL applyAtmos)
virtual void  IntersectRay (RenderInstance *inst, Ray &ray, ISect &isct, ISectList &xpList, BOOL findExit)
virtual BOOL  IntersectWorld (Ray &ray, int skipID, ISect &hit, ISectList &xplist, int blurFrame=NO_MOTBLUR)
virtual ViewParams GetViewParams ()
virtual FILE *  DebugFile ()
virtual INT_PTR  Execute (int cmd, ULONG_PTR arg1=0, ULONG_PTR arg2=0, ULONG_PTR arg3=0)

Public Attributes

Renderer renderer
int  projType
int  devWidth
int  devHeight
float  xscale
float  yscale
float  xc
float  yc
BOOL  antialias
Matrix3  camToWorld
Matrix3  worldToCam
float  nearRange
float  farRange
float  devAspect
float  frameDur
Texmap envMap
Color  globalLightLevel
Atmospheric atmos
ToneOperator pToneOp
TimeValue  time
BOOL  wireMode
float  wire_thick
BOOL  force2Side
BOOL  inMtlEdit
BOOL  fieldRender
BOOL  first_field
BOOL  field_order
BOOL  objMotBlur
int  nBlurFrames

Protected Attributes

IRenderElementMgr mpIRenderElementMgr

Constructor & Destructor Documentation

RenderGlobalContext ( ) [inline]
: pToneOp(NULL), mpIRenderElementMgr(NULL) { }

Member Function Documentation

IRenderElementMgr* GetRenderElementMgr ( ) [inline]
Remarks:
Returns a pointer to the Render Element Manager. See Class IRenderElementMgr.
{ return mpIRenderElementMgr; }
void SetRenderElementMgr ( IRenderElementMgr pIRenderElementMgr ) [inline]
Remarks:
Sets the render element manager being used.
Parameters:
IRenderElementMgr *pIRenderElementMgr

Points to the render element manager to set.
{ mpIRenderElementMgr = pIRenderElementMgr; }
int NRenderElements ( ) [inline]
Remarks:
Returns the number of render elements.
IRenderElement* GetRenderElement ( int  n ) [inline]
Remarks:
Returns a pointer to the specified render element (or NULL if not found).
Parameters:
int n

The zero based index of the render element.
Point2 MapToScreen ( Point3  p ) [inline]
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.
     {  
            if (projType==1)
            {
                 return Point2(  xc + xscale*p.x , yc + yscale*p.y);
            }
            else
            {
                 if (p.z==0.0f)
                        p.z = .000001f;
                 return Point2( xc + xscale*p.x/p.z,  yc + yscale*p.y/p.z);
            }
     }
virtual FilterKernel* GetAAFilterKernel ( ) [inline, virtual]
Remarks:
Returns a pointer to the current anti-aliasing filter from the renderer. See Class FilterKernel.
{ return NULL; }
virtual float GetAAFilterSize ( ) [inline, virtual]
Remarks:
Returns the filter size of the current anti-aliasing filter.
{ return 0.0f; }
virtual int NumRenderInstances ( ) [inline, virtual]
Remarks:
Returns the number of RenderInstances.
{ return 0; }
virtual RenderInstance* GetRenderInstance ( int  i ) [inline, virtual]
Remarks:
Returns a pointer to the 'i-th' RenderInstance.
Parameters:
int i

Specifies which RenderInstance to return (0 through NumRenderInstances()-1).
{ return NULL; }
virtual AColor EvalGlobalEnvironMap ( ShadeContext sc,
Ray r,
BOOL  applyAtmos 
) [inline, virtual]
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 environment. 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); }
     { 
            return AColor(0.0f,0.0f,0.0f,1.0f); 
     }
virtual void IntersectRay ( RenderInstance inst,
Ray ray,
ISect isct,
ISectList xpList,
BOOL  findExit 
) [inline, virtual]
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 intersected 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.
{}
virtual BOOL IntersectWorld ( Ray ray,
int  skipID,
ISect hit,
ISectList xplist,
int  blurFrame = NO_MOTBLUR 
) [inline, virtual]
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.
{ return FALSE; }
virtual ViewParams* GetViewParams ( ) [inline, virtual]
Remarks:
Returns a pointer to a class which describes the properties of a view being rendered.. See Class ViewParams.
{ return NULL; } 
virtual FILE* DebugFile ( ) [inline, virtual]
Remarks:
This method is used internally.
Default Implementation:
{ return NULL; };
{ return NULL; }
virtual INT_PTR Execute ( int  cmd,
ULONG_PTR  arg1 = 0,
ULONG_PTR  arg2 = 0,
ULONG_PTR  arg3 = 0 
) [inline, virtual]
Remarks:
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.
Returns:
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; }
{ return 0; } 

Member Data Documentation

float xscale
float yscale
float xc
float yc
float nearRange
float farRange
float devAspect
float frameDur
TimeValue time
BOOL wireMode

RenderGlobalContext RenderGlobalContext RenderGlobalContext RenderGlobalContext RenderGlobalContext RenderGlobalContext RenderGlobalContext RenderGlobalContext RenderGlobalContext RenderGlobalContext
RenderGlobalContext RenderGlobalContext RenderGlobalContext RenderGlobalContext RenderGlobalContext RenderGlobalContext RenderGlobalContext RenderGlobalContext RenderGlobalContext RenderGlobalContext