Skip to main content
gamedev.net
🔒 Locked

Framebuffer Alpha Blending?

Started by Telamon 1 reply 1k views
Original Post
Telamon
Telamon
Hi. I have a textured cube that I''m drawing on a black background. The cube''s vertices are saved in a vertex buffer in the format PositionTexturedNormal (this is C#, btw), so there''s no alpha blending information there or in the texture itself. I am trying to find a simple way to draw the cube at varying levels of transparency (I want it to fade away). I''ve been reading the DX9 SDK docs (even the C++ ones) and I can''t figure out what exactly I need to do. I''m pretty sure what I want to do is called framebuffer alpha blending, since I want to draw the entire cube in a transparent way. How do I do this? This is my pitiful attempt at setting it up: dev.RenderState.AlphaBlendEnable = true; dev.RenderState.BlendFactor = Color.FromArgb(128,128,128,128); dev.RenderState.BlendOperation = BlendOperation.Max; DrawBlock(b,x,y); dev.RenderState.AlphaBlendEnable = false; There are other settings that looked useful, but that I didn''t touch: // dev.RenderState.AlphaSourceBlend = Blend.BlendFactor; // dev.RenderState.AlphaDestinationBlend = Blend.BlendFactor; I feel that I''m very close, as it seems the the RenderState.BlendFactor is the only setting that lets me direct the transparency with which the entire block is drawn. I''m not sure if I need to specify a blend operation or not... Thanks for any help! PS - I''m looking for a solution that doesn''t require changing the contents of my cube vertex buffer or texture information in any way. I just want to draw a semi-transparent cube... ---------------------------------------- Let be be finale of seem, seems to me. ---------------------------------------- Coding: http://www.stanford.edu/~jjshed/coding Miscellany: http://www.stanford.edu/~jjshed
Telamon
Telamon
Just an itty bitty bit of help? Is this not a common thing people want to do?
Namethatnobodyelsetook
Namethatnobodyelsetook
In C++

D3DMATERIAL8 mat;

dev->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
dev->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
dev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
dev->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
// setup other material properties...
mat.Diffuse.a = alphavalue;
dev->SetMaterial(&mat);
dev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE2X);
dev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
dev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
dev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
dev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);

dev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
dev->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);


1. Enable blending
2. Set blending mode to add
3. Specify how to use source and dest colors (std. blending shown above)
4. Ensure diffuse colors comes from material, even if FVF contains colors
5. Set material''s diffuse alpha
6. Setup texture stages for std. textured and lit color
7. Setup texture stages for alpha to come from diffuse alpha
8. Terminate stages w/ disable

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.