How to properly declare a TextureParameter in a Custom PostProcessing Effect?

Hello guys ,
I’m having a bit of troubke when trying to make cuatom postbprocessing effects that require extra texgures . Here is my code :

[Serializable]
[PostProcess(typeof(TextureOverlayRenderer), PostProcessEvent.BeforeStack, "Custom/TextureOverlay")]
public sealed class PostProcessingEffect_TextureOverlay : PostProcessEffectSettings
{
    [Tooltip("Texture To Apply")]
    public TextureParameter overlayTexture = new TextureParameter();
    [Range(1.0f, 20.0f), Tooltip("Texture Repeat Factor")]
    public FloatParameter textureRepeatFactor = new FloatParameter { value = 1.0f };
    [Range(0f, 1f), Tooltip("Effect Opacity")]
    public FloatParameter opacity = new FloatParameter { value = 0.5f };

    public override bool IsEnabledAndSupported(PostProcessRenderContext context)
    {
        return enabled.value && (overlayTexture != null) && (opacity>0);
    }
}

public sealed class TextureOverlayRenderer : PostProcessEffectRenderer<PostProcessingEffect_TextureOverlay>
{
    public override void Render(PostProcessRenderContext context)
    {
        var sheet = context.propertySheets.Get(Shader.Find("Hidden/Custom/TextureOverlay"));
        sheet.properties.SetTexture("_OverlayTexture", settings.overlayTexture);
        sheet.properties.SetFloat("_TextureRepeatFactor", settings.textureRepeatFactor);
        sheet.properties.SetFloat("_EffectOpacity", settings.opacity);
        context.command.BlitFullscreenTriangle(context.source, context.destination, sheet, 0);
    }
}

As you can see , I´m declaring the texture and setting it to new TextureParameter(). However in editor I’m always getting erros concerning that texture. The most common one is “Argument Null Exception , Argument cannot be null. Parameter Name:Value”

I really don’t know what to do , when I move something in the effect editor or add the effect to the post processing cinemachine component those errors show up . But whem I’m in play mode they seem to go away.

Anyone?? No one??? Because of those null references the setup of the post process in every virtual camera is getting erased randomly

@InkaTorque, Have you resolve this, I think I met the same problem.

EDIT:
Found a solution to this. The sequence of steps I used is as follows:

  1. Add the TextureParameter to the *Settings class
  2. Add this post processing effect as an effect in your post processing profile.
  3. Set the texture in your post processing profile
  4. Add the sheet.properties.SetTexture(…) statement in your *Renderer class.

This is a hacky fix, but it worked for me. I could definitely see this being super tedious when using this effect across many different profiles/projects (you’ll need to comment out step 4, set the texture as in step 4, then uncomment out your comment).

I’d love to know if there is a better solution to this, however.


Original Post:
I’m getting the same issue as well. Even when I have a null check in the Render function.

No clue what’s going on.

// Reference (UnityPackage: Post Processing Texture Overlay)

public sealed class PostMask : PostProcessEffectSettings
{
    public TextureParameter maskTex = new TextureParameter { value = null };
}

public sealed class PostMaskRenderer : PostProcessEffectRenderer
{
    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);
    }
}