Мерцающая проблема с сеткой: DirectX HLSL - PullRequest
1 голос
/ 30 декабря 2010

Проблема : Я рендерил сетку с использованием HLSL (High Level Shader Language) в Managed DirectX 9. В зависимости от сложности сетки (количество вершини лица) Иногда у меня возникают проблемы с мерцанием.

Очевидно, что сетка с более высокой сложностью должна рендериться дольше, а степень мерцания увеличивается со сложностью сетки.Однако происходит то, что сетка не отображается вообще , а время, необходимое для рисования сетки , значительно меньше .

Increased Mesh Complexity -> Increased Flickering

Код :

/* Before this is called: 
     - The Device has been set up successfully
     - The Effects have been compiled successfully
     - The RenderState is correct, etc.. etc..
*/

public void Draw(Device device, MyMeshClass mesh)
{
    // Set vertex/index buffers (this has been timed, negligible)
    CustomVertex.PositionNormalTextured[] vb = mesh.Vertices;
    short[] ib = mesh.Indices

    // Set shader parameters (this has been timed, negligible)
    this.effect.SetValue("texture", mesh.Texture);
    this.effect.SetValue("color", mesh.Color);
    this.effect.SetValue("worldViewProj", mesh.ViewProjection);

    int passes = this.effect.Begin(0);
    for (int i = 0; i < passes; ++i)
    {
        this.effect.BeginPass(i);
        device.DrawIndexedUserPrimitives(PrimitiveType.TriangleList, 0, ib.Length, ib.Length / 3, ib, true, vb);
        this.effect.EndPass();
    }
    this.effect.End();
}

Результаты : Это вывод, который я получаю (я вставил таймеры, которые не включены в приведенный выше коддля удобства чтения) :

// This is a Copy/Paste from the debug output
.
.
Draw Mesh: 1.2851 ms
Draw Mesh: 1.3882 ms
Draw Mesh: .4819 ms     // <-- It flickered here
Draw Mesh: 1.3638 ms
Draw Mesh: 1.4972 ms
Draw Mesh: 1.4262 ms
Draw Mesh: 1.2239 ms
Draw Mesh: 1.6684 ms
Draw Mesh: 1.6963 ms
Draw Mesh: 2.3397 ms
Draw Mesh: 1.3484 ms
Draw Mesh: 1.4012 ms
Draw Mesh: .5287 ms     // <-- It flickered here
Draw Mesh: .4644 ms     // <-- It flickered here
Draw Mesh: 1.6140 ms
Draw Mesh: 1.4392 ms
Draw Mesh: 1.4579 ms
Draw Mesh: .4987 ms     // <-- It flickered here
Draw Mesh: 1.4873 ms
.
.

Код HLSL : Здесь приведен сокращенный код HLSL, обратите внимание, что это НЕ фактический код, поэтомуНе забывайте о синтаксических ошибках, уверяю вас, что настоящий код очень похож.

Texture texture;
sampler TextureSampler; // There is more here, I cut it out to save space
float4x4 worldViewProj : WorldViewProjection;
float4 color;


float4 mainVS(float4 pos : POSITION) : POSITION
{
    float4 Out = mul(pos, worldViewProj);           

    return Out; 
}

float4 mainPS(float4 pos : POSITION) : COLOR
{
    float4 Out = tex2D(TextureSampler, pos.xy);

    return Out;
}


technique Standard
{
    pass One
    {
        CullMode = CCW;
        AlphaBlendEnable = true;
        SrcBlend = SrcAlpha;
        DestBlend = InvSrcAlpha;

        VertexShader = compile vs_2_0 mainVS();
        PixelShader = compile ps_2_0 mainPS();
    }
}

Любая помощь / идеи / предложения будут высоко оценены.Спасибо!

1 Ответ

0 голосов
/ 07 января 2011

Решением является использование VertexBuffer и IndexBuffer и рендеринг с использованием DrawIndexedPrimitives

...