UDN
Search public documentation
PostProcessMaterials
Using Materials with Post Processing
Document Summary: This document is intended to detail the use of Materials in the Post Process system for Unreal Engine 3. Document Changelog: Created by Alan Willard.Creating a PostProcess Material
Here I'm going to give some examples of how to create materials for use in the PostProcess system.Using materials in PostProcess
Materials used in the Post Process system in Unreal Engine 3 are nearly identical to materials created for use on other assets. The primary difference is that the Emissive channel is the only one used, and the material must be unlit.What is the Scene Texture module
Instead of using a TextureSample as the primary render source for the material, the SceneTextureSample module is used. This module represents the currently rendered scene. It is important to note that the SceneTextureSample does not render the scene correctly in the material editor, you must have it in use in the PostProcess system to see it in use.What is the Scene Depth module
To access the depth of the scene, the SceneDepth module is provided. In many cases to use this module requires additional math to be performed to scale and bias the depth results to the value range desired. For example, dividing a value by the SceneDepth (1024/SceneDepth) will provide an approximate distance value. Clamping this to a max of 0-1 will allow it to be used for many effects.Utilizing the Scene Texture module
The SceneTextureSample module is used in exactly the same manner as any TextureSample. The most basic usage is to connect the RGB output to the emissive input for the shader. If this example is used in the PostProcess system, there will be no visual result, as it is merely rendering the scene and not doing any additional work to the results. The SceneTextureSample has a Coordinate input, which again is identical to the one on TextureSamples. Changes in tiling and UV offsets can be done using this Coords input.Utilizing the Scene Depth module
The SceneDepth shader module returns the depth of the entire scene, however the values that are returned are not in a commonly usable range for doing PostProcess material effects. The most common adjustment made to the SceneDepth module is dividing it by a high value that represents the range of depth you want.Adding the material to the PostProcess stack
Creating a MaterialEffect module
The default PostProcess setup used by the engine is located in EngineMaterials, DefaultPostProcess in name. Double-clicking on this object will open the PostProcess editing window, similar in layout to Kismet. The default PostProcess setup is the scene wired into a Bloom/DOF module. Right-clicking on the workspace will allow you to add a MaterialEffect node. Dragging a connection from the output of the Bloom node into the input of the Material node will add that effect to the stack. There are a selection of example PostProcess materials available in the DemoContent\Packages folder, in the UDN_ExampleMaterials package, in the PostProcess group. M_UDN_PostProcess_SepiaTone is a good example to use. Click on the MaterialEffect node, and select the SepiaTone material in the Generic browser. In the properties for the MaterialEffect node, the Material field when selected will have a green arrow on the far right of the field. Clicking this arrow will enter the currently selected material. If the bShowInEditor flag is on the MaterialEffect node, and the flag for PostProcessEffects is enabled in the 3d viewport, you should now see your scene rendered using this effect.Depth Groups
The other option in the MaterialEffect node is the SceneDPG, which refers to which buffer will be sampled by the material effect. Most material effects will use the SDPG_PostProcess group, but any effect that uses the SceneDepth module will probably use the SDPG_World group.Modifying the rendered scene
These are a few methods of using the MaterialEffect channel to modify the final rendered scene.Recoloring the scene
Modifying the scene color - M_UDN_PostProcess_SepiaTone In the M_UDN_PostProcess_SepiaTone shader, the Scene Texture is desaturated, and the Red channel of the scene is also separated and multiplied by a constant of 64, then multiplied by an RGB value which represents the sepia 'stain'. This is then recombined with the desaturated version of the scene to reintroduce the other (non-red) elements of the scene. The end result of this is then used in the Emissive channel.Modifying the UVs of the scene
Modifying the UVs of the scene - M_UDN_PostProcess_Distortion In this example, we use the Coordinates input to the Scene Texture to modify the UVs of the final rendered scene. This is simply done by adding the red channel of a texture sample to a Texture Coordinates module. This distorts the UVs, and is used as the Coordinates of the Scene Texture.Scene Depth used as a mask
Using the Scene Depth as an alpha mask - M_UDN_PostProcess_DistanceDistortion This is a more complicated material, as it uses the scene depth as the interpolator between an animated and distorted version of the scene and the default version of the scene. There is a long chain of modifiers that essentially distort a panning UV coordinate set using a grayscale texture, use those results as the coordinates for a normal map with a fractal pattern. This normal map is then reduced to the R and G channels via a ComponentMask, and multiplied by .5 to darken it. This result is added to a Texture Coordinate, which is finally used as the Coordinate input for one of the two Scene Texture Samples in this material. At the same time, the Scene Depth is being divided by a value of 256 to establish a range of depth, then clamped to give a valid range of 0-1. This clamped value is used as the alpha for a linear interpolate between the distorted version of the Scene Texture and a non-distorted version of the scene. When added to the MaterialEffect node in the PostProcess object, it will not function correctly until the SceneDPG is set to SDPG_World. Once this is done, you should see the effect correctly. The desired result of this effect is objects and surfaces will become more distorted the further from the camera they are. Modifying the constant the SceneDepth module is divided with will adjust the distance away from the camera things become distorted.Referenced packages
There is a single package that is repeatedly referenced in this document: UDN_ExampleMaterials.upk. This package resides in %EnginePath%\ExampleGame\Content\Packages.Relevant Threads
https://udn.epicgames.com/lists/showpost.php?list=unedit3&id=3787https://udn.epicgames.com/lists/showpost.php?list=unedit3&id=3813
