Question: Opacity with texture
is there any way to render a textured vertex buffer partially transparent (lets say with an opacity of 0.2?)
[like in flash, setting _alpha to 0.2 so that you see 20% of the object and 80% of the other objects
ty
Yes.
Are you using shaders, or the fixed pipeline?
For a shader, simply set the output alpha value to whatever you'd like, or if you're mixing with the texture's alpha, multiply the two values.
For the fixed pipeline, use alphaops to choose the alpha values to use.
pDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
pDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
pDev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR);
pDev->SetRenderState(D3DRS_TEXTUREFACTOR, alpha * 0x01000000);
In both cases, you'll need to enable alpha blending
pDev->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
pDev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pDev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
And in both cases, you want to render all solids first, then alpha blended items sorted from back to front.
Are you using shaders, or the fixed pipeline?
For a shader, simply set the output alpha value to whatever you'd like, or if you're mixing with the texture's alpha, multiply the two values.
For the fixed pipeline, use alphaops to choose the alpha values to use.
pDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
pDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
pDev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR);
pDev->SetRenderState(D3DRS_TEXTUREFACTOR, alpha * 0x01000000);
In both cases, you'll need to enable alpha blending
pDev->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
pDev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pDev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
And in both cases, you want to render all solids first, then alpha blended items sorted from back to front.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement