Creating Render Targets

Render targets define the form of the final rendered output you want to create when you render your scene.

Bake instances

Most types of render targets require you to specify one or more bake instances: mesh instances (or point clouds) in your scene for which the output specified by the target will be created. A target without bake instances will not actually render any output (except for camera targets; see below).

Types of render targets

Beast supports several different types of render targets, described in the following sections. The type of render target you should use depends on how you plan to use the rendered data in your game, and on the type of objects you are baking (mesh instance or point clouds).

Texture targets

The texture target bakes the lighting information for one or more mesh instances into a single output texture. All mesh instances that you add to the texture target are baked together into a single UV space.

The texture target supports all types of render passes.

To create a texture target, call the ILBCreateTextureTarget() function. In your call, you need to specify the width and height of the final texture that will be generated to hold the baked lightmap.

In addition, you can use the following API functions to configure each bake instance you add to your texture target:

  • If your mesh has one or more UV sets (mappings between the vertices in the mesh and the UV coordinates at which those vertices will be placed), you can choose the UV set that will be used for each instance by calling ILBSetBakeUVSet(). For more information on UV sets, see Creating Meshes.
  • You can specify the placement of each bake instance within UV space by supplying offsets along the U and V axes. This allows you to bake multiple instances to specific unoccupied places in the output texture so that their lightmaps will not overlap. Call the ILBSetUVTransform() function.
  • After you create a render pass and assign your targets to the pass, you can scale the resolution of all texture targets assigned to that pass with a single call to the ILBSetResolutionScale() function.

Atlased texture targets

The atlased texture target bakes its instances together into a single texture like the texture target, but places the lightmap generated for each instance into an unoccupied area of UV space. If the number of baked lightmaps exceeds the UV space available in the output resolution set for the target, the atlased texture target will create additional output textures as necessary. The layout of the UV space in the output textures is atlased, so that you can retrieve the UV coordinates for each instance.

The atlased texture target supports all types of render passes.

To create an atlased texture target, call the ILBCreateAtlasedTextureTarget() function.

  • In your call to ILBCreateAtlasedTextureTarget(), you need to specify the maximum width and height of each texture that will be generated to hold the baked lightmaps. If the actual UV space needed to hold the lightmaps for all bake instances is less than the maximum dimensions, the output texture will be shrunk as needed to fit the output data. For example, if you set the maximum width and height to 1024x1024, but a 512x256 texture will hold all the output, the final framebuffer generated for the target will be 512x256.
  • In your call to ILBCreateAtlasedTextureTarget(), you also have to set the maximum number of textures that may be generated. Use 0 for no limit.

In addition, you can use the following API functions to configure your atlased texture target. See the function descriptions for details.

  • You can control the placement of the instances within the output texture by calling ILBSetAtlasAlignment(). When set to a value larger than 1, this alignment forces the placement of the lightmap for each instance to be at a multiple of the alignment value from the left side of the texture.
  • You can control the number of pixels that are left empty between adjacent instances in the texture by calling ILBSetAtlasPadding().
  • You can request that instances be packed in UV space according to their positions in the world space of the scene. When enabled, instances that are close together in the scene will also tend to be closer together in UV space. Call ILBEnableAtlasSpatial().
  • You can request each target to re-scale its resolution automatically based on the frequency information of its lightmap. This may help you produce smaller lightmaps for your scene without losing detail. Call the ILBEnableAtlasRescale() function for each target that you want to re-scale.

    The resolution for each target is re-scaled relative to a frequency threshold. If the frequency of the lighting data for the target is above this value, the resolution of the target's lightmap is not decreased. If the frequency is below this value, the resolution of the target's lightmap is scaled downward relative to the threshold. By default, the re-scaling threshold is set to 1.0, but you can customize it by calling by calling ILBSetAtlasRescaleFrequencyThreshold().

  • You can enable automatic rescaling of instances in the atlas based on frequency information from the baked lightmaps by calling ILBEnableAtlasRescale(). This will alter the actual atlas UV-layout according to lightmap frequency. To control the resizing you use the function ILBSetAtlasRescaleFrequencyThreshold().

