RealityServer Features

Auto Exposure

When rendering a phyically based scene it is typically necessary to tonemap the results as the lighting units are usually well above the 0 to 1 range that is representable in an LDR image (like jpeg or png). In Iray this is often done using the Photographic Tonemapper by setting the tm_tonemapper attribute on the camera to mia_exposure_photographic.

This tonemapper then needs to be configured by setting f number, iso and shutter speeds just like an SLR camera. And just like an SLR camera this can be tricky and a trial and error process for the normal user.

The falsecolor render loop handler improves on this situation by adding an auto expose feature, just like compact and SLR cameras have. When an auto expose is triggered a small HDR image is rendered and analyzed to calculate appropriate tonemapping settings (f number and shutter speed) to produce a well exposed image. The results of this can either be returned to the user or automatically set on the scene camera to be used in subsequent renders.

Auto exposure is controlled via attributes on the scene's camera. A request is made by setting a request ID and parameter attributes on the camera and responses are read from attributes on the camera once the auto expose is complete.

Triggering requests and receiving results

As performing an auto exposure is an asynchronous process a mechanism is needed to trigger the exposure and then discover when it is completed. This is done by using the attributes ae_request and ae_response on the scene camera. These attributes are numeric ids that are used to detect when to perform an auto exposure and when the results are available.

To perform an auto expose simply set a value on the ae_request attribute. Before the render handler performs the next render it will check the value of this attribute, and if it has changed an auto expose will be performed.

Once the auto expose has been completed the handler sets the ae_response attribute to be the same as ae_request. The user should use element_get_attribute to poll for the value of this attribute, and when it matches the request value used, the auto expose results can be read off the camera.

Auto Expose Trigger Camera Attributes
Attribute Name Attribute Value Attribute Type Description
ae_request none Sint32 Change this to a value other than 0 to set off an auto expose.
ae_response none Sint32 When this attribute has the same value as the request the auto expose is complete.

Example: Trigger an auto exposure

let auto_expose_request = 0;

auto_expose_request++;
send_realityserver_command(
    {
        "method": "element_set_attribute",
        "params": {
            "element_name": "my_camera",
            "attribute_name: "ae_request",
            "attribute_value": auto_expose_request,
            "attribute_type": "Sint32",
            "create": true
        }
    }
);

Example: Poll for the result

let auto_expose_response = send_realityserver_command({
            "method": "element_get_attribute",
            "params": {
                "element_name": "my_camera",
                "attribute_name: "ae_response"
            }
        }
    );
while (auto_expose_response !== auto_expose_request) {
    sleep(5); // wait 5 seconds then poll again
    auto_expose_response = send_realityserver_command({
            "method": "element_get_attribute",
            "params": {
                "element_name": "my_camera",
                "attribute_name: "ae_response"
            }
        }
    );
}
// auto expose is complete, the results can now be fetched off the camera if required.
Note: In the above the function send_realityserver_command is a synchronous function that sends the provided command or array of commands and returns it's result or undefined on error.

Auto exposure settings

Auto exposure calculation is controlled via various attributes on the scene camera.

Auto Exposure Camera Setting Attributes
Attribute Name Default Value Attribute Type Description
ae_resolution_x 150 Sint32 The x resolution of the auto expose render.
ae_resolution_y 80 Sint32 The y resolution of the auto expose render.
ae_render_samples 30 Sint32 The number of samples to render when auto exposing.
ae_exposure_compensation 2 Float32 Exposure compensation, the calculated f stop is offset by this amount.
ae_metering_mode full_image String What area of the image to use when calculating exposure.
  • full_image use the entire image.
  • spot restricts to a circle in the center of the image.
  • center_weighted weights the image center differently to the edges.
ae_metering_radius 0.5 Float32 In spot and center_weighted metering modes this gives the radius of the metering circle. Range is 0 to 1.
ae_center_weight 0.8 Float32 In center_weighted metering mode this gives the weight of the metering circle. Range is 0 to 1.
ae_f_stop_maximum 32 Float32 The maximum f stop value to use, if calculated f stop is above this value the shutter speed is modified instead.
ae_f_stop_minimum 0 Float32 The minimum f stop value to use, if calculated f stop is below this value the shutter speed is modified instead.
ae_set_onto_camera 2 Sint32 Bitflag telling what result attributes to set on the camera.
  • 0x1 sets the falsecolor mif_min and mif_max attributes to ae_min and ae_max (clamped to within 3 standard deviations of the average).
  • 0x2 sets the photographic tonemapper mip_f_number and mip_camera_shutter attributes.
  • 0x4 sets irradiance attribute to indicate if an irradiance exposure was performed.
