Class LightDesc

3DS Max Plug-In SDK

Class LightDesc

See Also: Class RenderData, Class LightRayTraversal, Class ObjLightDesc, Class ShadeContext, Class Color, Class Point3.

class LightDesc : public RenderData

Description:

This class has a method Illuminate() used to determine the color and direction of the light striking the point sc.P() and a method to get the position of the light. It also has two public data members that determine if the diffuse and specular colors of objects are affected.

Data Members:

public:

BOOL affectDiffuse;

This data member is available in release 2.0 and later only.

If TRUE the light affects the diffuse color; otherwise it does not.

BOOL affectSpecular;

This data member is available in release 2.0 and later only.

If TRUE the light affects the specular color; otherwise it does not.

BOOL ambientOnly;

This data member is available in release 3.0 and later only.

If TRUE the light affects the ambient color only; otherwise it does not.

DWORD extra;

This data member is available in release 3.0 and later only.

This is not currently used and is available for use in the future.

Methods:

Prototype:

LightDesc();

Remarks:

Constructor. The affectDiffuse and affectSpecular data members are set to TRUE.

Prototype:

virtual BOOL Illuminate(ShadeContext& sc, Point3& normal,

Color& color, Point3 &dir, float &dot_nl, float &diffuseCoef);

Remarks:

Implemented by the Plug-In.

This method is called to determine the color and direction of illumination from the light that is hitting the point (sc.P()).

Parameters:

ShadeContext& sc

Describes the properties of the point to shade. The point itself is sc.P().

Point3& normal

The normal to the surface in camera space.

Color& color

The color that is returned. This is the brightness of light striking the point (sc.P())

Point3 &dir

The direction that the light is coming from.

float &dot_nl

This provides a bit of optimization as most lights will have to calculate this quantity. This is the dot product between the light vector and the normal to the surface.

float &diffuseCoef

This parameter should be set by the Illuminate function. The default value is the same as dot_nl. It will be used by shading functions instead of dot_nl to compute the diffuse illumination of the surface. The built-in lights use the new "Contrast" parameter (which has a range of [0..100]) to compute the diffuseCoef from the dot_nl by the Contrast function:

// precomputed:

float a = contrast/200.0f + 0.5f; // so "a" varies from .5 to 1.0

kA = (2.0f-1.0f/a);

kB = 1.0f-kA;

 

// called by Illuminate() to compute diffuseCoef from dot_nl.

float ContrastFunc(float nl) {

// the "Bias" function described in Graphics Gems IV, pp. 401ff

  return (contrast==0.0f)? nl : nl/(kA*nl+kB);

}

Return Value:

Returns FALSE if the hitpoint is outside the effective range of the light or if the normal of the surface faces away from the light. This is a hint to the material that the light dd not calculate its illumination because it is assumed it wasn't going to be used. If TRUE the point is being illuminated.

Default Implementation:

{ return 0;}

Prototype:

virtual Point3 LightPosition();

Remarks:

This method is available in release 2.0 and later only.

Returns the position of the light.

Default Implementation:

{ return Point3(0,0,0); }