- Home /
How to first draw all objects using one pass, then using another pass?
I'm writing a refraction shader that in a first pass renders the backfacing triangles of an object, then a grabpass is performed, and then the front facing triangles are drawn using the grabbed texture. For a single object this already works very well and gives good results.
Now, there will be many objects in the scene using this shader (but they can't be batched together as they use different shader properties and textures each, and the textures are too big to be combined into an atlas) - but I do not want to perform an expensive fullscreen grabpass for each object drawn. What I want to do is:
render all objects using pass0 (back facing triangles)
perform one grabpass
render all objects using pass1 (front facing triangles)
How can I achieve this? I know that 'Grabpass' has a mode in which the grabpass is only performed once, but this is not useful in my situation since then this grabbed texture would contain only the backfacing triangles of the very first object that calls the grabpass. I will need the grabpass texture to contain all backfacing triangles of all the objects using this shader.
One way I see is to split the passes into two separate materials, duplicate each object (one clone with each of the materials), fiddle with the renderqueue of the materials to ensure first all material0 objects are drawn and then all material1 objects, and in the material1 shader perform a grabpass that is shared among all objects. But duplicating the objects and splitting the shader into two shaders doesn't seem so elegant.
Anyone sees a better solution to this?
Your answer
![](https://koobas.hobune.stream/wayback/20220613102936im_/https://answers.unity.com/themes/thub/images/avi.jpg)