You can use the following API functions to configure each bake instance that you add to your atlased texture target. See the function descriptions for details.

  • You can determine the size of the lightmap to be generated for each instance in the atlased texture. You can specify the desired size explicitly by calling ILBSetBakeResolution(). Alternatively, you can specify a scale value that determines the size of the lightmap based on the size of the instance, so that larger meshes have larger lightmaps. To use this approach, call ILBSetTexelScale().
  • If your mesh has one or more UV sets (mappings between the vertices in the mesh and the UV coordinates at which those vertices will be placed), you can choose the UV set that will be used for each instance by calling ILBSetBakeUVSet(). For more information on UV sets, see Creating Meshes.
  • At any time after rendering, you can call ILBGetAtlasInformation() to retrieve the index of the framebuffer that contains a specified instance, and the coordinates of that instance in UV space. See also Retrieving the Rendered Output.

Vertex targets

The vertex target bakes lighting information for each vertex in the mesh instances that you add to the vertex target. The output is a list of values for each vertex, in the same order in which the vertices were added to your mesh.

The vertex target supports all types of render passes.

To create a vertex target, call the ILBCreateVertexTarget() function.

Point cloud targets

The point cloud target bakes lighting information for a point cloud. It works like the vertex target, but instead of generating and returning lighting data for each vertex in a mesh, it generates the data for each point in the point clouds that you set up for the target.

Supported passes are Illumination SH and Lua.

To create a point cloud target, call the ILBCreatePointCloudTarget() function.

Camera targets

The camera target renders a still image of the scene as seen from the point of view of a specific camera in the scene.

The only type of render pass supported by the camera target is the full shading pass.

To create a camera target, call the ILBCreateCameraTarget() function. In your call, you need to specify the camera that will be used to generate the image, and the width and height of the image.

When creating a live camera target, you can specify the target as a standard frame render or a special bake mode. The bake mode will result in a frame buffer from the point-of-view of the camera, but is actually baking texture and vertex lightmap targets in the view. The camera mode is chosen using ILBCameraTargetSetRenderMode().

Setting up a render target

You set up render targets in the context of setting up and running a rendering job. For more information about how to set up a render target in the overall context of rendering a scene, see Rendering the Scene.

To set up a render target:

  1. Create a new ILBTargetHandle.
  2. Initialize and configure the handle according to the type of output you want to bake. See the functions listed for the different types of render targets listed under Creating Render Targets above.

For each bake instance that you want to set up for your target:

  1. Create a new ILBTargetEntityHandle.
  2. Add the bake instance to your target by calling the following functions:
  3. When setting up texture targets or atlased texture targets, you can configure the way each instance is baked by calling other functions from the Beast API. See Creating Render Targets above.

For example:

ILBTargetHandle atlasTarget;
ILBCreateAtlasedTextureTarget(job, _T("atlasTarget"), 512, 512, 0, &atlasTarget);
for (size_t i = 0; i < myMeshInstances.size(); i++) {
    ILBTargetEntityHandle entity;
    ILBAddBakeInstance(atlasTarget, myMeshInstances[i], &entity);
}
ILBTargetEntityHandle entity;
ILBAddBakeInstance(atlasTarget, floorInstance, &entity);
ILBSetBakeResolution(entity, 128, 128);

Enabling post-filtering

You can enable a world-space filter for preview baking of texture and vertex targets. This filter smooths over noise, UV seams, and seams between objects with adjacent surfaces.

To enable the filter, you call the ILBEnableWorldSpaceFilter() function, and specify the target and the type of light component you want to filter. For example, to set up the filter for indirect light:

The size of the filter automatically adapts to the resolution and variance of your baking target. However, you may occasionally find that you get better results by tweaking its kernel size. Use the ILBSetWorldSpaceFilterSize() function. For example:

The default filter size is 1.0. Therefore, specifying 2.0 as in the example above doubles the radius of the filter kernel.

Related API functions

API functions related to the creation and setup of render targets are declared in the beasttarget.h and beasttargetentity.h files.