using D3DXCreateSphere with alpha?

Started by
6 comments, last by QuadMV 17 years, 11 months ago
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
3DMUVE is an amateur game development team, and the designer and developer of a new gaming technology “MUVE” for the gaming industry.
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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.
3DMUVE is an amateur game development team, and the designer and developer of a new gaming technology “MUVE” for the gaming industry.
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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

3DMUVE is an amateur game development team, and the designer and developer of a new gaming technology “MUVE” for the gaming industry.
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.


3DMUVE is an amateur game development team, and the designer and developer of a new gaming technology “MUVE” for the gaming industry.
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?
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.
3DMUVE is an amateur game development team, and the designer and developer of a new gaming technology “MUVE” for the gaming industry.

This topic is closed to new replies.

Advertisement