Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Return multiple outs from a shader

Discussion in 'High Definition Render Pipeline' started by Rob-Clouth, Sep 24, 2019.

  1. Rob-Clouth

    Rob-Clouth

    Joined:
    Jun 19, 2013
    Posts:
    3
    in 2019.3 you can now add custom post-processing shaders. I'm trying to render to two outputs in the shader.
    However, unlike what I've read in various posts, I can't change the return type of the CustomPostProcess(Varyings input) function to be a struct instead of a float4.
    It fails to compile with:
    cannot convert from 'struct Targets' to 'float4' at line 164 (on metal)

    The Targets struct looks like this:
    struct Targets
    {
    float4 target0 : SV_Target0;
    float4 target1 : SV_Target1;
    };

    My postprocessor class looks like this:

    public override void Setup()
    {
    if (Shader.Find("Hidden/Shader/Test") != null)
    material = new Material(Shader.Find("Hidden/Shader/Test"));

    textures = new RTHandle[] { RTHandles.Alloc(new Vector2(1, 1), 1, DepthBits.Depth8), RTHandles.Alloc(new Vector2(1, 1), 1, DepthBits.Depth8) };
    textureIds = new RenderTargetIdentifier[] { textures[0].nameID, textures[1].nameID };
    }

    public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle source, RTHandle destination)
    {
    if (material == null)
    return;

    // setting the uniforms here
    material.SetTexture("_InputTexture", source);
    HDUtils.DrawFullScreen(cmd, material, textureIds, textures[0]);
    }
     
  2. Rob-Clouth

    Rob-Clouth

    Joined:
    Jun 19, 2013
    Posts:
    3
    Oh dear. I hadn't set the return type to Targets...oops.