Jump to content
  • Advertisement
Sign in to follow this  
QuadMV

using D3DXCreateSphere with alpha?

This topic is 4462 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I'm using D3DXCreateSphere to create a bounding sphere around an object. I want to render the sphere with some sort of translucency? Right now I’m just setting my world transform to position where to render, then calling DrawSubset. Can someone suggest what might be the best way of enabling some transparency on the sphere? I don’t know if createsphere sets texture coordinates, but I don’t want to render a texture, so I don’t think texture alpha would work. Do I have to walk the triangle list and modify the color alpha for every vertex or is there a global setting I can use to do it? Thanks

Share this post


Link to post
Share on other sites
Advertisement
I was writing about this in the FAQ last night [lol]

If you're using fixed-function then its fairly simple:

SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB( a, r, g, b ) );
SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TFACTOR );
SetTextureStageState( 0, D3DRSS_COLOROP, D3DTA_SELECTARG1 );

SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR );
SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTA_SELECTARG1 );


Thats off the top of my head, so if it doesn't work just have a dig around in the "Texture Blending" and "Alpha Blending" sections of the SDK's index (theres a fairly nice guide to various methods).

Given its a sphere and that blending is draw-order dependent a nice trick is to do a 2-pass render. Render the same geometry in both passes but swap the culling mode (D3DRS_CULLMODE) so that the first pass renders the back-faces of the sphere and the second pass renders the front-faces of the sphere.

hth
Jack

Share this post


Link to post
Share on other sites
Thanks, I kind of knew this, but I knew I was forgetting it. I guess I've been doing more with shaders and forgot some of this basic stuff.

Share this post


Link to post
Share on other sites
If you're doing shaders then isn't the simplest way just to create a shader that emits a constant alpha/colour?

Quote:
Original post by QuadMV
Thanks, I kind of knew this, but I knew I was forgetting it. I guess I've been doing more with shaders and forgot some of this basic stuff.
I feel this might be relevant, if a little OT:

Quote:
Homer Simpson:
every time I learn something new, it pushes some old stuff out of my brain. Remember when I took that home winemaking course, and I forgot how to drive?


Cheers,
Jack

Share this post


Link to post
Share on other sites
Here are the minor adjustments I had to make if anyone is interested, but it worked flawlessly:

pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR , D3DCOLOR_ARGB( 0x0F, 0xFF, 0, 0 ) );
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TFACTOR );
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR );
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );

I also used:

pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );

so it would render the sphere on both sides

Share this post


Link to post
Share on other sites
Quote:

If you're doing shaders then isn't the simplest way just to create a shader that emits a constant alpha/colour?


That's assuming I'm good a shaders ;-)

Also though, it would require creating a file with the proper shader code, loading it, enabling it, debugging it, etc... I think your suggestion is actually easier.


Share this post


Link to post
Share on other sites
Quote:
Original post by QuadMV
I also used:

pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );

so it would render the sphere on both sides

That's rather dangerous, since alpha blending only works correctly when sorted from back to front. You should make sure that you render the sphere such that the back side is drawn first. (Which luckily should be possible with a sphere.)

Edit: You're turning Z writing off when drawing that sphere, right?

Share this post


Link to post
Share on other sites
In this particular case the sphere is the very last thing to get rendered, so sorting isn't a problem nor is z write, but in general yes, you are absolutely right. I draw my water and billboards with alpha sorted appropriately.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!