using D3DXCreateSphere with alpha?
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
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
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
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.
If you're doing shaders then isn't the simplest way just to create a shader that emits a constant alpha/colour?
Cheers,
Jack
Quote:Original post by QuadMVI feel this might be relevant, if a little OT:
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.
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
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
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
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.
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?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement