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. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    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.