Search Unity

Whats the correct way of declaring and using TextureParameter in a Custom PostProcessing Effect?

Discussion in 'Image Effects' started by LeapDev1, Feb 26, 2019.

  1. LeapDev1

    LeapDev1

    Joined:
    Feb 2, 2018
    Posts:
    2
    Hey guys. I´m creating a Custom Post Processing Effect that requires an extra texture in order to work but I´m having weird problems when trying to use the effect in the editor.

    First , I get lots of null value errors pointing to that texture parameter , sometimes they go away once I select the texture I want to use in the PostProcessing profile editor but other times the error just stays there.

    However , the worst problem I´m having is that the config of the effect randomly gets deleted from the profiles. This often happens when I change the scene but It can also happen when I do as little as clicking the another object in order to inspect it.

    I don´t know if Im declaring the TextureParameter wrong or I´m missing something , so I´m leaving the code here for you to inspect it.

    Code (CSharp):
    1. [Serializable]
    2. [PostProcess(typeof(TextureOverlayRenderer), PostProcessEvent.BeforeStack, "Custom/TextureOverlay")]
    3. public sealed class PostProcessingEffect_TextureOverlay : PostProcessEffectSettings
    4. {
    5.     [Tooltip("Texture To Apply")]
    6.     public TextureParameter overlayTexture = new TextureParameter();
    7.     [Range(0f, 1f), Tooltip("Effect Opacity")]
    8.     public FloatParameter opacity = new FloatParameter { value = 0.5f };
    9.     [Range(0f, 1f), Tooltip("Original Pixel Blending")]
    10.     public FloatParameter blending = new FloatParameter { value = 0.0f };
    11.     [Tooltip("Texture Rows ")]
    12.     public IntParameter rows = new IntParameter { value = 1 };
    13.     [Tooltip("Texture Colums ")]
    14.     public IntParameter colums = new IntParameter { value = 1 };
    15.     [Range(0.0f, 60.0f), Tooltip("Animation Speed ")]
    16.     public FloatParameter AnimationSpeed = new FloatParameter { value = 1.0f };
    17.     [Tooltip("Uses Negate Effect Texture ")]
    18.     public BoolParameter usesNegateTexture = new BoolParameter { value = false };
    19.     [Tooltip("Negate Effect Texture")]
    20.     public TextureParameter negateEffectTexture = new TextureParameter();
    21.     [Range(0f, 1f), Tooltip("Negate Texture Alpha Cutout")]
    22.     public FloatParameter alphaCutout = new FloatParameter { value = 0.0f };
    23.     [Range(0f, 1f), Tooltip("Negate Texture Blend")]
    24.     public FloatParameter negateBlend = new FloatParameter { value = 0.0f };
    25.  
    26.     public override bool IsEnabledAndSupported(PostProcessRenderContext context)
    27.     {
    28.         return enabled.value && (overlayTexture != null) && (opacity > 0) &&
    29.             (
    30.             (usesNegateTexture == true && negateEffectTexture != null)
    31.             ||
    32.             (usesNegateTexture==false && negateEffectTexture==null)
    33.             );
    34.     }
    35. }
    Hope you can help me
     
    kkrg001 likes this.
  2. yl_tys

    yl_tys

    Joined:
    Jan 22, 2018
    Posts:
    1
    // Reference (UnityPackage: Post Processing Texture Overlay)
    public sealed class PostMask : PostProcessEffectSettings
    {
    public TextureParameter maskTex = new TextureParameter { value = null };
    }

    public sealed class PostMaskRenderer : PostProcessEffectRenderer<PostMask>
    {
    public override void Render(PostProcessRenderContext context)
    {
    var sheet = context.propertySheets.Get(Shader.Find("Hidden/tys/PostMask"));

    var imageTexture = settings.maskTex.value == null? RuntimeUtilities.whiteTexture: settings.maskTex.value;
    sheet.properties.SetTexture("_MaskTex", imageTexture);
    context.command.BlitFullscreenTriangle(context.source, context.destination, sheet, 0);
    }
    }