views:

32

answers:

2

I am working with directx. I am displaying two objects on my window. They are intersecting each other. I find the intersecting object.

My problem is-
I want two original objects to be transparent and the resulting intersected part to be opaque, so that the intersected part can be seen clearly.

I found some question related to transparency but they are related to transparency of window. But I want the object to be transparent.

A: 

As far as I know DirectX does not do any volumetric algebra for you to compute the exact intersecting volume between two objects.

What you can do is fake it: Look for solutions on shadow casting. Basically assume that camera location is the light source. Assuming that you've determined that object A intersects with object B, then determine which object is closer to the camera. Using your chosen shadow casting method, determine which mesh faces on the more distance object will be the shadow of the closer object. Once you determine which mesh faces are in the shadow, feed those into your render pipeline, but normally lit.

Ants
@Ants You misunderstand my question. I already have three objects. I just want to know how to make two object transparent and third opaque.
Himadri
@Himadri: Sorry I misunderstood your question. The original question seemed to ask for making the intersection of two objects visible. I see that you've updated the question to indicate that you already have the intersection as a 3rd object.
Ants
+1  A: 

You enable alpha blending by doing this:

 pDevice->SetRenderState( D3DRS_ALPHABLENDENABL, TRUE );

Set the final parameter to FALSE to disable it.

There are multiple different types of blend that are now available to you. The simplest is additive alpha blending set as follows:

 pDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );
 pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );

Other forms may well require sorting of polys to display correctly.

Its also worth noting that if you want to see the back of the model as well you need to set the cull mode to none:

pDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
Goz