Home » Community » Forums » DirectX and XNA » C# MDX Texture Splat Problem
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 C# MDX Texture Splat Problem
Post New Topic  Post Reply 
I've just started to mess around with Fixed Function texture blending in C#, but am having some difficulty. There do not seem to be any resources on this with C# code, so I've been converting it from the c++ examples, and am thinking that perhaps something didn't transfer correctly?

I was going by the demo from the GameDev texture splatting tutorial located at www.gamedev.net/reference/articles/article2238.asp

It is supposed to look like:


but instead is turning out to be:


The correct texture colors are there, and the alpha blending is there, but no texture details appear. Is this a filtering issue, or have I done something wrong in my code?

private void OnResetDevice( Device device )
{
	// Set projection
	m_camera.AspectRatio = (float)BackBufferWidth / (float)BackBufferHeight;
	device.Transform.Projection = m_camera.Projection;
	// Set render states
	device.RenderState.Lighting = false;
	device.RenderState.FillMode = m_framework.FillMode;
	device.SetRenderState( RenderStates.ZEnable, true );

	// Allow multiple passes to blend together correctly
	device.SetRenderState( RenderStates.AlphaBlendEnable, true );
	device.SetRenderState( RenderStates.SourceBlend, (int)Blend.SourceAlpha );
	device.SetRenderState( RenderStates.DestinationBlend, (int)Blend.InvSourceAlpha );

	device.SetSamplerState(0, D3D.SamplerStageStates.MinFilter, (int)D3D.TextureFilter.Linear );
	device.SetSamplerState(0, D3D.SamplerStageStates.MagFilter, (int)D3D.TextureFilter.Linear );
	device.SetSamplerState(0, D3D.SamplerStageStates.MipFilter, (int)D3D.TextureFilter.Linear);
	
	// Prevent some ugliness with the alphamaps			
	device.SetSamplerState(0, D3D.SamplerStageStates.AddressU, (int)D3D.TextureAddress.Clamp );
	device.SetSamplerState(0, D3D.SamplerStageStates.AddressV, (int)D3D.TextureAddress.Clamp );
			
	device.SetSamplerState(1, D3D.SamplerStageStates.MinFilter, (int)D3D.TextureFilter.Linear);
	device.SetSamplerState(1, D3D.SamplerStageStates.MagFilter, (int)D3D.TextureFilter.Linear);
	device.SetSamplerState(1, D3D.SamplerStageStates.MipFilter, (int)D3D.TextureFilter.Linear);

	device.SetSamplerState(2, D3D.SamplerStageStates.MinFilter, (int)D3D.TextureFilter.Linear);
	device.SetSamplerState(2, D3D.SamplerStageStates.MagFilter, (int)D3D.TextureFilter.Linear);
	device.SetSamplerState(2, D3D.SamplerStageStates.MipFilter, (int)D3D.TextureFilter.Linear);

	device.SetSamplerState(3, D3D.SamplerStageStates.MinFilter, (int)D3D.TextureFilter.Linear);
	device.SetSamplerState(3, D3D.SamplerStageStates.MagFilter, (int)D3D.TextureFilter.Linear);
	device.SetSamplerState(3, D3D.SamplerStageStates.MipFilter, (int)D3D.TextureFilter.Linear);

	device.SetSamplerState(4, D3D.SamplerStageStates.MinFilter, (int)D3D.TextureFilter.Linear);
	device.SetSamplerState(4, D3D.SamplerStageStates.MagFilter, (int)D3D.TextureFilter.Linear);
	device.SetSamplerState(4, D3D.SamplerStageStates.MipFilter, (int)D3D.TextureFilter.Linear);
}



and the render calls
private void Render( Device device ) 
{
	// Alphamap: take the alpha from the alphamap
	device.SetTextureStageState(0, D3D.TextureStageStates.AlphaOperation, (int)D3D.TextureOperation.SelectArg1 );
	device.SetTextureStageState(0, D3D.TextureStageStates.AlphaArgument1, (int)D3D.TextureArgument.TextureColor);
	// Texture: take the color from the texture, take the alpha from the previous stage
	device.SetTextureStageState(1, D3D.TextureStageStates.ColorOperation, (int)D3D.TextureOperation.SelectArg1 );
	device.SetTextureStageState(1, D3D.TextureStageStates.ColorArgument1, (int)D3D.TextureArgument.TextureColor );
	device.SetTextureStageState(1, D3D.TextureStageStates.AlphaOperation, (int)D3D.TextureOperation.SelectArg1 );
	device.SetTextureStageState(1, D3D.TextureStageStates.AlphaArgument1, (int)D3D.TextureArgument.Current );

	device.SetTexture(0, alp1);
	device.SetTexture(1, tex1);
	//...draw primitives
			
	device.SetTexture(0, alp2);
	device.SetTexture(1, tex2);
	//...draw primitives

	device.SetTexture(0, alp3);
	device.SetTexture(1, tex3);
	//...draw primitives

	device.SetTexture(0, alp4);
	device.SetTexture(1, tex4);
	//...draw primitives
}



Thanks for your help

 User Rating: 992   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I'm still having this trouble, and think the problem is with the texture stages in the Render function.

device.SetTextureStageState(0, D3D.TextureStageStates.AlphaOperation, (int)D3D.TextureOperation.SelectArg1 );
device.SetTextureStageState(0, D3D.TextureStageStates.AlphaArgument1, (int)D3D.TextureArgument.TextureColor);

device.SetTextureStageState(1, D3D.TextureStageStates.ColorOperation, (int)D3D.TextureOperation.SelectArg1 );
device.SetTextureStageState(1, D3D.TextureStageStates.ColorArgument1, (int)D3D.TextureArgument.TextureColor );
device.SetTextureStageState(1, D3D.TextureStageStates.AlphaOperation, (int)D3D.TextureOperation.SelectArg1 );
device.SetTextureStageState(1, D3D.TextureStageStates.AlphaArgument1, (int)D3D.TextureArgument.Current );


Is this the proper way to render part of Stage 1 texture based on Stage 0's alpha? Could anyone give me a hint in the right direction?

Thanks

 User Rating: 992   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: