- Home /
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)?
Answer by MakeCodeNow · Oct 08, 2014 at 04:40 AM
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).
That makes sense. I got a working example and passed in the info using render textures. I guess my final question would be: is there a more elegant or drag-and-drop solution to make a material shader that doesn't require a C# / JavaScript counterpart? Thanks! :)
Not that I'm aware of. Some script somewhere has to bind those textures to the right slots for the material.
PS - Please mark answer as accepted.
Cool. Thanks for the answer. I've got the effect I want. Just isn't as clean as I was hoping for. :) I was thinking it would make it difficult to work with on the asset store.
I was waiting to see if any additional answers came in. Accepting. Cheers.