[MDX] Terrain rendering problems using multiple vertex stream

Started by
1 comment, last by LowRad 15 years, 1 month ago
Hi, I have converted my terrain to use multiple stream to allow me to have a bigger landscape. I've manage to make it work. However, after a few frames a rendering bug is showing up. Some triangle start to flicker and they seems to change over time or when i move the camera. I've tried to debug the problem using PIX, but everytimes a take a snapshot everythings is fine (image is ok). This is the relevent part of my shader:

struct VS_INPUT
{
    float2 Position : TEXCOORD0;
    float2 TexCoord : TEXCOORD1;	
    float1 HeightPosition : TEXCOORD2;
};


VS_OUTPUT VS(VS_INPUT input)
{
    VS_OUTPUT output = (VS_OUTPUT)0;
      
    float4 position = float4(input.Position.x, input.HeightPosition.x, input.Position.y, 1);
    
    output.Position = mul(position, g_WorldViewProjection);
    output.TexCoord = input.TexCoord;                       
        
    return output;    
}

And the relevent part from my code

    public struct TerrainVertex
    {
        public float x, z;
        public float u1, v1;
    }

    public struct TerrainHeightVertex
    {
        public float y;
    }

    VertexElement[] vertexDeclaration = new VertexElement[] 
    { 
        new VertexElement(0, 0, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),              
        new VertexElement(0, 8, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 1),
        new VertexElement(1, 16, DeclarationType.Float1, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 2),
        VertexElement.VertexDeclarationEnd,
    };

    public void Draw(Matrix viewMatrix, Matrix projectionMatrix)
    {          
        _graphicsDevice.RenderState.ZBufferEnable = true;
        _graphicsDevice.RenderState.ZBufferWriteEnable = true;
        _graphicsDevice.RenderState.CullMode = Cull.CounterClockwise;

        // disabled alpha-blending and alpha testing
        _graphicsDevice.RenderState.AlphaBlendEnable = false;            
        _graphicsDevice.RenderState.AlphaTestEnable = false;
            
            
        _graphicsDevice.SetStreamSource(0, _gridVertexBuffer, 0, Marshal.SizeOf(typeof(TerrainVertex)));
        _graphicsDevice.SetStreamSource(1, _heightVertexBuffer, 0, Marshal.SizeOf(typeof(TerrainHeightVertex)));
        _graphicsDevice.Indices = _indexBuffer;
        _graphicsDevice.VertexDeclaration = _vertexDeclaration;


        int passCount = _effect.Begin(FX.None);

        for (int iPass = 0; iPass < passCount; iPass++)
        {
            _effect.BeginPass(iPass);
            _graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, _vertexCount, 0, _primitiveCount);
            _effect.EndPass();
        }
            
        _effect.End();

    }

And the results: renderbug image So i'm asking here, since i dont have any good ideas on what could cause this strange behaviour. If i didnt post enought, just ask me the relevent part missing. Thanks to look into it with me ;) Lowrad
Advertisement
Anything from the DX Debug runtimes?
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
I really feel bad right now... thanks for reminnding me to reinstall DX SDK so i could get the debug runtime running.

My error was pretty obvious:
Direct3D9: (ERROR) :Vertex stride in stream 1 is less than in the declaration

I forget to change my declaration offsets to:
VertexElement[] vertexDeclaration = new VertexElement[] {     new VertexElement(0, 0, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),                  new VertexElement(0, 8, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 1),    new VertexElement(1, 0, DeclarationType.Float1, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 2),                VertexElement.VertexDeclarationEnd,};


Vertex declaration offset are stream based. duh! :)

Thanks!

This topic is closed to new replies.

Advertisement