class RED::ISunLightShape

This interface gives access to the creation and edition of sunlights. More...

#include <REDISunLightShape.h>

Inherits: IREDObject.

Public functions:

virtual RED_RCGetSamplesCount ( unsigned int & oSamplesCount, int iStateNumber = -1 ) const = 0
virtual RED_RCGetSun ( RED::Vector3 & oSunDir, double & oSunScale, double & oSunMult, int iStateNumber = -1 ) const = 0
virtual RED_RCSetSamplesCount ( unsigned int iSamplesCount, const RED::State & iState ) = 0

Public static functions:

static RED::CIDGetClassID ( )

Detailed description:

This interface gives access to the creation and edition of sunlights.

The RED::ISunLightShape interface is exposed by the CID_REDLightShape instances.

This light simulates a sun based on a sky model definition. It's set-up through the RED::ISkyLightShape interface by calling RED::ISkyLightShape::SetSunLight. You can get the correct sun's position as seen from earth according to time, date and location by using the RED::ISkyLightShape::ComputeSunDirection method.

To get a full sky simulation (i.e including light scattered by the atmosphere), don't forget to add a RED::ISkyLightShape instance to your scene.

The moon light is handled separately using the RED::IMoonLightShape and RED::ISkyLightShape interfaces.

task

Task: Setup a physical sun light

A physical sun light can't exist without a physical sky light. So all starts with the creation of a physical sky light (Setup a physical sky light).

Then the sky light is used to set up the sun light according to its sky model:

// "sky" is a pointer to a previously created and set up RED sky light instance.
RED::ISkyLightShape* isky = sky->As< RED::ISkyLightShape >();

// Initialize the sun light according to the current sky model settings.
RED::Object* sun = NULL;  // passing NULL makes the method below to create the sun instance for us.
RC_TEST( isky->SetSunLight( sun, iresmgr->GetState() ) );

Because the sun is a physical light, no other parameters are needed (like colour or intensity) and all other data are computed based on physics simulation. Finally, you can tune the quality of the sun light sampling by setting the sun samples count used during rendering:

// 64 samples are used to evaluate the contribution of the sun during rendering.
RED::ISunLightShape* isun = sun->As< RED::ISunLightShape >();
RC_TEST( isun->SetSamplesCount( 64, iresmgr->GetState() ) );

The sun is a relatively small source of light as seen from the earth. Hence, a few samples can be generally used to render it with good quality.

The effect of increasing the sun light samples count: 4 samples were used for the sun in the whole image except in the green zone where 16 samples were used.

Functions documentation

public virtual RED_RC RED::ISunLightShape::GetSamplesCount(unsigned int &oSamplesCount,
intiStateNumber = -1
)const = 0

Gets the number of sun samples.

See SetSamplesCount for details.

Parameters:

oSamplesCountthe maximum number of sun light samples.
iStateNumberqueried state number.

Returns:

RED_OK if the operation has succeeded,
RED_BAD_PARAM if the method has received invalid parameters,
RED_ALLOC_FAILURE if an internal allocation has failed,
RED_WORKFLOW_ERROR if a transaction error has occurred,
RED_FAIL otherwise.
public virtual RED_RC RED::ISunLightShape::GetSun(RED::Vector3 &oSunDir,
double &oSunScale,
double &oSunMult,
intiStateNumber = -1
)const = 0

Gets parameters of a physical sun.

See RED::ISkyLightShape::SetSunLight for all details on the parameters returned by this method.

Parameters:

oSunDirunit direction from the ground to the sun.
oSunScaleSun size scaling factor.
oSunMultSun intensity multiplier.
iStateNumberQueried state number.

Returns:

RED_OK if the operation has succeeded,
RED_BAD_PARAM if the method has received invalid parameters,
RED_ALLOC_FAILURE if an internal allocation has failed,
RED_WORKFLOW_ERROR if a transaction error has occurred,
RED_FAIL otherwise.
public virtual RED_RC RED::ISunLightShape::SetSamplesCount(unsigned intiSamplesCount,
const RED::State &iState
) = 0

Sets the number of samples to be taken during sun evaluation.

Lights are sampled during the rendering phase in each shaded point to estimate their contribution to the scene. The more the samples, the better the result and the longer the rendering times.

Lights can't have less than 1 sample. If 0 is supplied, 1 will be used instead.

A sun light is a very small source as seen from the ground and few samples are needed for a good result.

Parameters:

iSamplesCountmaximum number of samples to be taken while evaluating the sun light contribution.
iStatecurrent transaction.

Returns:

RED_OK if the operation has succeeded,
RED_BAD_PARAM if the method has received invalid parameters,
RED_ALLOC_FAILURE if an internal allocation has failed,
RED_WORKFLOW_ERROR if a transaction error has occurred,
RED_FAIL otherwise.