Transparency/Masking : See through an Outer Sphere and see Inner Sphere in true colours Summary

I want to be able to look through an outer sphere - BlueSphere, and see another sphere inside - RedSphere

This is the target goal I'm trying to get to:



Issues

Here is what I have tried, and the problems I'm having:

1)

If I set the spheres transparency alpha values to 0.75 
  - then the inner RedSphere does not take on its "true" colour and shows as blue instead of red.



2)

If I set the spheres transparency alpha to lower values of 0.5


the spheres lose their crispness which I don't want
and the inner RedSphere still does not take on its "true" colour


{ can't paste a 3rd sample - need more reputation points } 

Background

I am animating two spheres, one inside the other, superimposed about a common origin.


At the start:


the outer BlueSphere is at full radius
the inner RedSphere is at zero radius

As time progresses:


the outer BlueSphere shrinks
the inner RedSphere expands



So what happens is the expanding inner RedSphere "bursts through" the contracting outer BlueSphere.

So the effect I am looking for is to see the RedSphere appearing as Red as it expands inside the BlueSphere.

Thinking/Logic

So I figure that transparency is not the way to go.

The transparency settings are behaving correctly - as one would expect, in a "real world" situation - the inner sphere (Red) takes on the colour of the outer sphere (Blue) seeing as we are looking through a (transparent) Blue material.

Any ideas on what approach to take ?

It's almost as if I should be "removing" the part of the BlueSphere that the RedSphere "occupies" so that we see the RedSphere directly without any BlueSphere between us and the RedSphere.

Some sort of masking ??

Advice, comments, suggestions welcome. Thanks.

[requested edit]

Using internal render.

[ My End Solution - Thanks for the guidance ]

Right, so here is the way I got to my final result:

1) I created python drivers for each sphere


I used the frame_current scene property for input
Passed that to a scripted expression which used sin() as the scaling factor
Used some if / elif conditionals against frame_current to make the spheres visible only when I needed them


2) I created 3 layers


On Layer-1 - background


I put RedSphere AND BlueSphere
with drivers driver_Outer_RedSphere() &amp; driver_Outer_BlueSphere()
limiting the display of each sphere to show only where each radius > halfway

On Layer-2 - foreground-1


I put RedSphere ONLY
with driver driver_Inner_RedSphere()
limiting the display of RedSphere to show only where its radius &lt;= halfway

On Layer-3 - foreground-2


I put BlueSphere ONLY
with driver driver_Inner_BlueSphere()
limiting the display of BlueSphere to show only where its radius &lt;= halfway



3) I rendered each layer to .PNG sequence [RGBA] (alpha channel for transparency)


Render Layer-1 - background


background : [sky]

Render Layer-2 - foreground-1


background : [transparent]

Render Layer-3 - foreground-2


background : [transparent]



4) I brought all 3 sequences into the Video Sequence Editor


Strip-1 - background


blend [cross]
opacity [1.00]

Strip-2 - foreground-1


blend [alpha-over]
opacity [0.50]

Strip-3 - foreground-2


blend [alpha-over]
opacity [0.50]



5) Rendered the 3 layer final sequence to H.264

So the "aha moment" struck me right at the end when I was in the Video Sequence Editor:


"Don't try to make the Outer Spheres transparent, and see through to the Inner Spheres"
"Instead overlay the Inner Spheres over the Outer Spheres, and limit the opacity of the Inner Sphere overlay"




So now I see my Inner Spheres in their true colours, but the colours are muted due to the .75 opacity - and hence it gives the visual impression that the Inner Spheres are in fact inside the Outer Spheres.

Thanks all for the input - it got me going in the right direction.
You might be able to accomplish the effect you want using Compositing and Render Layers.

https://www.blender.org/manual/render/post_process/layers.html

Put the red sphere on one layer and the blue sphere on another layer.  Make sure the red layer is transparent ( Can Blender render pngs with the background transparent? )

Some of the compositor nodes you would need have screenshots in Using scenes and render layers to composite an object isolated on white background with shadow .


  use an alpha over node in the compositor to put the red ball OVER the
  blue one. Both will keep their solid appearance.
  - Gez


When it comes time for the spheres to swap orders, you can have a second alpha-over node that puts the blue ball over the red ball.  Then route those two alpha-over nodes into a Mix (under the Add > Color menu) node and animate its Fac to switch from 0 to 1.  This animation can be keyframed, or if you want to get super-fancy you can rig a driver that uses python to compare the radius of the two spheres.

Unfortunately the layers property of an object can not be keyframed.  I do not think there is a way to keyframe the visibility of an object within a single layer.  It is possible to animate the hide_render property (the camera icon on the outliner) that affects its visibility on all layers.  This enables an alternative where you just have 3 layers and one of them is an identical blue sphere that is unrenderable until the keyframe where it has shrunk enough that you want it to appear (you could also get fancy and use drivers).  This technique does not require you to keyframe compositor nodes and slightly simplifies the node tree.  It also works better if you have multiple nested spheres in the scene.

Having two distinct blue sphere objects can illustrate some properties of blenders datablock sharing system.  If you animate the sphere and then create a duplicate for the other layer they will share the same action datablock and will animate the same.  If you duplicate the sphere before you give it any keyframes (so at that time the original has no action), the two spheres will not share the action datablock (although you can later link it in using the Action Editor mode of the Dope Sheet window).