Corrupted texture on Radeon

I'm using C# and managed DirectX to display a mesh with two texture stages. It draws fine on a GeForce, but looks corrupted on a Radeon X300 and also a ATI Radeon 9600 Pro. I think it started when I added a second texture stage to modify the texture color before rendering. You can see the results on both cards here:

http://gosub.com/DirectXTextureError.htm

Here's how I setup the render states:

dx.RenderState.Lighting = true;
dx.RenderState.NormalizeNormals = true;
dx.RenderState.ZBufferEnable = true;
dx.RenderState.CullMode = Cull.CounterClockwise;
dx.RenderState.ColorWriteEnable = ColorWriteEnable.RedGreenBlueAlpha;
dx.RenderState.AlphaBlendEnable = true;
dx.RenderState.SourceBlend = Blend.SourceAlpha;
dx.RenderState.DestinationBlend = Blend.InvSourceAlpha;
dx.RenderState.ColorWriteEnable = ColorWriteEnable.RedGreenBlueAlpha;
dx.RenderState.AlphaBlendOperation = BlendOperation.Add;
dx.RenderState.ColorVertex = true;

dx.TextureState[0].AlphaOperation = TextureOperation.Modulate;
dx.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
dx.TextureState[0].AlphaArgument2 = TextureArgument.Current;
dx.TextureState[1].AlphaOperation = TextureOperation.Disable;

dx.TextureState[0].ColorOperation = TextureOperation.AddSmooth;
dx.TextureState[0].ColorArgument1 = TextureArgument.Constant;
dx.TextureState[0].ColorArgument2 = TextureArgument.TextureColor;
dx.TextureState[0].ConstantColor = Color.Black;
dx.TextureState[1].ColorOperation = TextureOperation.Modulate;
dx.TextureState[1].ColorArgument1 = TextureArgument.Diffuse;
dx.TextureState[1].ColorArgument2 = TextureArgument.Current;
dx.TextureState[2].ColorOperation = TextureOperation.Disable;

// Use mip maps
dx.SamplerState[0].MipFilter = TextureFilter.Linear;
dx.SamplerState[0].MinFilter = TextureFilter.Linear;
dx.SamplerState[0].MagFilter = TextureFilter.Linear;
dx.SamplerState[1].MipFilter = TextureFilter.Linear;
dx.SamplerState[1].MinFilter = TextureFilter.Linear;
dx.SamplerState[1].MagFilter = TextureFilter.Linear;

Any one have any ideas

Thanks,

Jeremy



Answer this question

Corrupted texture on Radeon

  • SujitKhasnis

    That fixed it!


  • Rich Visotcky

    Thanks Ralf,

    Hopefully I understood all your suggestions correctly, and came up with the code below. It works on the GeForce, but I can't test it on a Radeon until Monday. I didn't check the Caps on the assumption that these are all new cards and seem like they should support Constant.

    > or even better learn something about pixelshaders and build a simple one.

    Yes, I should. But until I wanted to add this, the fixed pipeline was exactly what I needed. Also, I wasn't sure how many video cards out there support pixel shaders.

    I'll let you know if it works.

    -Jeremy

    dx.RenderState.Lighting = true;
    dx.RenderState.NormalizeNormals = true;
    dx.RenderState.ZBufferEnable = true;
    dx.RenderState.ColorVertex = true;
    dx.RenderState.CullMode = Cull.CounterClockwise;
    dx.RenderState.ColorWriteEnable = ColorWriteEnable.RedGreenBlueAlpha;

    dx.RenderState.BlendOperation = BlendOperation.Add;
    dx.RenderState.SourceBlend = Blend.SourceAlpha;
    dx.RenderState.DestinationBlend = Blend.InvSourceAlpha;
    dx.RenderState.TextureFactor = 0;

    dx.TextureState[0].AlphaOperation = TextureOperation.Modulate;
    dx.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
    dx.TextureState[0].AlphaArgument2 = TextureArgument.Current;

    dx.TextureState[0].ColorOperation = TextureOperation.AddSmooth;
    dx.TextureState[0].ColorArgument1 = TextureArgument.TFactor;
    dx.TextureState[0].ColorArgument2 = TextureArgument.TextureColor;

    dx.TextureState[1].AlphaOperation = TextureOperation.SelectArg1;
    dx.TextureState[1].AlphaArgument1 = TextureArgument.Current;
    dx.TextureState[1].AlphaArgument2 = TextureArgument.Current;

    dx.TextureState[1].ColorOperation = TextureOperation.Modulate;
    dx.TextureState[1].ColorArgument1 = TextureArgument.Diffuse;
    dx.TextureState[1].ColorArgument2 = TextureArgument.Current;

    dx.TextureState[2].ColorOperation = TextureOperation.Disable;
    dx.TextureState[2].AlphaOperation = TextureOperation.Disable;

    // Use mip maps
    dx.SamplerState[0].MipFilter = TextureFilter.Linear;
    dx.SamplerState[0].MinFilter = TextureFilter.Linear;
    dx.SamplerState[0].MagFilter = TextureFilter.Linear;
    dx.SamplerState[1].MipFilter = TextureFilter.Linear;
    dx.SamplerState[1].MinFilter = TextureFilter.Linear;
    dx.SamplerState[1].MagFilter = TextureFilter.Linear;


  • skipster32

    Usual couple of things to check - what does refrast look like Any errors when you turn the debug output up to max

    How big are the textures Is one blowing the max size for that card What are the caps differences between the cards

    Otherwise its not a texture corruption that I've seen before. Does it go away when you comment out the 2nd texture stage you added



  • AamirButt

    I see three possible problems with your code.

    1. The AlphaBlendOperation renderstate is for the separate alpha blend option. You should use BlendOperation. But I am sure that this is not the problem.

    2. You should not use the color part of a texture stage pipeline and disable the alpha part. It works most times but Direct3D does not specified what should happened when you do this. You can simply transfer the default value from one stage to next if you use Current as argument one and SelectArg1 as operation. But this should not the problem in your case a most drivers I know do this anyway.

    3. You use Constant as TextureArgument and I am sure you donh’t have checked the Caps if your card support it. Unfortunately ATI have decided that they don’t support it even with never cards. As a workaround you can use TFactor as argument or even better learn something about pixelshaders and build a simple one.



  • Corrupted texture on Radeon