Version:

Render to Texture

Render to Texture


This feature is in preview release and is subject to change.

You can use the Render to Texture component to render the scene from a specific camera to a texture. You can use this feature to create rear-view mirrors, security camera screens, and draw 3D models in the viewport.

To enable this component, you must enable the Render to Texture gem. To enable gems, see Enabling Gems.

[Render to Texture gem in the Project Configurator.]

Topics

Adding the Render to Texture Component in a Scene

Example
Entity (1) has a Camera component and a Render to Texture component. This entity faces a game object, entity (2). In entity (1), the Render to Texture component specifies a render target. A material file references that render target as its diffuse texture. The material is then added to entity (3), so that the render target appears in the viewport.

[Render to Texture component in the viewport.]

To use the Render to Texture component

  1. In Lumberyard Editor, create an entity in the viewport. For more information, see Creating an Entity.

  2. In the Entity Inspector, click Add Component.

  3. Select the Camera component, choose Be this camera, and then move the camera entity using the viewport camera controls to look at an object in your level.

  4. In the Entity Inspector, click Add Component.

  5. Select the Render to Texture component.

  6. For Texture name, enter a name that starts with the $ character, such as $rendertarget. Note
    The $ character tells Lumberyard that the texture will not be loaded from disk. If you don’t specify the $ character, Lumberyard will try to locate the texture file from disk, which can impact performance.

  7. To open the Material Editor, choose Tools, Material Editor or press M.

  8. Click the Add New Item icon to create a material, enter a name such as RenderToTexture, and then click Save.

  9. In the Texture Maps section, for Diffuse, enter the Texture name that you specified, such as $rendertarget.

  10. In the Asset Browser, navigate to primitive_plane.cgf, and then select and drag the file into the viewport.

  11. Assign the material to the primitive plane entity. In the Mesh component, for the Material override property, specify the material file that you created, such as RenderToTexture.mtl.

    The primitive plane entity now shows the texture from the Render to Texture component.

Adding a Render Target to a UI Element

You can also specify the render target in an Image component for a UI element. For example, you can add the render target to appear in a button or object that a user can select in a UI menu.

For more information, see Visual Components.

Example
A camera entity (1) faces the Render to Texture entity (2), which has a Render to Texture component attached. The Texture name is $rendertarget.

[Add the render target for the UI Editor.]

To add a render target to a UI Image component

  1. Complete steps 1 to 6 in the previous procedure. See Adding the Render to Texture Component in a Scene.

  2. In Lumberyard Editor, choose Tools, UI Editor.

  3. In the UI Editor, create or open a UI canvas.

  4. Right-click the canvas and choose New, Element from Slice Library, Image.

  5. In the Image component, for SpriteType, click the drop-down menu, and then select Render target.

  6. For Render target name, enter the same texture name in the Render to Texture component, such as $rendertarget.

    The UI Image component displays the render target in the UI Editor.
    [Add the render target to the Render target name in an Image component.]

Render to Texture Properties

[Render to Texture component properties.]

The Render to Texture component has the following properties.


