Announcement

Collapse
No announcement yet.

Radial Blur PostProcess Material

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

    #61
    This works great, but how can I access a post process material in c++ and change its values at runtime? I can get the PostProcessVolume in c++, but I can't find a way to get the materials from it.

    If it can't be done in c++, is there a way to do that via blueprint? Maybe I can then affect this blueprint via c++.

    I want to essentially change the blur strength over time.

    Edit: I figured it out. I learned about parameter collections. You can set the post process material parameters as collection parameters instead. You can access these collection parameters from c++.

    Code:
    UMaterialParameterCollection* col = LoadObject<UMaterialParameterCollection>(nullptr, TEXT("MaterialParameterCollection'/Game/.../Materials/RadialBlurParamCollection.RadialBlurParamCollection'"));
    if(col)
        UKismetMaterialLibrary::SetScalarParameterValue(GetWorld(), col, TEXT("BlurAmount"), myVariable);
    Last edited by ItBurn; 08-23-2017, 06:42 PM.

    Comment


      #62
      Originally posted by ItBurn View Post
      This works great, but how can I access a post process material in c++ and change its values at runtime? I can get the PostProcessVolume in c++, but I can't find a way to get the materials from it.

      If it can't be done in c++, is there a way to do that via blueprint? Maybe I can then affect this blueprint via c++.

      I want to essentially change the blur strength over time.

      Edit: I figured it out. I learned about parameter collections. You can set the post process material parameters as collection parameters instead. You can access these collection parameters from c++.

      Code:
      UMaterialParameterCollection* col = LoadObject<UMaterialParameterCollection>(nullptr, TEXT("MaterialParameterCollection'/Game/.../Materials/RadialBlurParamCollection.RadialBlurParamCollection'"));
      if(col)
      UKismetMaterialLibrary::SetScalarParameterValue(GetWorld(), col, TEXT("BlurAmount"), myVariable);
      A couple of comments, follow the Epic coding standards and make sure you have proper braces. Also use static const FName NAME_BlurAmount(TEXT("BlurAmount")); rather that passing the string in directly, it runs 1000x faster IIRC. You also want to cache the MPC and not load it all of the time.

      Comment


        #63
        Originally posted by Kory View Post

        A couple of comments, follow the Epic coding standards and make sure you have proper braces. Also use static const FName NAME_BlurAmount(TEXT("BlurAmount")); rather that passing the string in directly, it runs 1000x faster IIRC. You also want to cache the MPC and not load it all of the time.
        That's just quick code I was writing to debug this thing, but thanks for the input! We often forget the cost of creating new strings. I won't follow Epic's standard though

        Comment


          #64
          Originally posted by Dorian000 View Post
          Got this working in VR by multiplying the effect by two, one for each eye then mapping it all in UV space from 0 to 2.
          Hi, Dorian000, Would you like explain more about how to handle radial blur in VR ?
          Thank you.
          Last edited by elliot.uj; 09-11-2017, 03:53 AM.

          Comment


            #65
            But How Do I Use For Stuff Like Lets Say I Am Dashing And At A Certain Speed The Same Effect As You Showed Happens So whats the steps ?

            Comment


              #66
              Hello guys. Thanks for this method. I used radial blur for android in 4.16 version and this worked cool, but after 4.17 This material not work. I have crash in my mobile (galaxy S8).

              Comment


                #67
                The material doesn't want to work in my case. I have the following problem : undeclare identifier 'View_ViewSizeAndSceneTexelSize'
                Any idea what I did wrong ?

                By the way I'm using ue4.18

                Comment


                  #68
                  Hi guys !

                  I can't get it to work. There is a problem with the HLSL code in ue4.18. It says there is an unideclared identifier View_ViewSizeAndSceneTexelSize....

                  Any Idea what could have replaced that identifier in the latest versions of unreal engine ?

                  Comment


                    #69
                    I too am also getting the same error in 4.18.
                    VR Virtual Keyboard Marketplace Asset: https://www.unrealengine.com/marketp...rtual-keyboard

                    Comment


                      #70
                      Hey all, here's what I use in 4.18. Pretty much the same result. Probably need to factor in texel size though.

                      Code:
                      float2 ScreenMult = View.BufferSizeAndInvSize.xy / ViewSize;
                      int TexIndex = 14;
                      float samples[10] = {-0.08,-0.05,-0.03,-0.02,-0.01,0.01,0.02,0.03,0.05,0.08};
                      float2 dir = ScreenMult * float2(0.5,0.5) - ScreenUV;
                      float4 sum = SceneTextureLookup(ScreenUV, TexIndex, false);
                      float2 pos = float2(0.0,0.0);
                      for(int i = 0; i<10; i++)
                      {
                          pos = ScreenUV + dir * samples[i] * BlurDist;
                          max(min(pos, ScreenMult * float2(1.0, 1.0)), float2(0.0,0.0));
                          sum += SceneTextureLookup(pos, TexIndex, false);
                      }
                      sum *= 1.0/11.0;
                      return sum;

                      Comment


                        #71
                        TheJamsh The function SceneTextureLookup gives me an error, how can i fix it?

                        Comment


                          #72
                          Make sure you're in version 4.18 and above, and ensure it's a post process material.

                          Comment


                            #73
                            I used it on 4.18 and worked well. I only had to change ViewSize to View.ViewSizeAndInvSize.xy on line 1.
                            Here is complete list of ViewUniformShaderParameters parameters: https://docs.unrealengine.com/latest...ers/index.html

                            Complete code after change, remember to add ScreenUV, Tex and BlurDist inputs:
                            Code:
                            float2 ScreenMult = View.BufferSizeAndInvSize.xy / View.ViewSizeAndInvSize.xy;
                            int TexIndex = 14;
                            float samples[10] = {-0.08,-0.05,-0.03,-0.02,-0.01,0.01,0.02,0.03,0.05,0.08};
                            float2 dir = ScreenMult * float2(0.5,0.5) - ScreenUV;
                            float4 sum = SceneTextureLookup(ScreenUV, TexIndex, false);
                            float2 pos = float2(0.0,0.0);
                            
                            for(int i = 0; i<10; i++)
                            {
                                pos = ScreenUV + dir * samples[i] * BlurDist;
                                max(min(pos, ScreenMult * float2(1.0, 1.0)), float2(0.0,0.0));
                                sum += SceneTextureLookup(pos, TexIndex, false);
                            }
                            
                            sum *= 1.0/11.0;
                            return sum;
                            Last edited by sp01sh; 02-15-2018, 10:48 AM.
                            Github: sp0lsh
                            Twitter: @_spolsh

                            Comment


                              #74
                              Has anyone got this material working in 4.19?

                              The viewport window seems to double up when the viewport isn't scaled to 100% size.

                              I thought it might have something to do with the new changes to the ScreenPosition/SceneTexture nodes.

                              Comment


                                #75
                                Originally posted by melonFury View Post
                                Has anyone got this material working in 4.19?
                                Try this:
                                Code:
                                const float2 ScreenMult = View.ViewSizeAndInvSize.xy * View.BufferSizeAndInvSize.zw;
                                
                                const int TexIndex = 14;
                                const float Samples[11] = {-0.08,-0.05,-0.03,-0.02,-0.01,0,0.01,0.02,0.03,0.05,0.08};
                                
                                float2 dir = float2(0.5,0.5) - ViewportUV;
                                float4 sum = float4(0.0, 0.0, 0.0, 0.0);
                                for(int i = 0; i<11; i++)
                                {
                                    float2 pos = ViewportUV + dir * Samples[i] * BlurDist;
                                    pos = clamp(pos, float2(0.0,0.0), float2(1.0, 1.0));
                                    sum += SceneTextureLookup(pos * ScreenMult, TexIndex, false);
                                }
                                
                                return sum / 11.0;
                                Last edited by moadib; 03-19-2018, 06:26 AM.

                                Comment

                                Working...
                                X