Announcement

Collapse
No announcement yet.

So Blurred glass material is impossible in Unreal Engine 4?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • replied
    Ok, I found a way to get rid of the halo.

    Click image for larger version

Name:	Blur_No_Halo.jpg
Views:	1
Size:	121.2 KB
ID:	1078790

    So now I have 2 problems to fix:

    1 - The skySphere is not affected by DOF. I don't think it's the most difficult part - but I didn't find out how to tweak it's material the proper way).

    Click image for larger version

Name:	SkySphere_No_Blur.jpg
Views:	1
Size:	36.9 KB
ID:	1078792

    2 - With my actual setup, actors are always or never blurred.

    Click image for larger version

Name:	Third.jpg
Views:	1
Size:	30.5 KB
ID:	1078793

    So, in the pic above, my character which is behind the window, should be blurred, but he is not.
    Last edited by EdWasHere; 07-02-2015, 03:11 AM.

    Leave a comment:


  • replied
    The above halo problem is a pretty standard problem. Even the approach I did has that same problem.

    The custom node version can fix this problem though by comparing depths and rejecting a sample if it came from a depth that is greater than the window. But then you have to do something like use an old color or use no color, which means you still have a halo of some kind, like a halo of no blur at all. Clever use of temporalAA may help solve it. I haven't tried that yet but it might be fun to mess around with.

    Leave a comment:


  • replied
    In this example, I used a simple plane instead of a cube, I unchecked "Receive Decals" on the skeletal mesh and used SceneTexture:decalmask to better define where the blur is applied.
    And it works but the problem is that I can't get rid of the "blurry halo" around the character:

    Click image for larger version

Name:	Blurring_Glass_WIP_5.jpg
Views:	1
Size:	25.1 KB
ID:	1076587

    Such a shame I can't exclude the character from beeing affected by depth of field, as meshes with translucent materials can be.
    Or is there an option here?
    Last edited by EdWasHere; 07-02-2015, 04:22 AM.

    Leave a comment:


  • replied
    Nevermind figured it out. You need to set the material to "Before Tonemapping" down in the "post process material" settings.

    This is a really nice basically free way to get controllable blur. The only problem with this technique is you will give up DOF elsewhere in the scene since this isn't doing a separate pass its simply blending to a scene without the post process for outside the window.

    Leave a comment:


  • replied
    I tried your setup as well and for some reason the DOF blur shows up even when I just plug in the straight "SceneTexture:SceneColor" sample or PostProcessInput0. Were you just defining DOF in a post process volume or was there something else going on?

    In terms of why the custom node didn't work, is what ue4 version are you in? What did the output of the node give? Any errors? A pic of the material graph would be useful.

    Leave a comment:


  • replied
    Even with these tweaks, it doesn't work for me.
    Wondering what I'm missing here.
    What was the map you tested it on?
    Does it work for someone else?
    Last edited by EdWasHere; 05-16-2015, 11:07 PM.

    Leave a comment:


  • replied
    Nice setup

    You could try using CustomDepth to create masks for the objects in your scene to use.

    In terms of why the other approach didnt work, did you have scenecolor hooked up to opacity somewhere? You also need to make sure that the values for Distance, Distance Steps and Radial Steps are all above 1 or nothing happens. Also just set DistanceMask to 1 to rule that out.

    Leave a comment:


  • replied
    I reproduced your material graph and pasted the second code in the custom node.
    I checked it multiples times but I can't get it to work.
    Can't figure out what the problem is.
    Do you apply this material to a plane, a cube or a sprite? Does it matter?
    Are there important settings you didn't indicate?

    Othewise: no doubt using a shader is the way to achieve this blurring effect but I have no skills to do it.
    So I tried to achieve my limited gaussian blur DOF effect in a post process material as a first step.
    Quite simple, in fact. Here is the graph, if it can be useful to someone:

    Click image for larger version

Name:	Limited_Gaussian_DOF_Graph.jpg
Views:	1
Size:	46.7 KB
ID:	1076518

    And the texture I used as a mask in the material:

    Click image for larger version

Name:	Screen_Mask.jpg
Views:	1
Size:	9.0 KB
ID:	1076519

    And here is what i get in game:

    Click image for larger version

