User Scene Textures for Post Process Materials(4/5)

  1. The last one’s Input Name is Alpha and the Input Type is Function Input Scalar.

    Alternatively, you can copy the code from the image above and paste it directly into your graph of your material function.

    Connect the Lerp to the Output Result node.

User Scene Textures for Post Process Materials(4/5) - 图1 Save and Close the Material Function Editor.

Creating a Material with Variable Blur using User Scene Textures

This is the final material you’ll create that ties all these components together for the variable blur post process effect. The TripleBilinearLerp material function uses the half-res and quarter-res user scene textures to create the variable blur effect on screen, and you’ll use the Alpha input to control areas of the screen affected by the blur effect across the center, middle, and outer edges of the screen.

  1. In the Content Browser, click the Add (+) button and create a Material. Name the material “BlurApply”.
  2. Open the BlurApply material.
  3. In the Details panel, set the following: User Scene Textures for Post Process Materials(4/5) - 图2 Domain: Post Process
  4. Blendable Location: Scene Color Before Bloom

    In the graph, drag in the TripleBilinearLerp material function you created in an earlier step.

User Scene Textures for Post Process Materials(4/5) - 图3

Add a **Scene Texture** input data expression. In the **Details** panel, set **Scene Texture Id** to **PostProcessInput0**.

The PostProcessInput0 is the same as SceneColor but for post process materials.

Connect the **Color** output of the **SceneTexture:PostProcessInput0** node to the **A** input of the **TripleBilinearLerp** material function node.

User Scene Textures for Post Process Materials(4/5) - 图4

Add two **User Scene Texture** nodes. For each, set the following in the Details panel:

User Scene Textures for Post Process Materials(4/5) - 图5

  1. User Scene Texture: This feeds in the half-res and quarter-res user scene textures. Name one HalfC and the other QuarterC.
  2. Filtered: Checked
  3. Clamped: Checked

Connect the Color output of the UserSceneTexture:HalfC node to the B input of the TripleBilinearLerp node. Connect the Color output of the UserSceneTexture:QuarterC node to the C input of the TripleBilinearLerp node. In the graph, add a Constant node. Leave its value 0.

Connect the **Constant** to the **Alpha** input of the **TripleBilinearLerp** node.

This ensures the material will compile before moving onto the next section of this guide.

Connect the TripleBilinearLerp output to the Emissive Color input on the main material node. Click Apply to compile the material.

You should have something that looks like this now in the material graph below:

User Scene Textures for Post Process Materials(4/5) - 图6 In the Preview window, you may notice that there is a Red: Missing Input error message for the HalfC user scene texture input in the QuarterA material instance. This error happens because QuarterA is using the HalfC input before it’s actually been written. The Preview window isn’t capable of handling multi-level dependencies. But, you can fix this issue manually by setting priorities for some of the passes in the materials.

User Scene Textures for Post Process Materials(4/5) - 图7 To set the material priorities, follow these steps:

  1. Open the quarter-res passes for QuarterA, QuarterB, and QuarterC.
  2. In the Details panel for each of these material instances under the Post Process Overrides, check the box next to Blendable Priority.
  3. Set the Blendable Priority to 1 for each quarter-res instance. User Scene Textures for Post Process Materials(4/5) - 图8
  4. Save and Close each material instance.
  5. Open the BlurApply material.
  6. In the Details panel, set the Blendable Priority to 2. User Scene Textures for Post Process Materials(4/5) - 图9
  7. Click Apply to compile the material.

In the Preview window, the error message should be resolved, like the example below. This change makes it so that all the passes run after the half-res passes, guaranteeing that the half-res output has been created before it’s needed.

User Scene Textures for Post Process Materials(4/5) - 图10

Adding Variable Blur to the Material with Parameters

In the previous section, a Constant value was used to compile the material and get a result. However, we can use that Alpha input with some logic to actually vary the blur across the screen with some unblurred parts in the middle of the screen, medium blurred part around the screen, and heavier blurred outer edge of the screen to create this variable blur effect.

  1. Delete the Constant node plugged into the Alpha input of the TripleBilinearLerp node.
  2. Drag off the Alpha input on the TripleBilinearLerp node and add a Multiply node.
  3. Drag off the A input of the Multiply node and add a Length expression.
  4. Drag off the input of the Length node and add a Subtract node.
  5. On the Subtract node, set the value of B input to 0.5. This moves the location of the blur in screen space to the center of the frame.

Drag off the A input of the Subtract node and add a Screen Position node. Click Apply to compile the material.

Your graph should look similar to this now:

User Scene Textures for Post Process Materials(4/5) - 图11 Adjust the value for the B input values on the Multiply of the Alpha to control the intensity of the blur happening on screen.

User Scene Textures for Post Process Materials(4/5) - 图12

Alpha Multiply: 1.0 Alpha Multiply: 1.5 Alpha Multiply: 2.0

You can create an area at the center of the screen where no blur is happening by adding a Subtract node before the Multiply node for finer control of this effect.

User Scene Textures for Post Process Materials(4/5) - 图13 Incrementally adjusting the value of B on the Subtract node scales the area at the center of the screen where no blur is happening.

Subtract: 0.0 (No Effect) Subtract: 0.1 Subtract: 0.25

To learn how you can set up some material logic to visually inspect where blur is being applied to the screen with this effect, see the Applying Color to Debug the Material Effect section of this page.