Sunday, August 3, 2014

[Unreal Engine 4] Localized Post-Process Effects

One of the new features of UE4 (in comparison to UE3) is that you can access the world position of a pixel via post processing. I just realized that this makes it possible to limit post process effects to a specific areas of a level. Still you can see the effect from far away, which means the camera/player won't need to actually enter this specific area - obviously that's the main advantage over a separate post process volume.

For this tutorial I decided to describe 2 types of these "volumes" in a volume, spheres and boxes. The material graphs shown output a greyscale image which you can use to Lerp between the original scene color and a post process effect of your choice. In my example that's a simple scene desaturation.


Sphere

This is the material for a sphere shape. using 3 parameters to define the sphere position, size(radius) and transition hardness.




Box

For a box shape there are 2 different ways of setting up the material. The first one is similar to the sphere setup, defining the box shape by a center point and the (half) length of all 3 sides.

The second one defines the box by 2 opposing corner points. Think of these as the lower, front, left and the upper, rear, right vertices of a box. Please note that the softness parameter needs to be a pretty large value to take any effect, e.g. 2^16.

Setup #1

Setup #2


6 comments:

  1. with some HLSL code inside a Custom node you could actually access the World Position from a PostProcess in UDK. I could provide you the code but at this point I guess you'll have no use for it :)

    anyway it's nice to hear it comes out of the box in UE4. thanks for the tutorial too
    cheers,
    Chosker

    ReplyDelete
  2. Yeah that's true, just like you said it wasn't there out of the box. I was using a material by myself which would calculate the view space position from depth, never tried to convert this to world space though.

    ReplyDelete
  3. Hello, thanks for your tutorials :) pretty useful stuff to say the least.
    I would like to use a cube mask (like the one you show here) but also have a rotation parameter (I need to be able to align it to multiple rotations).
    Any chance you can help me figure out the math? :p

    ReplyDelete
  4. Can you use something like this with regular Post Process settings such as eye adaptation and LUT?

    ReplyDelete
  5. Could you invert this and apply postprocessing to everything except a handful of spheres (around actors)? It seems like you could.

    ReplyDelete
  6. I, erm. I don't see where to add Absolute World Position (sorry, possibly being an idiot)

    ReplyDelete