【问题标题】:Flickering Mesh Problem: DirectX HLSL闪烁网格问题:DirectX HLSL
【发布时间】:2011-01-07 05:33:56
【问题描述】:

问题:我在 Managed DirectX 9 中使用 HLSL(高级着色器语言) 渲染网格。取决于网格的复杂性 (数字顶点和面) 我有时会遇到闪烁问题。

显然,复杂度较高的网格体渲染时间应该更长,并且闪烁量随着网格体的复杂度而增加。然而,所发生的情况是网格根本没有渲染,而绘制网格所需的时间显着缩短

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

任何帮助/想法/建议将不胜感激。谢谢!

【问题讨论】:

    标签: c# hlsl flicker directx-9 managed-directx


    【解决方案1】:

    解决方案是使用VertexBufferIndexBuffer 并使用DrawIndexedPrimitives 进行渲染

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-19
      • 2015-01-04
      • 2016-03-06
      • 2012-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多