ShadBufRenderer Class Reference

#include <shadbuf.h>

Class Description

See also
Class ShadowGenerator, Class RendContext, Class RenderGlobalContext, Class ObjLightDesc, Class Matrix3.

Description:
This class is used to generate a Shadow Buffer which may be used to determine if a point is in shadow or not. The 3ds Max shadow maps use this object internally, for example.

There is a global function that creates one of these ShadBufRenderer objects. With one of these developers can call its Render() method to generate (render) a Shadow Buffer.

The rendered shadow buffer stores a Z distance at every point in the buffer. This can then be used to determine if something is in shadow. To check a certain point you simply see if the Z value is behind the one in the buffer. That is, a shadow buffer tells one, from the point of view of a light, how far it is to the first object for each pixel in the buffer. If the Z point of the thing being shadowed is farther than (behind) the corresponding Z value in the buffer then the thing is in shadow. If it's closer than it is not in shadow.

The main Render() method is typically called from the Update() method of class ShadowGenerator which is called on every frame to create a new shadow buffer.

To use this class you basically do the following:

Allocate an array of floating point values, one float for each point in the shadow buffer:

buffer = new float[shadsize*shadsize];

Then create a default Shadow Buffer Renderer using the global function provided:

ShadBufRenderer *sbr = NewDefaultShadBufRenderer();

Then you setup all the parameters for the view, etc prior to calling the Render() method to render the buffer. (These parameters are passed in to the ShadowGenerator::Update() method).

int nRendered = sbr->Render(rc, RGC, buffer, parallel, shadsize, param, aspect, clipDist, ltDesc, worldToLight);

You can check the return value to determine if any objects were intersected by the shadow volume. If none were, the shadow buffer can be freed.
if (nRendered==0)
{
delete [] buffer;
sbr->DeleteThis();
buffer = NULL;
return 1;
}
All methods of this class are implemented by the system.
+ Inheritance diagram for ShadBufRenderer:

Public Member Functions

virtual int Render (RendContext &rc, RenderGlobalContext *RGC, float *buf, BOOL parallel, int shadsize, float param, float aspect, float clipDist, ObjLightDesc *ltDesc, Matrix3 worldToLight)=0
 
virtual float Furthest ()=0
 
virtual float Closest ()=0
 
virtual void DeleteThis ()=0
 

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...
 

Member Function Documentation

virtual int Render ( RendContext rc,
RenderGlobalContext RGC,
float *  buf,
BOOL  parallel,
int  shadsize,
float  param,
float  aspect,
float  clipDist,
ObjLightDesc ltDesc,
Matrix3  worldToLight 
)
pure virtual
Remarks
Compute a shadow Z buffer for the current scene from the viewpoint of the light. NOTE: The computed shadow buffer has positive Z values as you go away from the light, which is the reverse of the 3ds Max coordinate system.
Parameters:
RendContext &rc

The RendContext which is used for the progress bar API.

RenderGlobalContext *RGC

Points to the RenerGlobalContext which is used to retireve information about the global rendering enviornment (to get an instance list).

float *buf

This is the buffer to render to. This is a pre-allocated array of floats (shadsize*shadsize).

BOOL parallel

The projection type. TRUE if parallel projection; FALSE if perspective projection.

int shadsize

The size of the buffer (shadsize by shadsize pixels).

float param

The view parameter. For a perspective this is the:field-of-view (in radians). For a parallel view this is the width in world coordinates.

float aspect

This is the aspect ratio of the buffer projection.

float clipDist

The clipping distance. This tells the shadow buffer renderer to not consider objects farther than this distance from light.

ObjLightDesc *ltDesc

This is the descriptor for light that was passed in to CreateShadowGenerator().

Matrix3 worldToLight

The world to light transformation matrix for the light.
Returns
Returns the number of objects that the shadow volume intersected. If this value is 0, the shadow buffer can be freed to save memory.
virtual float Furthest ( )
pure virtual
Remarks
After a render, this method returns the farthest Z in the shadow buffer.
virtual float Closest ( )
pure virtual
Remarks
After a render, this method returns the closest Z in the shadow buffer.
virtual void DeleteThis ( )
pure virtual
Remarks
Deletes this ShadowBufRenderer object.