2

I have problem with rendering 1000 cubes in XNA 4.0. I haven't found similar problem solution, so I post this question. The FPS falls down to 21 (form basic 30). I don't know how to solve it. It's surely problem of rendering. I've used simple shader as follows:

uniform extern float4x4 WorldViewProj : WORLDVIEWPROJECTION;

struct VS_OUTPUT
{
    float4 position : POSITION;
    float4 color : COLOR0;
};

VS_OUTPUT VS(float4 Pos  : POSITION)
{
    VS_OUTPUT Out = (VS_OUTPUT)0;
    Out.position = mul(Pos, WorldViewProj);
    Out.color = float4(1,1,1,1);
    return Out;
}

float4 PS( VS_OUTPUT vsout ) : COLOR
{
    return vsout.color;
}

technique TransformTechnique
{
    pass P0
    {
         vertexShader = compile vs_2_0 VS();
         pixelShader = compile ps_2_0 PS();
    }
}

and using of it:

public static void RenderModel(Model model, Texture2D texture, Effect effect,
    Matrix view, Matrix projection, Vector3 position)
{
    var world = Matrix.CreateWorld(position, Vector3.Forward, Vector3.Up);
    var worldViewProjection = world * view * projection;
    effect.Parameters["WorldViewProj"].SetValue(worldViewProjection);
    effect.CurrentTechnique = effect.Techniques["TransformTechnique"];

    // Assign effect to model
    foreach (ModelMesh mesh in model.Meshes)
    {
        foreach (ModelMeshPart part in mesh.MeshParts)
        {
            part.Effect = effect;
        }
    }

    foreach (var mesh in model.Meshes)
    {
        mesh.Draw();
    }
}

I need to render about 10 thousand or more cubes.

fakir314
  • 592
  • 1
  • 4
  • 12

0 Answers0