How to target what multiple shaders interact with

I have 3 materials ABC each with a different shader ABC.

Material C is the main scene, then over it blends a sprite with material B and then blends material A

So the final render order is (C+B)+A

However I was wondering if it was possible to make material A interact only with material B instead of interacting with the combination of C+B, I wanted my scene to interact only with the blend of B+A,

in essence C + (B+A)

Is this possible in any way?

maybe a way to change the order of the operations is also possible? but without changing having the scene first

Well (C + B) + A == C + (B + A) because addition is cumulative, meaning the order of operations don’t change the result. So problem solved!

Of course I’m being pedantic and you don’t actually mean “+” here, but whatever the blend operation you have on each shader is.

The answer is not really no. Not without some significant changes to your rendering setup at least. Basically you’d have to render B & A into a separate render texture by themselves and composite back into the scene on top of C. Or at least render B into it’s own render texture and have A read from it and render over C.

The best solution is really try to find a way to combine B & A into a single shader pass.

So is the best way lets say, have an extra camera D and an extra layer with (B and A) visible only on that camera, use camera D as render texture and then blend D over C?

so
layer A - camD
layer B - camD
layer C - main scene + D

Yep, basically. It might be slightly more efficient to do layer A into camD, then render B over C with B reading the camD render texture, but that requires a little more shader work. It has the advantage of more properly and easily handling intersections in 3d and rendering order for 2d than your proposed method as B is still being rendered into the scene normally.

Honestly even the A&B in camD method you want to use a premultiplied alpha shader otherwise you’ll get dark fringing.

What if in my case I dont even need a layer B, cam D is just a black background with a lot of white to black gradient circles with additive blend mode. Then I would take that render texture and blend with multiply over C. Essentially this would be a sprite mask, but live with a lot circles crossing and a lot of change in position scale and feathering.

The shaders I have at the moment are just sprites/default modified for additive and multiply blends

so it seems what i want to do is C * (B+A) XD?