blending / combining two sprites

I am working on a game that incorporates two circular sprites - they are identical and imported from a spritesheet that consists of one single all-white circle. The two sprites are different colors and I choose the colors by changing the color property of the material on the sprite renderer.

Question: when the two circles overlap (say partially overlap), is there any way to automatically have the color of the portion that overlaps be a blend / combination of the two original circles. eg specifically if sprite1 is 0xFF0000 (red) and sprite2 is 0x0000FF (blue) I would want ONLY the overlapping portions of the two circles to be 0xFF00FF (purple) and the non-overlapping portions to remain red and blue respectively.

eg - Is there some sort of material that is ‘additive’ to what is under it rather than simply covering up?

Any help / hints would be greatly appreciated. I am new to Unity but it is fantastic!

Jim

What if you make the two circles partially transparent? Then naturally the overlapping areas will be a different color.

Here, check this out:
http://www.reddit.com/r/Unity2D/comments/1r2mem/sprite_shader_variants_includes_normalmapping_on/

When you say “partially transparent” … do you mean setting the alpha of each to, say, 0.5? I have tried that but it has the wrong effect that I want where the background blends / shows through. It is an all black background, so the end effect is that the separate red or separate blue circles are simply dull red and dull blue. Or do you mean something different when you say “partially transparent”?

You could give each one a moving white background as a child object. Then, if you get the sorting layers correct, they’ll blend with each other but not the background.

This might help you to figure out which blend mode you will need for your shader:
Visual glBlendFunc + glBlendEquation Tool

I just had a look at the Sprites-Default shader which you can get from Unity’s Download Archive.

Replace the line where it says…

Blend SrcAlpha OneMinusSrcAlpha

…with…

Blend SrcColor DstColor

…and you get this result: Web Player

Not sure if this is what you wanted but maybe it’s a start.
(I’m sorry for the sheer ugliness of the scene.)

Thank you all for the suggestions. I have my original question working with the shader examples from the response by zombiegorilla, which is very similar to Bivrost mod.

Unfortunately I now realize that my original question wasn’t what I was looking for, and instead I want a shader that can programatically produce a different color in the portions that the two sprites overlap. eg something like:

if (colorOfPixel.r == 1  colorOfPixel.b == 1) {
  ColorOfPixel.r = 0;
  ColorOfPixel.g = 1;
  ColorOfPixel.b = 0;
}

where ColorOfPixel is the COMBINED color of the two sprites that I am moving around. So specifically sprite 1 is a red circle, sprite 2 is a blue circle … and for the portions that overlap as I move them around, I want only that overlapping portion to be green. Can this be done?

Here is the key part of my shader code (but it does NOT work):

struct v2f
{
float4 vertex   : SV_POSITION;
	fixed4 color    : COLOR;
	half2 texcoord  : TEXCOORD0;
};
			
v2f vert(appdata_t IN)
{
	v2f OUT;
	OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
	OUT.texcoord = IN.texcoord;
	OUT.color = IN.color;
	fixed4 ss = OUT.color;
	if (ss.r == 1  ss.b == 1) {
		OUT.color.r = 0;
		OUT.color.g = 1;
		OUT.color.b = 0;
	}
	return OUT;
}		

sampler2D _MainTex;

fixed4 frag(v2f IN) : COLOR
{
	return 2f * tex2D(_MainTex, IN.texcoord) * IN.color;
}