RenderGlobalContext Class Reference

#include <RenderGlobalContext.h>

Class 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.
+ Inheritance diagram for RenderGlobalContext:

Public Member Functions

 RenderGlobalContext ()
 
IRenderElementMgrGetRenderElementMgr ()
 
void SetRenderElementMgr (IRenderElementMgr *pIRenderElementMgr)
 
int NRenderElements ()
 
IRenderElementGetRenderElement (int n)
 
Point2 MapToScreen (Point3 p)
 
virtual FilterKernelGetAAFilterKernel ()
 
virtual float GetAAFilterSize ()
 
virtual int NumRenderInstances ()
 
virtual RenderInstanceGetRenderInstance (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 ViewParamsGetViewParams ()
 
virtual FILE * DebugFile ()
 
virtual INT_PTR Execute (int cmd, ULONG_PTR arg1=0, ULONG_PTR arg2=0, ULONG_PTR arg3=0)
 
- Public Member Functions inherited from BaseInterfaceServer
virtual UtilExport BaseInterfaceGetInterface (Interface_ID id)
 
virtual UtilExport int NumInterfaces () const
 
virtual UtilExport BaseInterfaceGetInterfaceAt (int i) const
 
virtual UtilExport ~BaseInterfaceServer ()
 
- Public Member Functions inherited from InterfaceServer
virtual UtilExport ~InterfaceServer ()
 Destructor. More...
 

Public Attributes

Rendererrenderer
 
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
 
TexmapenvMap
 
Color globalLightLevel
 
Atmosphericatmos
 
ToneOperatorpToneOp
 
TimeValue time
 
BOOL wireMode
 
float wire_thick
 
BOOL force2Side
 
BOOL inMtlEdit
 
BOOL fieldRender
 
BOOL first_field
 
BOOL field_order
 
BOOL objMotBlur
 
int nBlurFrames
 
bool simplifyAreaLights
 

Protected Attributes

IRenderElementMgrmpIRenderElementMgr
 
- Protected Attributes inherited from BaseInterfaceServer
Tab< BaseInterface * > interfaces
 

Additional Inherited Members

- Static Public Member Functions inherited from MaxHeapOperators
static UtilExport voidoperator new (size_t size)
 Standard new operator used to allocate objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e)
 Standard new operator used to allocate objects if there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate objects that takes the type of memory, filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate arrays of objects. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport void operator delete (void *ptr)
 Standard delete operator used to deallocate an object If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an object If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an object that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, void *placement_ptr)
 Placement new operator. More...
 
static UtilExport void operator delete (void *ptr, void *placement_ptr)
 Placement delete operator. More...
 
static UtilExport voidaligned_malloc (size_t size, size_t alignment)
 Allocates memory on a specified alignment boundary. More...
 
static UtilExport voidaligned_realloc (void *ptr, size_t size, size_t alignment)
 Reallocates memory on a specified alignment boundary. More...
 
static UtilExport void aligned_free (void *ptr)
 Frees a block of memory that was allocated with aligned_malloc/aligned_realloc. More...
 

Constructor & Destructor Documentation

RenderGlobalContext ( )
inline
IRenderElementMgr * mpIRenderElementMgr
Definition: RenderGlobalContext.h:148
#define NULL
Definition: autoptr.h:18
ToneOperator * pToneOp
Definition: RenderGlobalContext.h:164

Member Function Documentation

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

Points to the render element manager to set.
190 { mpIRenderElementMgr = pIRenderElementMgr; }
IRenderElementMgr * mpIRenderElementMgr
Definition: RenderGlobalContext.h:148
int NRenderElements ( )
inline
Remarks
Returns the number of render elements.
193  {
195  }
IRenderElementMgr * mpIRenderElementMgr
Definition: RenderGlobalContext.h:148
virtual int NumRenderElements()=0
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.
201  {
203  }
IRenderElementMgr * mpIRenderElementMgr
Definition: RenderGlobalContext.h:148
#define NULL
Definition: autoptr.h:18
virtual IRenderElement * GetRenderElement(int index)=0
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.
211  {
212  if (projType==1)
213  {
214  return Point2( xc + xscale*p.x , yc + yscale*p.y);
215  }
216  else
217  {
218  if (p.z==0.0f)
219  p.z = .000001f;
220  return Point2( xc + xscale*p.x/p.z, yc + yscale*p.y/p.z);
221  }
222  }
float xscale
Definition: RenderGlobalContext.h:154
float y
Definition: point3.h:60
float xc
Definition: RenderGlobalContext.h:155
float yc
Definition: RenderGlobalContext.h:155
float yscale
Definition: RenderGlobalContext.h:154
float z
Definition: point3.h:61
float x
Definition: point3.h:59
Definition: point2.h:43
int projType
Definition: RenderGlobalContext.h:152
virtual FilterKernel* GetAAFilterKernel ( )
inlinevirtual
Remarks
Returns a pointer to the current anti-aliasing filter from the renderer. See Class FilterKernel.
226 { return NULL; }
#define NULL
Definition: autoptr.h:18
virtual float GetAAFilterSize ( )
inlinevirtual
Remarks
Returns the filter size of the current anti-aliasing filter.
229 { return 0.0f; }
virtual int NumRenderInstances ( )
inlinevirtual
Remarks
Returns the number of RenderInstances.
233 { return 0; }
virtual RenderInstance* GetRenderInstance ( int  i)
inlinevirtual
Remarks
Returns a pointer to the 'i-th' RenderInstance.
Parameters:
int i

Specifies which RenderInstance to return (0 through NumRenderInstances()-1).
239 { return NULL; }
#define NULL
Definition: autoptr.h:18
virtual AColor EvalGlobalEnvironMap ( ShadeContext sc,
Ray r,
BOOL  applyAtmos 
)
inlinevirtual
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); }
256  {
257  return AColor(0.0f,0.0f,0.0f,1.0f);
258  }
Definition: acolor.h:30
virtual void IntersectRay ( RenderInstance inst,
Ray ray,
ISect isct,
ISectList xpList,
BOOL  findExit 
)
inlinevirtual
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.
281 {}
virtual BOOL IntersectWorld ( Ray ray,
int  skipID,
ISect hit,
ISectList xplist,
int  blurFrame = NO_MOTBLUR 
)
inlinevirtual
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.
314 { return FALSE; }
virtual ViewParams* GetViewParams ( )
inlinevirtual
Remarks
Returns a pointer to a class which describes the properties of a view being rendered.. See Class ViewParams.
318 { return NULL; }
#define NULL
Definition: autoptr.h:18
virtual FILE* DebugFile ( )
inlinevirtual
Remarks
This method is used internally.
Default Implementation:
{ return NULL; };
323 { return NULL; }
#define NULL
Definition: autoptr.h:18
virtual INT_PTR Execute ( int  cmd,
ULONG_PTR  arg1 = 0,
ULONG_PTR  arg2 = 0,
ULONG_PTR  arg3 = 0 
)
inlinevirtual
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; }
343 { return 0; }

Member Data Documentation

IRenderElementMgr* mpIRenderElementMgr
protected
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
bool simplifyAreaLights