ae_irradiance false Boolean If true then the auto expose render uses irradiance mode. Useful for calculating min/max values for irradiance falsecolor renders.

Example: Trigger an auto exposure with settings and automatically sets the photographic tonemapper values

auto_expose_request++;
send_realityserver_command(
    {
        "method": "element_set_attributes",
        "params": {
            "element_name": "my_camera",
            "attributes": {
                "ae_request": {
                    "value": auto_expose_request,
                    "type": "Sint32"
                },
                "ae_metering_mode": {
                    "value": "spot",
                    "type": "String"
                },
                "ae_exposure_compensation": {
                    "value": 0,
                    "type": "Float32"
                },
                "ae_resolution_x": {
                    "value": 30,
                    "type": "Sint32"
                },
                "ae_resolution_y": {
                    "value": 30,
                    "type": "Sint32"
                },
                "ae_set_onto_camera": {
                    "value": 2,
                    "type": "Sint32"
                }
            }
            "create": true
        }    
    }
);

Auto exposure results

Once complete the following attributes are set on the scene camera to provide the results.

Auto Exposure Camera Result Attributes
Attribute Name Attribute Type Description
ae_max Float32 The maximum radiance/irradiance value found in the exposure.
ae_min Float32 The minimum radiance/irradiance value found in the exposure.
ae_average Float32 The average radiance/irradiance value found in the exposure.
ae_sd Float32 The radiance/irradiance standard deviation.
ae_f_number Float32 The calculated f number.
ae_camera_shutter Float32 The calculated shutter speed.

Changing Tonemapper

By default, after performing an auto exposure the tm_tonemapper will be set back to it's previous value. However it is often useful to use the auto exposure to calculate initial values for a given tonemapper when switching to that tonemapper. For example you may want to enable the false color tonemapper and use auto exposure to calculate sensible initial values. The typical workflow for this would be:

// trigger auto exposure and set the falsecolor tonemapping attributes
auto_expose_request++;
send_realityserver_command(
    {
        "method": "element_set_attributes",
        "params": {
            "element_name": "my_camera",
            "attributes": {
                "ae_request": {
                    "value": auto_expose_request,
                    "type": "Sint32"
                },
                "ae_set_onto_camera": {
                    "value": 1,
                    "type": "Sint32"
                }
            }
            "create": true
        }    
    }
);
// wait until complete 
let auto_expose_response = send_realityserver_command({
            "method": "element_get_attribute",
            "params": {
                "element_name": "my_camera",
                "attribute_name: "ae_response"
            }
        }
    );
while (auto_expose_response !== auto_expose_request) {
    sleep(5); // wait 5 seconds then poll again
    auto_expose_response = send_realityserver_command({
            "method": "element_get_attribute",
            "params": {
                "element_name": "my_camera",
                "attribute_name: "ae_response"
            }
        }
    );
}
// tonemapping attributes will now be set, activate the tonemapper
send_realityserver_command(
    {
        "method": "element_set_attribute",
        "params": {
            "element_name": "my_camera",
            "attribute_name":  "tm_tonemapper",
            "attribute_value": "falsecolor",
             "attribute_type": "String",
            "create": true
        }    
    }
); 

While this system works it involves (potentially) many roundtrips to check for completion and delays the activation of the tonemapper

As a convenience the auto exposure system supports the ae_tonemapper attribute. If this attribute exists, then after tonemapping it's value is transferred to the tm_tonemapper to activate the new tonemapper. ae_tonemapper is then deleted to ensure it isn't applied again the next time an auto expose occurs.

Auto Exposure Tonemap Set Camera Attributes
Attribute Name Attribute Type Description
ae_tonemapper String If set this automatically activates this tonemapper after auto exposure.

The above example can now be simply performed as:

// trigger auto exposure and set the falsecolor tonemapping attributes
// once auto expose is complete activate the falsecolor tonemapper.
auto_expose_request++;
send_realityserver_command(
    {
        "method": "element_set_attributes",
        "params": {
            "element_name": "my_camera",
            "attributes": {
                "ae_request": {
                    "value": auto_expose_request,
                    "type": "Sint32"
                },
                "ae_set_onto_camera": {
                    "value": 1,
                    "type": "Sint32"
                },
                "ae_tonemapper": {
                    "value": "falsecolor",
                    "type": "String"
                }
            }
            "create": true
        }    
    }
);