Blur an image in UnrealEd (UE3) via expressions,

Hello,

I’m just curious if there’s a possible way to blur an image via the UnrealEd material expressions. Thanks for your time.

(i.e.-blur an image, blur a screen-space effect, etc.)

(this is with UnrealEd in UT3)

Here is a way to do that:

This is a very basic setup where the image is only offset horizontally and vertically.
For a higher quality blur you might want to duplicate this tree and use diagonal offsets
as well. For even higher quality you can introduce halved offsets.

The multiplier node is there only for workflow reasons.

Most blurs are done with a sepratable filter where you blur your horizontal then the vertical, also they often use hardware filtering/ downscaling to help with the effect - a good examole being bloom. I am assuming this can be all done in unreals shader editor? This is something easy to write in code and will look messy in a shader graph. Looking at the example above is not quite how I would do it (I wouldnt use lerps for example)

Thanks for the shader workflow.

If there is another way, that would be great as well, as multiple solutions to the problem are always helpfull.

It’s best if you do it in code as mikiex mentioned, either that or do the lower resolution trick (works greats across the board, we used it to get blurry cube maps by using the mips)

If you want to truly do it in code it’s the cheaper way of doing a true blur, I don’t remember the specifics but it was something about the texture already being loaded in memory and in the right place so when you do a for loop with several texture calls it’s not that bad.

Mikiex: How would you do it? For some effects I use a node tree of
16 branches, so even a simple optimization would go a long way.

Blurry cubemaps are cool indeed. Too bad the stock Unreal engine
provides no direct access to mip levels. :\ So if you have to use
UT3 then you are pretty much stuck with using two cubemaps.

To do a traditional blur you need access to render targets, which are not typically exposed to shaders.

(RenderTargetName)
[ul]
[li]Render your scene to a (A).
[/li][li]Blur (A) only horizontally to (B).
[/li][li]Blur (B) only vertically back to (A).
[/li][/ul]

This allows you to tap (HorizontalTaps + VerticalTaps), instead of (HorizontalTaps * VerticalTaps) like you would have to do to get the same results in a single pass. You can think of the first pass as caching the values for you.

[QUOTE=Zoltan;3412]Mikiex: How would you do it? For some effects I use a node tree of
16 branches, so even a simple optimization would go a long way.

Blurry cubemaps are cool indeed. Too bad the stock Unreal engine
provides no direct access to mip levels. :\ So if you have to use
UT3 then you are pretty much stuck with using two cubemaps.[/QUOTE]

I don’t know what is exposed in the Unreal editor,

Instead of the lerps you can just add all your textures and divide your final result by the number of samples you have taken. So if you sample the texture 4 times, you can divide by 4. (a+b+c+d)/4. A Lerp used to be 4 instructions, but I don’t know if its faster these days.

About the picking lower mips, are there any alternative nodes for sampling textures? Something with bias or Lod in the name? Having a quick search it looks as though they have a lod bias option on the texture, if they do it that way its a bit of a shame - unless you can get to the constant and change it on the fly it will probably be fixed. Is there any scope for hacking the shaders?

In an “Opaque - Unlit” base material the “Lerp” method costs 13 instructions
and the “Add, Divide” costs 14. I’ve never written actual shader code, but it
seems that nowadays Lerp can be done in one step.

And yes, the LOD bias property of a texture asset is fixed. Unreal’s material
editing and management is very easy, convenient, but also watertight.
Any change would require serious effort, as I was told by our lead
programmer.
Fortunately in the most recent build there is a node which allows the user to
enter custom HLSL code. I haven’t had the chance to use that build yet, but
this move opens up new possibilities.

I didn’t know about the HLSL build, what build is it? April?

Changing the HLSL isn’t that hard, specially for a lead programmer, it’s fairly easy to write a custom node that does what you want.

May’09 QA Build:
" ‘Custom’ material shader node, for implementing HLSL code from within the
material editor. " (UDN article, needs login.)