Making ambient color appear transparent

Hello! This is probably an alpha blending related question:



I have a sphere lighted on a side by a distant light. This sphere has an ambient color (black, transparent) a diffuse color (gray, opaque) and a texture (opaque), and stands in a lightblue background.



I'd like to make the ambient color appear transparent. Setting it to background color doesn't give the right result.



Here is what I do:

Stage 0:

  • set texture stage render state
  • set an alpha render state for the stage giving:

    > alpha blend enabled

    > alpha test enabled, default test function (greater, if I’m not wrong)

    > alpha source function: 1-SRCalpha

    > alpha dest function: 1



    This gives some nice results as shown in the following picture:



    but, as you can see, the texture is saturated to white due to the alpha dest function, I suppose.



    QUESTION: how do I make another overlay (render pass or texture stage) to replace the opaque white with the color texture and leaving transparency from the previous stage?



    Thanks a lot for any help you can give.

Actually, using the render states I mentioned gives the effect of saturation only using non-dark background (= day). Renders nicely when dark, I managed to give the rising red moon effect as you can see here:

http://www.jmonkeyengine.com/jmeforum/index.php?topic=7233.0



So, I think the right procedure would be:



Render pass 1:

  * Render the background-colored silhouette to clear stars behind.

Render pass 2:

  * Stage 0:

    - set texture stage render state

    - set an alpha render state for the stage giving:

    > alpha blend enabled

    > alpha test enabled, default test function (greater, if I’m not wrong)

    > alpha source function: 1-SRCalpha 

    > alpha dest function: 1

i am trying to do the same thing. anyone?