The Ray Server

All V-Ray-related classes and functions are defined in a separate namespace, the VR:: namespace. See the notes in the V-Ray support classes section.

 

The V-Ray Geometry SDK allows 3dsmax plugins to generate custom render geometry. V-Ray's geometry system is very flexible and therefore may appear somewhat complex at first. Please read the explanations below for a general idea of how things work.

 

General notes

Implementing custom atomic (non-expandable) primitives

Implementing custom compound (expandable) primitives

 

Important classes

class RayServerInterface

class GeometryGenerator

class InfiniteRootPrimitive

class StaticRootPrimitive

class MovingRootPrimitive

class GenericPrimitive

class InfinitePrimitive

class StaticPrimitive

class MovingPrimitive

class RSRay

struct RSIntersection

 

Additional topics:

V-Ray Shading SDK additional classes

 


General notes

All intersections of rays with scene geometry are handled by a class named RayServerInterface. You can store different render primitives in the internal structures of the class using its methods.

 

There are three types of primitives:

The expandable primitives form a hierarchy of primitives that can change dynamically. Primitives can be expanded and collapsed on the fly, depending on the available memory and the rays that are being traced.

 

In addition the ray server can also work directly with triangles (static and moving). However, the number of triangles is limited by available memory, since all of them must be present at the same time.

 

A VRenderInstance can generate any kind and any number of these primitives, depending on its goal. It can generate both static and moving geometry at the same time.

 

The hierarchy of primitives is built on top of a system for dynamic allocation of resources. This system is not discussed in details here, but it in general it can be used for handling any other type of resource (textures, photon/irradiance maps etc).

 

Implementing atomic (non-expandable) primitives

Atomic primitives should be derived from class StaticPrimitive or class MovingPrimitive. Let us assume that a primitive is derived from class StaticPrimitive. These are the methods that need to be implemented:

 

int expandable(void) { return false; }

Must return false for atomic primitives.

 

void getBBox(StaticBox &bbox);

Must return the bounding box of the primitive.


void split(int dim, real middle, StaticBox &bLeft, StaticBox &bRight);

Must return the bounding boxes of the parts of the primitive on the two sides of a given splitting plane.

 

int intersect(RSRay &ray);

Intersects the primitive with a given ray.


uint32 type(void);

Must return the type of the primitive. This must be greater than PRIM_TYPE_USER.

 

Vector getGNormal(RSRay &ray);

This method is optional. Computes the geometric normal at the intersection point stored in the ray.

 

Vector getNormal(RSRay &ray);

This method is optional. Computes the smooth normal at the intersection point stored in the ray.

Implementing custom compound (expandable) primitives

Compound primitives should be derived from class StaticPrimitive or class MovingPrimitive. Let us assume that a primitive is derived from class StaticPrimitive. These are the methods that need to be implemented:

 

int expandable(void) { return true; }

Must return true for expandable primitives.


void getBBox(StaticBox &bbox);

Returns the bounding box of the primitive.


void split(int dim, real middle, StaticBox &bLeft, StaticBox &bRight);

Must return the bounding boxes of the parts of the primitive on the two sides of a given splitting plane. If the exact bounding boxes are difficult to compute, one can simply split the bounding box of this primitive.


int expand(DynamicRaycaster<StaticBox> *raycaster, int threadIndex);

Expands the primitive into other sub-primitives by calling DynamicRaycaster::insertPrimitive(). Returns the memory taken up by the new primitives.


int collapse(DynamicRaycaster<StaticBox> *raycaster, int threadIndex);

Collapses the primitive by calling DynamicRaycaster::removePrimitive() for all sub-primitives that were inserted during expansion. Returns the memory that was freed.


int getMemUsage(void) { return 0; }

Top-level primitives should implement this to return their memory usage in unloaded state. All other primitives should return 0.

 

uint32 type(void);

Returns the type of the primitive. This must be greater than PRIM_TYPE_USER.