Home Unreal Engine

RealTime Texture Blurring in UDK

polycounter lvl 11
Offline / Send Message
Ryan Smith polycounter lvl 11
Hello my fellow nerdy polycounters,

I want to share a quick function i just added in a material of mine that enables you to sample a texture of your choosing and apply a blur to it. The code is similar to a guassan blur, except less expensive (relatively).

The total function unfortunately costs a whopping 24 extra instructions =(.

Anyways, i just thought it would be cool to share it, because it is applicable to cube maps and reflection maps, and it may help you get a cool look that you're going for in your UDK renders.


The way it works is pretty simple, you have to make 9 duplicates of your texture parameter, and offset each one of the UVs by -1, and 1 on the X and Y coordinates. so you have a matrix of 9 coordinates, including 0.

then you add all the samples together and divide by 9, and you get your blur.

the number yo offset the UVs by is the "Radius" or the parameter i'm playing with in the screenshots. it should change depending on the size of the texture you are using.

Network -
ihydC.jpg


In Game =
y2qjS.jpg

Let me know what fellers think :D

Replies

  • JordanW
    Options
    Offline / Send Message
    JordanW polycounter lvl 19
    nice, one thing you should try is jittering your samples, create a noise texture and use it to modulate your samples, it could help break up seeing lines in the blurring.
  • Ryan Smith
    Options
    Offline / Send Message
    Ryan Smith polycounter lvl 11
    Wow that's actually a really great idea, i didn't think of doing it like that!

    If i were to use 3 different mix maps to jitter the texture, then just average out those samples, it would save a butload of instructions, while still giving a (pretty decent?) blur.

    this is something i'm going to have to try!
  • moose
    Options
    Offline / Send Message
    moose polycount sponsor
    The material editor, is not a big truck!

    nice stuff :)
  • Ryan Smith
    Options
    Offline / Send Message
    Ryan Smith polycounter lvl 11
    moose wrote: »
    The material editor, is not a big truck!

    nice stuff :)

    I'm glad someone caught that reference. :D
  • e-freak
    Options
    Offline / Send Message
    bringing this up again as im currently looking for a shader solution to do this: blur each pixel individually (get the average color of x pixel around him)? is that possible? (i'm trying to apply a greyscale map to the texture to blur certain areas more than others)

    with the solution above i think it's only possible to blur everything and then mix between the two textures? also above 1 pixel it seems to only take 1 sample and looks more like an offset picture rather than a blur :/
  • Computron
    Options
    Offline / Send Message
    Computron polycounter lvl 7
    Not sure what this is usefull for, can't you just use a lower mip?
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    You can, but you need to setup a separate custom node for Mip-Dropping.

    The irony is, the more useful texture for this feature (like Cubemaps and Normal Maps) cannot use the custom node without breaking. Normals break around the tangents (so you cannot use the Mip/Blur technique for SSS) and Cubemaps are only read out as 2D instead of 3D textures.

    So close, yet so far.
  • Vailias
    Options
    Offline / Send Message
    Vailias polycounter lvl 18
    Edit: The "offset picture" thing is what a box blur kinda is. :) so yeah over a very small range that is exactly what it looks like.

    I built a realtime controllable bilinear filtering material function to solve this very problem. It still has some artifacting here and there at the more blurry settings, but it is controllable at a per pixel level. Also it kinda works like a supersampler with a sample number higher than the pixel resolution of the image.

    here: Material function package is updated. Has some examples and some new stuff. Still no working cubemap blur, but the bilinear filtering mat function is working just fine. There's an example material in there for how to use a greyscale map as a control texture for selective blur via the bilinear filter.

    Download this
    ControlledBlur.jpg
    ControlledBlur2.jpg
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    As usual, Vailias pretty much kicks arse.
  • King Mango
    Options
    Offline / Send Message
    King Mango polycounter lvl 10
    What node offsets the image? I can't quite make out the text in the image. I've got a normal map of a block pattern that is basically half a block off my diffuse. I made a block pattern greeble in Maya a few weeks ago and used it on a plain tiling stone tex, then today I decided to cut out pieces of stone from 14 different textures and paste in blocks. I could go back into PS and offset the image by 128 px, but I can't for the life of me figure out how to just move one or the other over the amount I need.

    I've looked at every node in the editor and no name pops out as being the one I need. Tried it old school with a panner node at the X speed to the offset and hooked a constant with a value of zero into the time of the panner but that doesn't do it. Doesn't shift at all.
Sign In or Register to comment.