Average Multiply Shader

Hello. I use transparent shader with blend mode: SrcAlpha OneMinusSrcAlpha without ZWrite
Picture shows how it looks in Unity for two similar objects and background white plane.
Is any blend mode which allows to use average color instead dark area on the middle?

try blend One… otherwise look here… Unity - Manual: ShaderLab command: Blend

1 Like

Average no, because that would require you to keep track of all earlier information. (Or a sum and count of course, which is possible, but not by just setting a blend mode.)

There are some other interesting blend functions available though. Besides the multiplier on the source and target (One, SrcAlpha, etc.) you can also change the actual function, which is Add by default. Other functions include Min and Max, which might help you here.

The complete blending construction looks like:
Function(SourceMultiplier * Source, TargetMultiplier * Target)

Where Source is the pixel you are drawing and Target is the pixel you are overwriting. The Function can be set using BlendOp and is Add by default.

The SourceMultiplier and TargetMultiplier are set using Blend and also have various presets.

1 Like

If it’s not clear from the Blend and BlendOp pages @jvo3dc linked to, they’re the the same lists that are on the page @JonPQ linked to, which has a lot more useful information if you’re confused by them.

TLDR - try adding this line to your shader instead of Blend SrcAlpha OneMinusSrcAlpha:
BlendOp Min

1 Like