Grab pass render order

I’m using 2 shaders to render terrain and water and booth use grabpass. Camera is set to Forward. Terrain needs it to get more Samplers, so its splited into many passes and grabpass is used to get color data from first pass. Water use grabpass to get everything that is under it. Water should render after terrain, so itsgrabpass should get final color of the terrain.

But the issue is that sometimes waters grabpass renders before terrain shader is done and it is somehow connected with distance from camera. It looks like sometimes waters grabpass collect only first pass of the terrains shader.

I tried to use Tags “Queue” in shaders to determine which renders first, but with no success. Maybe there is a way to remove grabpass from water shader, and get color for refraction someway different.

Terrain shader:

CGPROGRAM
GrabPass
CGPROGRAM

Water shader:

GrabPass
Pass (CGPROGRAM)

Simmilar issue is when I removed water and added 1 empty pass at begin of terrain shader. Then terrains grabpass sometimes gets 2 first passes and sometimes only 1. Blue color is added at last CGPROGRAM pass.

What can cause that issue with order?

Why does the terrain shader need a grabpass? Generally terrain shaders with multiple passes just use an alpha blend to mix with the previously rendered layers.

I have shader based on shader used in old RTS game and I need it to look the same. I need to have 10 texture layers (color + normal) and blend them using 2 control textures. This is much more than 16 2dsamplers so I needed to split it to separate passes. From what i found on forums, the only good way to do it is to use GrabPass to get color from previous pass.

I’m using surface shader. In first pass i blend together all color textures with no lighting and render it to GrabPass texture. In next pass i use that data and assign it to o.Albedo and blend together normal textures.

The only way that i think it will work without grabpass is to create 2 passes in with will be 4 color and 4 normals with lighting, and I will blend them together using alpha data from 1 control texture. But then lighting will be calculated 2 times.

Grab passes are quite expensive. On older platforms or mobile, it’ll be way cheaper to do the lighting twice. On modern platforms a grab pass isn’t quite as expensive, but doing lighting twice is still probably cheaper. If you’re aiming for DX11 / OpenGL Core your better off using texture arrays to get around the texture sampler limit.