Jump to content
  • Advertisement
Sign in to follow this  

Alpha Blending when rendering to texture.

This topic is 4156 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

Hey there! I would like to render to texture one scene containing alpha'ed objects. Everything works nicely (using ID3DXRenderToSurface ) except that my transparent stuff is not blended with the scene background. What are the Render States to use so that the scene rendered to texture will blend with what's has been already rendered on the texture - and not the frame buffer. Is it D3DRS_SEPARATEALPHABLENDENABLE ? Thanks in advance

Share this post

Link to post
Share on other sites
You need to make sure the target's surface has an alpha channel (a format of A8R8G8B8 instead of X8R8G8B8). Also, you'll need to enable alpha blending when drawing the rendertarget into your actual scene.

Also, if you have multiple layers rendering into the rendertarget (in the first pass), you might want to enable alpha blending at that point as well.

And D3DRS_SEPARATEALPHABLENDENABLE isn't the correct renderstate. You're looking for D3DRS_ALPHABLENDENABLE .

Hope this helps.

Share this post

Link to post
Share on other sites
Thanks Sirob!

Yes, the surface was created with A8R8G8B8 and yes, the alpha blending D3DRS_ALPHABLENDENABLE render state is set.


- The same scene renders correctly onto the back buffer.
- Same problem on all these vidboards: ATI X1900, ATI X800, ATI X1600, GF 6800 and GF 8800.


Share this post

Link to post
Share on other sites
Also, remember to render anything that has alpha blending enabled after everything that is opaque. When rendering more than one object that is translucent, always render from back to front.

This will help avoid issues where the backbuffer blocks the background from being drawn.

Share this post

Link to post
Share on other sites
D3DRS_SRCBLEND and D3DRS_DESTBLEND are correctly set. Just triple-checked. Furthermore the scene renders properly onto the Back Buffer. It seems like alpha blending is somewhat disabled when rendering onto texture.

I am using a RenderTo Surface created as shown below: ( Managed C++ )

RenderToTexture (
Device^ device ,
int DynamicTextureSize , int MipLevels , TextureFilters FilteringOptions )
#ifdef _DEBUG
if ( 1 != MipLevels )
throw gcnew Exception ( "RenderToTexture does not support MipMaps for now." ) ;
this->DynamicTextureSize = DynamicTextureSize ;
this->MipLevels = MipLevels ;
this->FilteringOptions = FilteringOptions ;

PixelFormat pixelFormat = PixelFormat::A8R8G8B8 ;
DynamicTexture = gcnew Texture ( device ,
DynamicTextureSize , DynamicTextureSize , MipLevels ,
TextureUsage::RenderTarget , pixelFormat , Pool::Default ) ;
// Create an off-screen "render to" surface...
TextureSurface = gcnew Surface ( DynamicTexture , 0 ) ;

// Managed C++ Annoyance: A local variable is needed here !
ID3DXRenderToSurface * RenderToSurface ; // Surface for rendering to texture
ThF ( D3DXCreateRenderToSurface (
( IDirect3DDevice9 * ) device->nativeVoidStar ,
DynamicTextureSize, DynamicTextureSize,
( D3DFORMAT ) pixelFormat ,
// stenciling AND ( most importantly) depth buffer enabled when rendering
// to texture - cant disable stenciling without disabling Z buffer
& RenderToSurface ) ) ;
this->RenderToSurface = RenderToSurface;
// TODO: Consider implementing mip levels if needed

When it is time to render, a BeginScene is done on the render surface, then cleared, then the rendering code, and finally EndScene.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!