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)?
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! :)
– LovelockNot 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.
– MakeCodeNowCool. 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.
– Lovelock