Hello!
I wonder if anyone knows about theory on how to properly mask out in-front objects from a distortion shader.
If i knew that only a certain surface would be distorted, for example the ground, or below water, then I could possibly use grabpass alpha to mask out what should be distorted.
But what if I have a situation where I have a heat distortion in the center, and a ring of pillars, and the camera outside the pillars.
Then I would like to distort the pillars behind the heatsource, but not the pillars in front.
When I move the camera around, the pillars previously behind would be in front, and would thus not be used in the distortion.
How is this normally done? I suppose I would start with a z difference approach, and store the z-value in the grabpass alpha, then compare this value in the distortion.
But, if there are other proven methods, I’d love to hear about them. 
Thanks!
Kjetil
replacement shader RendertType=“XXX” of course,you can define your own tag ,like “MyDistort”=“Do it”, MyDistort"=“Ignore it”, and so on
then use it in setreplacementshader(,“MyDistort”)
Using depth difference is the easiest way i think, you can see in the ProWater4 they use depth difference to mask the grab pass
Meh, you are correct, the object infront bleeds into the distorted object.
This is solvable when I know that only a certain object will be part of the distortion, or when something will never be part of the distortion. For example the character.
It’s fixed by using the alpha in the grabpass, and then you just do a lerp between a non-distorted grabpass, and a distorted version of it. Use the distorted alpha to lerp. Here the alpha is predefined, and I suppose I should expand this system to also include the zvalue (unless somebody have another idea).
kjetil
rea, thanks for the tip!
then I at least know where I can find some more info 