Skip to main content
gamedev.net
🔒 Locked

Texture Blending

Started by Christoph 2 replies 850+ views
Original Post
Christoph
Christoph
Hi, I have two cloud textures (n texture stage 0 and 1) which I'm blending between to simulate cloud movement in the sky. These are my settings:


d3dDev.RenderState.DestinationBlend = Blend.InvSourceColor
d3dDev.RenderState.SourceBlend = Blend.SourceColor
d3dDev.RenderState.AlphaBlendEnable = True
d3dDev.RenderState.TextureFactor = Color.FromArgb(a, 0, 0, 0).ToArgb

d3dDev.TextureState(0).ColorOperation = TextureOperation.BlendFactorAlpha
d3dDev.TextureState(0).ColorArgument1 = TextureArgument.TextureColor
d3dDev.TextureState(0).ColorArgument2 = TextureArgument.Current

d3dDev.TextureState(1).ColorOperation = TextureOperation.BlendFactorAlpha
d3dDev.TextureState(1).ColorArgument1 = TextureArgument.Current
d3dDev.TextureState(1).ColorArgument2 = TextureArgument.TextureColor

The variable a changes slowly from 0 to 255 and back. This sort of works. But I noticed a mistake: There are many transparent (black) areas through which you are able to see the sky color. But the blending doesn't work properly here: When the factor a changes, black mingled with black doesn't stay black, but becomes a dark grey before changing to black again. So the sky color between the clouds gets darker and brighter from time to time. Can somebody please tell me how I perfectly blend two cloud textures, whereas black means transparent? Thanks, Chris
Namethatnobodyelsetook
Namethatnobodyelsetook
Shouldn't stage 0 just be selectarg1, texturecolor? Stage 1 will then blend between it's texture and the texture from stage 0, based on TFACTOR alpha.

Right now you're blending the first cloud texture with the vertex color THEN blending that with the new texture. Thus, when blend = 50%, you're getting this:

cloud1 at 25%, vertex color at 25%, and cloud2 at 50%.
Christoph
Christoph
Oh yeah, right. I thought that I'd have to use alpha on the first texture as well, so that it gets fainter while the other becomes more opaque. However, now it works. Thank you.
SoaringTortoise
SoaringTortoise
You might also want to try using dds files - alpha-mapped textures can make the blending even better because you can have semi-transparent parts of the texture. I did something like this with my water and looks pretty decent.
Always prey on the weak, the timid and the stupid. Otherwise you'll just get your butt kicked
For a tortoise, this is extremely hard to do, but when you get it right... the expression on their faces ...

Topic Locked

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

Sign in to reply to this topic.