Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for additional pass #13

Closed
kenamis opened this issue Jan 29, 2020 · 2 comments
Closed

Example for additional pass #13

kenamis opened this issue Jan 29, 2020 · 2 comments

Comments

@kenamis
Copy link

kenamis commented Jan 29, 2020

Hi, is there a good example or recommendation on how to render another pass in a shader (without a new material), or another shader entirely?

I'm trying to do an unlit render of objects with a color id map on each object to a RenderTexture (to look up later), in addition to the regular lit pass. I know I could use the Graphics api to re-render all those objects, but as far as I know, that's extra unnecessary work.

In the current examples with DrawRenderers, it looks like you need to use another material, which means then I can't have per-instance texture inputs. I also can't specify another pass without specifying a material. Do I need to make a new custom pass that takes all filtered objects, reads the current shader the object and renders with a named pass?

Thanks

@kenamis kenamis closed this as completed Feb 3, 2020
@andybak
Copy link

andybak commented Feb 3, 2020

Did you close this because you solved it? If so some insight would be valuable for others.

@kenamis
Copy link
Author

kenamis commented Feb 4, 2020

Yes. It was embarrassingly simple after I started reading through the code. It's essentially exactly the same as the DrawRenderers but without the override material or pass index. The thing that was tripping me up was I had a lightmode tag in my shader. I set it to the name of my pass, which fixed the issue, but I think shouldn't need it at all for an unlit shader (I need to look in to this further).

[System.Serializable]
class ColorID : CustomPass
{
    public string passName;
    public LayerMask layerMask = -1;

    ShaderTagId shaderTagId;

    // It can be used to configure render targets and their clear state. Also to create temporary render target textures.
    // When empty this render pass will render to the active camera render target.
    // You should never call CommandBuffer.SetRenderTarget. Instead call <c>ConfigureTarget</c> and <c>ConfigureClear</c>.
    // The render pipeline will ensure target setup and clearing happens in an performance manner.
    protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
    {
        // Setup code here
        shaderTagId = new ShaderTagId(passName);
    }

    protected override void Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera camera, CullingResults cullingResult)
    {
        if (string.IsNullOrEmpty(passName))
            return;

        // Executed every frame for all the camera inside the pass volume
        RendererListDesc result = new RendererListDesc(shaderTagId, cullingResult, camera.camera)
        {
            rendererConfiguration = PerObjectData.None,
            renderQueueRange = RenderQueueRange.all,
            sortingCriteria = SortingCriteria.CommonOpaque,
            excludeObjectMotionVectors = false,
            layerMask = layerMask,
        };

        HDUtils.DrawRendererList(renderContext, cmd, RendererList.Create(result));
    }

    protected override void Cleanup()
    {
        // Cleanup code
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants