Skip to main content
GameDev.net gamedev.net
🔒 Locked

Transparancy for rendering objects

Started by ktuluorion May 9, 2003 at 4:22 PM 5 replies 1.3k views
Original Post
ktuluorion
ktuluorion
I''m using DX9 and I am rendering a scene, and for every element I tried setting the material so that the alpha value is 20, but i didn''t get any see-through. I want to make it so everything I render is partially transparant. How do I achieve this? I am rendering things with DrawSubset. Thanks!
[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest o
gustav
gustav
Use this: (in VB, it is from my game)

D3Device.SetRenderState D3DRS_AlphaBlendEnabled, 1

For i = 0 To Platform.MatCount - 1
Platform.Mat(i).diffuse = CreateColorValue(0.1, 1, 1, 1)
D3DDevice.SetMaterial Platform.Mat(i)
D3DDevice.SetTexture 0, Platform.Tex(i)
Platform.Mesh.DrawSubset i
Next i

And the createcolorvalue function is:

Function CreateColorValue(a, r, g, b) As D3DCOLORVALUE
CreateColorValue.a = a
CreateColorValue.r = r
CreateColorValue.g = g
CreateColorValue.b = b
End Function


Example: CreateColorValue(AlphaValue, Red, Green, Blue)

[edited by - gustav on May 10, 2003 3:43:59 AM]
ktuluorion
ktuluorion
Thanks for the help... unfortunately, i''m not getting any transparancy from that code... are there any other render states I need to set or anything?
[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest o
ktuluorion
ktuluorion
OK.. i think i''m getting kinda sorta transparancy.. i created two renderstates

d3ddevice->SetRenderState( D3DRS_ALPHABLENDENABLE, true );
d3ddevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR);
d3ddevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVDESTALPHA);


Does this work with textures as well? Is there something additional I need to do to get textures transparant.
[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest o
Namethatnobodyelsetook
Namethatnobodyelsetook
The standard blend is
RS_SRCBLEND, D3DBLEND_SRCALPHA
RS_DESTBLEND, D3DBLEND_INVSRCALPHA
ie: NewColor = NewPixel * NewAlpha + OldPixel * (1-NewAlpha)

or for additive blending
RS_SRCBLEND, D3DBLEND_ONE
RS_DESTBLEND, D3DBLEND_ONE
ie: NewColor = NewPixel * 1 + OldPixel * 1

What you have blends the new pixel by it''s color, and the old pixel by the alpha in the destination surface. If it''s your backbuffer, it probably doesn''t have alpha (most cards don''t support it, you need to make a render target to have destination alpha)
NewColor = NewPixel * NewPixel + OldPixel * (1-OldAlpha)

And yes, blending works with colors, textures, or even procedural output from a pixel shader. The alpha is controlled with SetTextureStageState''s ALPHAOP and ALPHAARGn, just like color operations (or via your pixel shader output register). The alpha used for blending is the final alpha value of all your active texture stages.

Also of note, as I''ve seen people confused by it, is that you only need ALPHABLENDENABLE set to true when you want to blend with the backbuffer. If you are blending multiple textures and colors in the texture stages you don''t need to enable anything. That flag only controls blending with previous data in your backbuffer.
ktuluorion
ktuluorion
Great! Thanks for your help everyone! I have it working exactly as I would like.

[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest o

Topic Locked

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

Sign in to reply to this topic.