// 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;
Texture Blending
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement