Jump to content
  • Advertisement
Sign in to follow this  
Charles Thomas

Texture Blending

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

I trying to blend a mask texture and a regular texture together. The problem is that the detail of the regular texture doesn't show. It becomes one color.
// Setup

this.D3DDevice.RenderState.CullMode = Cull.None;
this.D3DDevice.RenderState.Lighting = false;
this.D3DDevice.RenderState.SourceBlend = Blend.SourceAlpha;
this.D3DDevice.RenderState.DestinationBlend = Blend.InvSourceAlpha;
this.D3DDevice.RenderState.AlphaBlendEnable = true;
this.D3DDevice.SetSamplerState(0, SamplerStageStates.MinFilter,
    (int)TextureFilter.Linear);
this.D3DDevice.SetSamplerState(0, SamplerStageStates.MagFilter,
    (int)TextureFilter.Linear);
this.D3DDevice.SetSamplerState(0, SamplerStageStates.MipFilter,
    (int)TextureFilter.Linear);
          
this.D3DDevice.SetSamplerState(0, SamplerStageStates.AddressU,
    (int)TextureFilter.Linear);
this.D3DDevice.SetSamplerState(0, SamplerStageStates.AddressV,
    (int)TextureFilter.Linear);

this.D3DDevice.SetSamplerState(1, SamplerStageStates.MinFilter,
    (int)TextureFilter.Linear);
this.D3DDevice.SetSamplerState(1, SamplerStageStates.MagFilter,
    (int)TextureFilter.Linear);
this.D3DDevice.SetSamplerState(1, SamplerStageStates.MipFilter,
    (int)TextureFilter.Linear);

// Render code

this.D3DDevice.RenderState.ZBufferEnable = false;
this.D3DDevice.RenderState.AlphaBlendEnable = true;
this.D3DDevice.BeginScene();
    this.D3DDevice.VertexFormat = quadFormat;
    this.D3DDevice.SetStreamSource(0, this.vb, 0);

    // mask texture
    this.D3DDevice.SetTextureStageState(0, TextureStageStates.ColorOperation,
        (int)TextureOperation.SelectArg1);
    this.D3DDevice.SetTextureStageState(0, TextureStageStates.AlphaOperation,
        (int)TextureOperation.SelectArg1);

    // regular texture
    this.D3DDevice.SetTextureStageState(1, TextureStageStates.ColorOperation,
        (int)TextureOperation.SelectArg1);
    this.D3DDevice.SetTextureStageState(1, TextureStageStates.AlphaOperation,
        (int)TextureOperation.SelectArg2);
                
    this.D3DDevice.SetTexture(0, alpha[1]);
    this.D3DDevice.SetTexture(1, tex[1]);
    this.D3DDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
this.D3DDevice.EndScene();
this.D3DDevice.RenderState.AlphaBlendEnable = false;
this.D3DDevice.RenderState.ZBufferEnable = true;


Share this post


Link to post
Share on other sites
Advertisement
You'll need to set the TEXCOORDINDEX of stage 1 to 0. This tells D3D that you're using the first set of texture coordinates (and most likely your only set of UVs in your vertex).

You can also put a second set of UVs in the vertex, and change the FVF to from TEX1 to TEX2. You can then use TEXCOORDINDEX on each stage to say which set of UVs to use.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!