UDN
Search public documentation:

RenderToTexture
日本語訳
中国翻译
한국어

Interested in the Unreal Engine?
Visit the Unreal Technology site.

Looking for jobs and company info?
Check out the Epic games site.

Questions about support via UDN?
Contact the UDN Staff

UE3 Home > Materials & Textures > Render to Texture

Render to Texture


Overview


The render-to-texture features of the engine allow you to dynamically capture the scene from different viewpoints to a texture resource. This allows for certain special effects such as remote cameras and surfaces that appear to be dynamically reflecting the scene.

The purpose of this document is to outline the steps needed to create a render-to-texture resource in UnrealEd and to use that texture as a target for capturing the scene.

Creating a render target texture


The first item that is needed for rendering the scene to a texture is a new render-to-texture resource. You can create one by right-clicking and selecting the RenderToTexture option from the context menu in the Generic Browser; or by just selecting New from the File menu.

gen_browser_1.jpg

Note that there are two types of render-to-texture resources and each one is used by different scene capture types:

  • RenderToTexture - used for 2d, reflection, and portal scene captures
  • RenderToTextureCube - used for cube map scene captures

These render-to-texture resources create a valid texture surface that can be used as the render target when rendering the scene. Note that the render-to-texture resource only saves a few properties to file, but does not actually save the texture surface since it only exists for rendering purposes.

After first creating the render-to-texture resource, you will notice that it will just be cleared to a default color. Once it is used for a scene capture, however, you should be able to see the results of the capture in the texture. At any time you can change the width, height, or format of an existing render-to-texture resource and it will update its internal render target surface to match the new settings.

gen_browser_2.jpg

When you are ready to apply the render-to-texture to a surface, you can place it within an material by using a TextureSampler material expression just as you would a regular static texture resource.

The next part of this doc shows you how to actually render something to a render-to-texture resource.

HDR Support

Only RGBA render-to-texture resources can be created at this time. Support for floating point HDR targets may be added in the future.

Rendering the scene to the texture


The scene can be captured using several different methods. The most common case is to just use a single viewpoint to capture the scene to a 2D plane, but you can also capture the scene from the six different orientations of a cube map or even have the scene reflected with respect to the current viewport's camera orientation.

The basic process involves placing a SceneCapture actor in the level and associating it with the render-to-texture resource that was created. You can see a list of the available SceneCapture actors in the Actor browser.

The following is an outline of the available capture actor types that can be used and how they work.

SceneCapture2DActor

With a SceneCapture2DActor you can have the scene captured as if it was projected onto the surface of the near plane of a view frustum.

When placing one of these actors in the level you will notice that a view frustum is displayed that shows the captured view of the scene. The actor's position and orientation are used for placing and orienting the view of the captured scene. The SceneCapture actor can also be attached to other actors in case you want it to be driven by a scripted sequence or manipulated by physics.

render-to-texture_actor.jpg

Note that this actor is just a container for a SceneCapture2DComponent. Details about each of the SceneCapture component types are explained later in this document.

Before any rendering occurs, the SceneCapture actor has to have a texture target to render to. You can assign your render-to-texture resource to the SceneCapture actor by setting the TextureTarget property of its SceneCapture compoenent.

SceneCaptureCubeMapActor

The SceneCaptureCubeMapActor is similar to the SceneCapture2DActor except that it has to render the scene in six separate passes - one pass for each cube map face. This can obviously be an expensive operation so it is recommended that a lower level of detail setting is used.

Also, the capture expects a "RenderToTextureCube" resource to use as its target texture. Using the default "RenderToTexture" resource creates only a single 2D surface and can not be used for the cube map scene captures. The steps for creating a "RenderToTextureCube" are similar to creating a "RenderToTexture" resource.

Note that this actor is just a container for a SceneCaptureCubeComponent. Details about each of the SceneCapture component types are explained later in this document.

SceneCaptureReflectActor (Dynamic Reflections)

The SceneCaptureReflectActor allows for dynamic reflections of the scene. Placing an actor of this type in the level creates a view capture of the scene that is reflected and clipped properly about a mirroring surface. The mirror surface is oriented so that it faces in the same direction as the actor's direction. The positioning of the actor is also important since that will change the mirror plane's position and therefore the clipped region of the scene.

One important note about the resulting reflection is that the render-to-texture resource should be accessed using a ScreenPosition material expression with the ScreenAlign option set to true and with a ComponentMask material expression that only uses Red,Green channels. This is needed because the reflection calculations assume that the texture will be mapped as if it covers the entire screen. The following image better illustrates the required material nodes:

mat_ed_1.jpg

Note that this actor is just a container for a SceneCaptureReflectComponent. Details about each of the SceneCapture component types are explained later in this document.

SceneCapturePortalActor

The SceneCapturePortalActor allows the scene to be rendered from the viewpoint of another location as if it was mapped to the surface of a portal.

Note that this actor is just a container for a SceneCapturePortalComponent. Details about each of the SceneCapture component types are explained later in this document.

SceneCaptureComponents

These components can capture the scene to a texture target. Each component does the actual work of placing a scene capture probe in the level so that the scene gets rendered in a separate pass before rendering the main view of the level to the back buffer. You can attach these components to any other type of actor as well.

All SceneCaptureComponent types have a set of common properties that can be modified.

Each component has a target texture to render the scene to:

  • TextureTarget - A render-to-texture resource for the resulting scene capture. Note that the scene capture won't render anything unless it has an assigned target texture.

The components also have settings that control how the scene is rendered:

  • bEnablePostProcess - Toggles the post processing step that is applied to the scene.
  • bEnableFog - Toggles any height fog rendering.
  • ClearColor - The background clear color for the texture target.
  • ViewMode - Enumerates the differnet view and lighting configurations. The available modes are:

