2010-12-30 9 views
1

Le problème: Je suis rendu un maillage en utilisant HLSL (High Level Shader Language) managé DirectX 9. En fonction de la complexité du maillage (nombre de sommets et faces) J'ai parfois des problèmes de scintillement.vacillant Mesh Problème: DirectX HLSL

Évidemment, un maillage avec une complexité plus élevée devrait prendre plus de temps à rendre, et la quantité de scintillement augmente avec la complexité du maillage. Cependant, ce qui se passe est que le maillage n'est pas rendu au et le temps nécessaire pour dessiner le maillage est significativement plus bas.

Increased Mesh Complexity -> Increased Flickering

Le Code:

/* 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(); 
} 

Résultats: Ceci est la sortie que je reçois (I inséré minuteries qui ne sont pas inclus dans le code ci-dessus pour la lisibilité):

// 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 
. 
. 

Code HLSL: Voici le abrégé code HLSL, s'il vous plaît noter que ce n'est pas le code réel, donc ne creusez pas dans les erreurs de syntaxe, je vous assure que le code réel est extrêmement similaire.

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(); 
    } 
} 

Toute aide/idée/suggestion serait très appréciée. Merci!

Répondre

0

La solution consiste à utiliser un VertexBuffer et IndexBuffer et rendre l'utilisation DrawIndexedPrimitives