Class ShadBufRenderer
See Also: Class ShadowGenerator, Class RendContext, Class RenderGlobalContext, Class ObjLightDesc, Class Matrix3.
class ShadBufRenderer
Description:
This class is available in release 3.0 and later only.
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.
The following global function is not a member of this class but is available for use:
Function:
ShadBufRenderer *NewDefaultShadBufRenderer();
Remarks:
This global function creates and returns a pointer to a new default shadow buffer renderer.
Methods:
public:
Prototype:
virtual int Render(RendContext &rc, RenderGlobalContext *RGC, float *buf, BOOL parallel, int shadsize, float param, float aspect, float clipDist, ObjLightDesc *ltDesc, Matrix3 worldToLight)=0;
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.
Return Value:
Returns the number of objects that the shadow volume intersected. If this value is 0, the shadow buffer can be freed to save memory.
Prototype:
virtual float Furthest()=0;
Remarks:
After a render, this method returns the farthest Z in the shadow buffer.
Prototype:
virtual float Closest()=0;
Remarks:
After a render, this method returns the closest Z in the shadow buffer.
Prototype:
virtual void DeleteThis()=0;
Remarks:
Deletes this ShadowBufRenderer object.