Mulit-Pass Custom Shader Workflow

When making a multi-pass material shader what is the proper approach to share information between passes?

Is there a way to use a render texture as an intermediary to store information from one pass so it may be used in subsequent passes?

I’ve seen examples of GrabPass being used to read pixel information between passes. But what if you can’t encode enough information in those pixels?

I’ve also seen use of Graphics.Blit() and OnRenderImage() to output data to render textures from shaders, but this seems to be just for image effects.

Say I want to write just a basic thickness material shader.

  • First pass: Render back faces and calculate distance from camera to vertices – store information somewhere (backDistance).
  • Second pass: Render front faces and calculate distance from camera to vertices (frontDistance)
  • Subtract backDistance from frontDistance to get thickness. Render using thickness.

I could easily be misunderstanding the workflow here, but is it possible to share information between passes for a material shader (not an image effect)?

Yes. You can render each pass to a RenderTarget and then bind those render targets as textures for the material shader to use (with VPOS to get the UV coordinates into those textures for the current pixel).