Problems w\Transparency when alpha blendin

Started by
2 comments, last by Sir Code Alot 21 years, 7 months ago
Hi everyone, First time poster, long time lurker... I am just getting my feet wet with Dx8 and have come across this problem. I can get textures to be transparent fine and translucent fine however if I try to get them to be both, I wind up with my transparent color showing as black. My render code looks like this, it is very straight foward (it seems anyway). Am I missing something in order to get both transparency and the second texture to be translucent? D3DDevice.BeginScene '' Draw first primative with no effects D3DDevice.SetTexture 0, TextureLand D3DDevice.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, TriStrip1(0), Len(TriStrip1(0)) '' Draw the second primative overlaying the first with transparency D3DDevice.SetTexture 0, TextureWater D3DDevice.SetTextureStageState 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE D3DDevice.SetTextureStageState 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE D3DDevice.SetTextureStageState 0, D3DTSS_ALPHAARG2, D3DTA_CURRENT D3DDevice.SetRenderState D3DRS_SRCBLEND, D3DBLEND_SRCALPHA D3DDevice.SetRenderState D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA D3DDevice.SetRenderState D3DRS_ALPHABLENDENABLE, 1 D3DDevice.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, TriStrip(0), Len(TriStrip(0)) D3DDevice.SetRenderState D3DRS_ALPHABLENDENABLE, 0 D3DDevice.EndScene Thanks in advance.
Advertisement
a couple things to try:

firstly:
if you have the zbuffer turned on then it won''t draw the same primitive over the top of itself since the pixels will fail the ztest.

secondly:
you can achieve this effect using multitexturing. see the SDK docs for info on this but basically you can set 2 textures at once and blend them together.

thirdly:
a screenshot would be helpful as well in determining whats actually going on. textual descriptions are always difficult

good luck,
Toby

Gobsmacked - by Toby Murray

D3DDevice.SetTexture 0, TextureWater
D3DDevice.SetTextureStageState 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE
D3DDevice.SetTextureStageState 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE
D3DDevice.SetTextureStageState 0, D3DTSS_ALPHAARG2, D3DTA_CURRENT

I think ARG2 is supposed to be D3DTA_TEXTURE. If you''re not using lighting, then CURRENT == DIFFUSE.


Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena
Thanks, Toby and Ken. I was finally able to figure it out: Ken, your D3DTA_TEXTURE hint was right on the money. The solution looks like this:


        D3DDevice.BeginScene        D3DDevice.SetRenderState D3DRS_SRCBLEND, D3DBLEND_SRCALPHA    D3DDevice.SetRenderState D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA    D3DDevice.SetRenderState D3DRS_ALPHABLENDENABLE, 1        ' Draw first primative with no effects    D3DDevice.SetTexture 0, TextureLand        D3DDevice.SetTextureStageState 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE    D3DDevice.SetTextureStageState 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE    D3DDevice.SetTextureStageState 0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE        ' TriStrip1 has all its vertex alpha's set to 1    D3DDevice.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, TriStrip1(0), Len(TriStrip1(0))        ' Draw the second primative overlaying the first with transparency    D3DDevice.SetTexture 0, TextureWater    D3DDevice.SetTextureStageState 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE    D3DDevice.SetTextureStageState 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE    D3DDevice.SetTextureStageState 0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE    D3DDevice.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, TriStrip(0), Len(TriStrip(0))        D3DDevice.SetRenderState D3DRS_ALPHABLENDENABLE, 0D3DDevice.EndScene         


BTW I would like to post a picture of the results. I have seen others do so, can I do this? I read the FAQ but couldn't find anything on it.

Again, thanks for your time guys.

- Sir Code Alot


[edited by - sir code alot on September 12, 2002 1:15:37 AM]

This topic is closed to new replies.

Advertisement