- Home /
How to make a custom GrabPass-like sampler2D in MRT shader?
I only know the basics of writing shaders, so I don't have a clue how I can make something similar to Unity's Grabpass in that a RenderTexture that is currently write only, can be changed to readonly and used in a sampler2D in a shader.
I set two render targets to my camera, and in one shader write to both targets, but in another shader I write to only one but need to read from the other one. I tried setting the rendertexture I need to read from to a material property, but even though the second shader doesn't currently touch the rendertexture, I believe the rendertexture is still write only because reading from it returns nothing.
I originally used GrabPass, but it doesn't work nicely with different camera viewport rects, as well as although it did work, it didn't make much sense to me because not only was I writing to rendertextures not the "screen" (GrabPass is supposed to makes a sampler of the screen area about to be drawn into, even though I wasn't writing to the screen directly currently), but I was using 2 rendertextures as targets but it only can grab from one, the first, so I had to change the order of the rendertextures so that the GrabPass sampler grabs from the correct first rendertexture. Also if at all possible I would like to avoid the supposed cost of GrabPass because I don't think I would need to make a new texture, just temporarily make one of the rendertextures read only and use it in a sampler2d, but again I know next to nothing about this.