SHARE
TWEET

Untitled

a guest Sep 29th, 2013 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct Cube
  2.         {
  3.             public Matrix World;
  4.             public Vector2 AtlasCoordinate;
  5.         }
  6.  
  7.         Int32 count = 100;
  8.  
  9.         private void GenerateInstanceInformation()
  10.         {
  11.             Cube[] cubes = new Cube[count];
  12.             Random rand = new Random();
  13.             for (int i = 0; i < count; i++)
  14.             {
  15.                 for (int x = 0; x < count; x++)
  16.                 {
  17.                     for (int z = 0; z < count; z++)
  18.                     {
  19.                         cubes[i].World = Matrix.CreateTranslation(new Vector3(x, 0, z));
  20.                         cubes[i].AtlasCoordinate = new Vector2(rand.Next(0, 2), rand.Next(0, 2));
  21.                     }
  22.                 }
  23.             }
  24.             instanceBuffer = new VertexBuffer(device, instanceVertexDeclaration, count, BufferUsage.WriteOnly);
  25.             instanceBuffer.SetData(cubes);
  26.         }
  27.  
  28.         public void DrawChunk(Effect effect, Camera camera, Texture2D texture)
  29.         {
  30.             effect.CurrentTechnique = effect.Techniques["Instancing"];
  31.             effect.Parameters["WVP"].SetValue(camera.View * camera.Projection);
  32.             effect.Parameters["cubeTexture"].SetValue(texture);
  33.  
  34.             device.Indices = indexBuffer;
  35.             effect.CurrentTechnique.Passes[0].Apply();
  36.             device.SetVertexBuffers(bindings);
  37.             device.DrawInstancedPrimitives(PrimitiveType.TriangleList, 0, 0, 24, 0, 12, count);
  38.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top