Mode Description
SceneCapView_Lit Default rendering mode for UE3 scenes with dynamic shadows and lighting
SceneCapView_Unlit No shadows or lighting passes are used when rendering the scene
SceneCapView_LitNoShadows Same as the default lit rendering mode but without dynamic shadows
SceneCapView_Wire All geometry in the scene is rendered using wireframe mode

  • SceneLOD - Sets the maximum Level of Detail (LOD) setting for all geometry in the scene. A value of 0 represents the highest LOD setting. (Currently not implemented)
  • FrameRate - Sets the FPS (Frames per Second) rate to capture the scene. For example, a value of 30 would capture the scene at 30 FPS. Also note that if the FrameRate value is 0 then the scene will only be captured once. This can be useful when you know you don't need to constantly update a particular scene capture.
  • PostProcess - Post process chain to be used by the capture. You can specify a custom post process chain for use by each scene capture (See known limitations at the end of this page).

SceneCapture2DComponent

This component handles rendering 2D captures of the scene as described in the SceneCapture2DActor. It manages the state necessary for this type of rendering, and adds a FSceneCaptureProbe2D to the current scene in order to render the capture in a separate pass.

The following properties are specific to this type of capture component:

  • FieldOfView - The horizontal field of view used to calculate the view projection.
  • NearPlane - The screen aligned view distance that represents the near clip plane.
  • FarPlane - The screen aligned view distance that represents the far clip plane. Any geometry that is completely behind the far clip plane is culled (not rendered). Decreasing the FarPlane value will result in better performance.
  • bUpdateMatrices - If this flag is set to false then the view and projection matrices are not automatically updated, and they can be set manually. This can be useful for gameplay code that needs more control over how a scene is being rendered.

SceneCaptureCubeMapComponent

This component handles rendering the six capture passes for each face of a cube map render target texture as described in the SceneCaptureCubeActor. It manages the state necessary for this type of rendering, and adds a FSceneCaptureProbeCube to the current scene in order to render the captures in a separate pass.

  • NearPlane - The screen aligned view distance that represents the near clip plane.
  • FarPlane - The screen aligned view distance that represents the far clip plane. Any geometry that is completely behind the far clip plane is culled (not rendered). Decreasing the FarPlane value will result in better performance.

The field of view is fixed at 90 degrees when rendering each of the six faces.

Note that, since this capture renders the scene six separate times, it will have slow performance in complex scenes. Try adjusting the FrameRate and FarPlane values to help performance. Remember that you can also set the FrameRate=0 in order to limit the rendering to just a single capture when the level initially renders.

SceneCaptureReflectComponent (Dynamic Reflections)

This component handles rendering the scene using a mirror plane to flip the current view and to clip all the geometry that is behind the plane. It manages the state necessary for this type of rendering, and adds a FSceneCaptureProbeReflect to the current scene in order to render the captures in a separate pass.

  • ScaleFOV - not used

SceneCaptureParaboloidComponent

Currently not supported.

SceneCapturePortalComponent

This component renders the scene as if it was viewed through a portal at another location. It uses both the orientation of the current portal and the destination portal to orient the capture. Note that the current portal and destination portal should use their own unique 2D render-to-texture resources.

  • ViewDestination - The actor at the view location for this portal. This is the point where the scene is captured from.
  • ScaleFOV - not used

Saving static captures


At times it may be necessary to save the results from an existing scene capture to a static texture. This is especially useful for generating cubemaps from various locations of your map (see note Cubemap generation note below). If you know that you don't need a dynamic capture of a scene and that a single static capture is sufficient, then it is better to create a static texture because the dynamic render-to-texture resources are not compressed like static textures are.

By right-clicking on a render-to-texture resource (2D or cubemap) you will see an option called Create Static Texture... on the context menu. After selecting this option, you can specify the name of the static resource to be created and the name of the package that it should reside in.

Static cube map captures

One very common usage for creating static textures from dynamic render-to-texture resources is for generating cubemaps from your scene. Here are the steps for generating cubemaps from your scene:

  1. Place a SceneCaptureCubeMapActor in the map at the location where you want the cubemap to be captured
  2. Create a new RenderToTextureCube resource in a package. This will be the dynamic render-to-texture target that the scene will be rendered to.
  3. Assign the RenderToTextureCube from step 2 to the TextureTarget property of the SceneCaptureCubeMapActor.
  4. Your scene is now being captured to the dynamic render-to-texture target. You can now save snapshots from this dynamic texture by right-clicking on it and selecting Create Static Texture... from the context menu. Each time you do this, a new static cubemap texture will be created along with the textures for its 6 corresponding faces.
  5. You can also move your SceneCaptureCubeMapActor to another location in the level and repeat step 4 for more static captures.
  6. Once you're done generating the static cube textures you can get rid of the temporary SceneCaptureCubeMapActor that you added to your level as well as the scratch RenderToTextureCube resource that goes with it.

Examples


The screenshots below are example of the Render to Texture feature in action.

render-to-texture.jpg

Reflections.jpg

Known Limitations


There are limits what nodes are supports for the SceneCaptureActor. The Blur and DOFAndBloom nodes can be used. The bloom in the DOFAndBlom node is not enabled. Most other nodes are made for normal full scene postprocessing and will not work for the SceneCaptureActor (e.g. UberPostProcessingNode).

To enforce update the rendering you can check and unckeck the "Enable postprocess" to update the setting from the chain.

Color manipulations should be done when reading from the texture. This will be more efficient as it doesn't require an intermediate texture and it will only be done for required pixels.