Name:	Blurring_Window.jpg
Views:	1
Size:	58.5 KB
ID:	1076520
    Attached Files
    Last edited by EdWasHere; 07-02-2015, 03:24 AM.

    Leave a comment:


  • replied
    Originally posted by Jandar-man View Post
    Hi there - i didn't understand which file (and file format) i must edit or create to put these HLSL code to it? And in which directory it must be stored?
    You have to add a "Custom" node, and paste the HLSL code there (and add the appropriate inputs).

    Leave a comment:


  • replied
    Hi there - i didn't understand which file (and file format) i must edit or create to put these HLSL code to it? And in which directory it must be stored?

    Leave a comment:


  • replied
    turns out the tempAA dither thing really needs the dither texture in addition to the math pattern offset. Makes the spec patterns much smoother except at very far distances.

    I would have just used the DitherTemporalAA material node but for some reason plugging it in consistently caused a crash so I basically had to put all the code from that function into here.

    float3 CurColor;
    float2 BaseUV = MaterialFloat2(ScreenAlignedPosition(Parameters.ScreenPosition).xy);
    float2 NewUV = BaseUV;
    float StepSize = Distance / (int) DistanceSteps;
    float CurDistance;
    float2 CurOffset;
    float TwoPi = 6.283185;
    float Substep;
    float2 ScenePixels=View.RenderTargetSize*BaseUV;
    ScenePixels+=View.TemporalAAParams.r;
    float2 RandomSamp = ((uint)(ScenePixels.x) + 2 * (uint)(ScenePixels.y)) % 5;
    RandomSamp+=TempAARandom+Texture2DSample(Tex,TexSampler,ScenePixels);
    RandomSamp/=6;
    RandomSamp-=0.5;
    RandomSamp*=TempAARandom;


    int i;
    if (DistanceSteps<1)
    {
    return DecodeSceneColorForMaterialNode(NewUV);
    }
    else
    {
    while ( i < (int) DistanceSteps)
    {

    CurDistance += StepSize;
    for (int j = 0; j < (int) RadialSteps; j++)
    {
    Substep++;
    CurOffset.x = cos(TwoPi*((RandomSamp+Substep) / RadialSteps));
    CurOffset.y = sin(TwoPi*((RandomSamp+Substep) / RadialSteps));
    CurOffset *=DistanceMask;
    NewUV.x = BaseUV.x + (CurOffset.x * (CurDistance));
    NewUV.y = BaseUV.y + (CurOffset.y * (CurDistance));
    CurColor += DecodeSceneColorForMaterialNode(NewUV);
    }
    Substep+=0.618;
    i++;
    }
    CurColor = CurColor / ((int)DistanceSteps*(int)RadialSteps);
    return CurColor;
    }
    Click image for larger version

Name:	SceneBlur_Mat2.JPG
Views:	1
Size:	45.8 KB
ID:	1076472

    Leave a comment:


  • replied
    That's so cool! Blows my mind what can be done in realtime these days.

    Leave a comment:


  • replied
    With the TempAARandom set to 0 you can see some cool artifacts in specular highlights using various values of "Radial Steps"

    3 radial steps:


    3.1 Radial steps causes a spiral instead:


    3.3 Radial steps causes a sort of fibonacci spiral:


    The tempAA random fixes some of this up but not all of it without using tons of samples.

    I think there is way better way of using TempAA here this was just an experiment.

    Leave a comment:


  • replied
    Coincidentally last "Epic Friday" I messed around with doing a radial style blur custom node. It only took 2 line changes to make it work with SceneColor like you want.

    I added a distance mask as well so you can have the blur get slightly less as objects get closer to the glass.

    This is probably not very optimized, I just barely got TempAA dithering working on it but the settings are very fiddly to fix the specular artifacts.

    Click image for larger version

Name:	SceneBlur.JPG
Views:	1
Size:	40.7 KB
ID:	1076470

    It requires that you hook up the SceneColor node somewhere in opacity otherwise the compiler won't recognize the texture.

    The material graph:
    Click image for larger version

Name:	SceneBlur_Mat.JPG
Views:	1
Size:	98.3 KB
ID:	1076471

    The hlsl code for the custom material node:

    float3 CurColor;
    float2 BaseUV = MaterialFloat2(ScreenAlignedPosition(Parameters.ScreenPosition).xy);
    float2 NewUV = BaseUV;
    int i;
    float StepSize = Distance / (int) DistanceSteps;
    float CurDistance;
    float2 CurOffset;
    float TwoPi = 6.283185;
    float Substep;
    float2 ScenePixels = View.RenderTargetSize*BaseUV;
    float2 RandomSamp = View.TemporalAAParams.r+ScenePixels;
    RandomSamp = ((uint)(RandomSamp.x) + 2 * (uint)(RandomSamp.y)) % 5;
    RandomSamp*=TempAARandom;
    if (DistanceSteps<1)
    {
    return DecodeSceneColorForMaterialNode(NewUV);
    }
    else
    {
    while ( i < (int) DistanceSteps)
    {

    CurDistance += StepSize;
    for (int j = 0; j < (int) RadialSteps; j++)
    {
    Substep++;
    CurOffset.x = cos(TwoPi*((RandomSamp+Substep) / RadialSteps));
    CurOffset.y = sin(TwoPi*((RandomSamp+Substep) / RadialSteps));
    CurOffset *=DistanceMask;
    NewUV.x = BaseUV.x + (CurOffset.x * (CurDistance+RandomSamp*StepSize));
    NewUV.y = BaseUV.y + (CurOffset.y * (CurDistance+RandomSamp*StepSize));
    CurColor += DecodeSceneColorForMaterialNode(NewUV);
    }
    Substep+=0;
    i++;
    }
    CurColor = CurColor / ((int)DistanceSteps*(int)RadialSteps);
    return CurColor;
    }

    Leave a comment:


  • replied
    Great, thanks again ! I'll experiment in this way.

    Leave a comment:

Working...
X