Exporting sky and image based lighting data
In Maxwell Render the sky can be defined though one of the following sky types:
- Physical sky
- Sky dome
- Image based sky (HDR/EXR/MXI)
The active type is set using the function:
setActiveSky (const char* skyType);
Where skyType can be “physical”, “constant” or NULL (no sky).
The environment is defined using the following Cmaxwell member functions:
Physical sky
byte setPhysicalSkyGeometry( real longitude, real latitude, int sm, dword dayOfYear, real timeOfDay, real basisRotation ); // Longitude: from -180.0 to 180.0; default = your city // Latitude: from -90.0 to 90.0; default = your city // Sm: from -12 to 12; default 0; // dayOfYear: from 1 to 365; default 100; // timeOfDay: from 0.0 to 24.0; default 17; // basisRotation: from 0 to 2PI radians (it is in radians) byte setPhysicalSkySunAngles( real zenith, real azimuth ); // It is an alternative way to set the sun position based on spheric angles // Call this function after setPhysicalSkyGeometry and longitude and latitude parameters will be overriden byte setPhysicalSkySunDirection( Cvector dir ); // It is an alternative way to set the sun position based on a direction // Call this function after setPhysicalSkyGeometry and longitude and latitude parameters will be overriden byte setPhysicalSkySun( byte sunActive, real sunTemperature, real sunPowerScaleFactor, real planetReflectance ); // SunActive: 0 or 1, by default sun is enabled (1) // sunTemperature: in kelvins. // Default 5777. Range: 100 - 1000000 // sunPowerScaleFactor: total power refered to the Earth's sun. // For example a value of 0.8 would mean a sun emititng 0.8 times less energy than ours. // Default: 1.0. Range: Is allowed any value greater than 0. // planetReflectance: from 0 to 1 byte setPhysicalSkyAtmosphere( real ozone, real water, real angstromTurbidity, real wavelengthTurbidity, real aerosolAlbedo, real asymmetryFactor ); // ozone: ( cms ) Default: 0.4 Range: Any value greated than 0 (usually between 0 and 1) // water: water vapor ( cms ) Default: 2.0 Range: Any value greated than 0 // angstrom turbidity: coefficient Default: 0.04 Range: Any value greated than 0 // wavelength turbidity exponent Default: 1.2 Range: Any value greated than 0 // aerosolAlbedo: aerosol albedo Default: 0.8 Range: (0-1) // asimmetryFactor: "anisotropy" of aerosol. Default: 0.7. Range (-0.99999, 0.99999);
There are complementary functions for the physical sky to get the direction of the sun and the sky color for each direction. It might be useful to display a preview of the sky in an openGL viewport (drawing a sphere and setting the colors of the vertex using getSkyColor)
byte getSunDirection( Cvector &dir ); byte getSkyColor( Crgb8 &rgb, Cvector &dir ); void getSundirection ( Cvector& dir ); void getSundirection ( Crgb8 &rgb, Cvector& dir );
Constant sky
void setSkyConstant ( Crgb &color, // sky color real radiance, // Default = 5.0, range byte useSun = 0 ); // Radiance: from 0.0 to 1000000. Default = 50.0.
The Crgb object is defined in color.h. It is an RGB color structure composed by three floats from 0 to 1. It does not have a constructor so it should be always filled using the Crgb::assign() method.
Crgb greycolor; greycolor.assign ( 0.5, 0.5, 0.5 );
Always check that the RGB colors are in float precision. RGB colors in the 0-255 range should be normalized diving them by 255.0 before passing them to Maxwell
Image based environment
To enable the image based environment, all that is needed is to call this function setting the parameter “isEnabled” to true:
byte enableEnvironment ( bool isEnabled );
There are four different channels that must be set filled: Background, Reflection, Refraction and llumination. All the channels are set with the function setEnvironmentLayer:
byte setEnvironmentLayer ( const char* pLayerName, const char* pBitmapPath, bool useSkyActive, bool useSphericalMapping, real intensity = 1.0, real uTile = 1.0, real vTile = 10., real uTileOffset = 0.0, real vTileOffset = 0.0 ); // pLayerName sets the layer type // pLayerName = "background", "reflection", "refraction", "illumination" // pBitmapPath sets the bitmap path // If "useSkyActive" is true, the sky is used instead of this channel // sphericalMapping can only be set to false when pLayerName = "background". The rest of the channels always set sphericalMapping to true // Intensity range: From 0.0 to 1000.0 (default 1.0) // Tile range: From 0.0001 to 1000.0 (default 1.0) // Offset range: From 0.0 to 1.0 (default 0.0)