NameDescription
CameraEntity with a Camera component attached to use as the view. If you specify an entity without a Camera component, only the position and orientation will be used from that entity. If you don’t specify an entity, this property defaults to the entity to which the Render To Texture component is attached.
Texture nameName of the texture to which to render. Follow the Lumberyard convention of using a $ as the first character in the texture name. This is how Lumberyard denotes render targets.
Max FPSMaximum frames per second at which this view updates.
WidthWidth of the render texture, in pixels.
HeightHeight of the render texture, in pixels.
Apply GammaEnables gamma application to the texture. If you want to use this texture with a material inside the main view, leave this property disabled, because gamma will be applied to the entire scene during post-processing. As a best practice, if you are using render targets in the UI, clear the Apply Gamma property and don’t select the Render Target sRGB property in the UI Image component. However, if the texture appears too dark, you can set either property.
Alpha ModeYou can specify the following values: [See the AWS documentation website for more details] [See the AWS documentation website for more details]
Enable OceanEnables drawing the ocean in the render target.
Enable TerrainEnables drawing terrain in the render target.
Enable VegetationEnables drawing vegetation in the render target.
Enable ShadowsEnables drawing shadows in the render target.
GSM LODsNumber of global shadow map levels of detail ( LOD ) to use for the render to texture scene. A value of -1 will use the current settings for the e_GsmLodsNum console variable.
GSM rangeGlobal shadow map range to use for the render to texture scene. A value of -1 will use the current settings for the e_GsmRange console variable.
GSM range stepGlobal shadow map range step to use for the render to texture scene. A value of -1 will use the current settings for the e_GsmRangeStep console variable.
Antialiasing ModeYou can specify the following values: [See the AWS documentation website for more details]
Display Debug ImageDisplays debug overlay images in Lumberyard Editor only.
Update in editorEnables updating the render target outside of game mode while in Lumberyard Editor.

EBus Request Bus Interface

You can use the event bus (EBus) interface to communicate with other components in your game.

For more information, see Working with the Event Bus (EBus) system.


Request NameDescriptionParameterReturnScriptable
GetTextureResourceIdGets the resource ID of the render target. A value of -1 is an invalid render target.NoneintegerYes
SetAlphaModeSets the alpha mode for the render target.0 = Disabled 1 = Opaque 2 = Depth basedNoneYes
SetCameraSets the entity with a Camera component to use for rendering.EntityIDNoneYes
SetEnabledEnables or disables rendering to texture.0 = Disable 1 = EnableNoneYes
SetMaxFPSSets the maximum rate at which this render target updates, in frames per second.FPSNoneYes
SetWriteGammaEnables or disables gamma application.0 = Disable 1= EnableNoneYes

EBus Notification Bus Interface

You can use the event bus (EBus) interface to communicate with other components in your game.

For more information, see Working with the Event Bus (EBus) system.


Request NameDescriptionParameterReturnScriptable
OnPreRenderToTextureCalled before rendering to texture begins for each Render to Texture component.NoneNoneYes
OnPostRenderToTextureCalled after rendering to texture is finished for each Render to Texture component.NoneNoneYes

Known Limitations

The Render to Texture component supports DirectX 11 for Windows.

Prevent Graphical Artifacts When Render to Texture is Active with the Following CVARs

Forces the object LOD to update at the beginning of the frame instead of the end of the previous frame. If you don’t set this console variable, you may see LOD flickering.

For more information about setting console variables, see Using the Console Window.

e_LodForceUpdate=1

Disables precaching of the streaming system due to common large jumps in the camera position when the render to texture feature is active.

e_AutoPrecacheCameraJumpDist=0

Enables subpixel morphological antialiasing (SMAA) instead of temporal antialiasing (TAA).

r_AntialiasingMode=2

Disables volumetric fog.

e_volumetricFog=0

Disables multi-GPU mode.

r_MultiGPU=0

Disables sparse voxel octree global illumination (SVOGI gem).

e_GI=0

You might see flickering, black or blurry textures if the streaming system thrashes while the Render to Texture component is active. This can occur in a scene that uses a large amount of texture memory.

To fix this, increase the value for r_TexturesStreamPoolSize, or set the Max FPS property to 0 so that the component updates each frame. This might help the streaming system balance texture priorities.

Tip
To verify if the graphics artifacts are a result of streaming thrashing, set r_TexturesStreamingDebug to 2. This console variable shows the textures that are streamed in and the memory usage.

Unsupported Features in the Render Target

The following features are not supported for the Render to Texture component because they don’t work with multiple cameras.

  • TAA and SMAA
  • Lens flares
  • Sun shafts
  • Volumetric fog
  • CBuffer (constant buffer) occlusion (vis areas are supported)
  • Motion blur
  • Merged mesh vegetation
  • Shadows cache