/// <summary>
 /// Initializes a new instance of the <see cref="InstancedBilboardModel"/> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="BilboardsName">Name of the bilboards.</param>
 /// <param name="diffuseTextureName">Name of the diffuse texture.</param>
 /// <param name="instances">The instances.</param>
 /// <param name="dynamicBufferSize">Size of the dynamic buffer, use this if you want something different from number of instances</param>
 public InstancedBilboardModel(GraphicFactory factory, String BilboardsName, String diffuseTextureName, BilboardInstance[] instances, int  dynamicBufferSize = -1 )
     : base(factory, BilboardsName  ,false)
 {
     this.instances = instances;
     this.diffuseTextureName = diffuseTextureName;            
     this.dynamicBufferSize = dynamicBufferSize;
     LoadModelo(factory);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ForwardMaterial"/> class.
 /// </summary>
 /// <param name="shader">The shader.</param>
 public FluidMaterial(IShader shader, int maxParticles, Microsoft.Xna.Framework.Vector2 scale)
 {
     this.Shader = shader;
     CanAppearOfReflectionRefraction = false;
     CanCreateShadow = false;
     IsVisible = true;
     BilboardInstance = new BilboardInstance[maxParticles];
     for (int i = 0; i < maxParticles; i++)
     {
         BilboardInstance[i] = new BilboardInstance();
         BilboardInstance[i].Scale = scale;
     }
 }
 /// <summary>
 /// Sets the bilboard instances.
 /// </summary>
 /// <param name="instances">The instances.</param>
 public void SetBilboardInstances(BilboardInstance[] instances)
 {
     if(instances.Count() < dynamicBufferSize)
     {
         this.instances = instances;
         BatchInformations[0][0].InstanceCount = instances.Count();
         BatchInformations[0][0].InstancedVertexBuffer.SetData(instances);
     }
     else
     {
         ActiveLogger.LogMessage("Calling SetBilboardInstances with different BilboardInstance size is not recomended, lot of performance penalty here", LogLevel.Warning);
         this.instances = instances;
         VertexBuffer InstancedvertexBufferS = factory.CreateDynamicVertexBuffer(vd, instances.Count(), BufferUsage.WriteOnly);
         InstancedvertexBufferS.SetData(instances);
         BatchInformations[0][0].InstanceCount = instances.Count();
         BatchInformations[0][0].InstancedVertexBuffer = InstancedvertexBufferS;
     }            
 }
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo,factory, contentManager);

            SimpleModel simpleModel = new SimpleModel(factory, "Model//block");
            simpleModel.SetTexture(factory.CreateTexture2DColor(1,1,Color.White),TextureType.DIFFUSE);
            BoxObject tmesh = new BoxObject(new Vector3(0,10,0), 1, 1,1,50,new  Vector3(5000,1,5000),Matrix.Identity, MaterialDescription.DefaultBepuMaterial());
            tmesh.isMotionLess = true;
            DeferredNormalShader shader = new DeferredNormalShader();
            DeferredMaterial fmaterial = new DeferredMaterial(shader);
            IObject obj = new IObject(fmaterial, simpleModel, tmesh);
            this.World.AddObject(obj);            
            
            {
                List<BilboardInstance> poss = new List<BilboardInstance>();
                for (int i = -10 ; i < 20; i++)
                {
                    for (int j = -10; j < 20; j++)
                    {
                        float x, y;
                        x = i * 100;
                        y = j * 100;
                        BilboardInstance bi = new BilboardInstance();
                        bi.Scale = new Vector2(100, 100);
                        bi.Position = new Vector3(x, 5, y);
                        poss.Add(bi);
                    }
                }

                ///same as before, just the name of the class change
                ///You can change the position of a individual bilboard using bm.GetBilboardInstances(), updating the structure recieved and 
                ///using bm.SetBilboardInstances(). Dont do this every frame pls =P
                ///You can change lots of parameters of the DeferredInstancedBilboardShader, check it
                InstancedBilboardModel bm = new InstancedBilboardModel(factory, "Bilbs", "..\\Content\\Textures\\tree",poss.ToArray());                
                DeferredInstancedBilboardShader cb = new DeferredInstancedBilboardShader(BilboardType.Cilindric);                
                DeferredMaterial matfor = new DeferredMaterial(cb);
                GhostObject go = new GhostObject();
                IObject obj2 = new IObject(matfor, bm, go);
                this.World.AddObject(obj2);
            }


            #region NormalLight
            DirectionalLightPE ld1 = new DirectionalLightPE(Vector3.Left, Color.White);
            DirectionalLightPE ld2 = new DirectionalLightPE(Vector3.Right, Color.White);
            DirectionalLightPE ld3 = new DirectionalLightPE(Vector3.Backward, Color.White);
            DirectionalLightPE ld4 = new DirectionalLightPE(Vector3.Forward, Color.White);
            DirectionalLightPE ld5 = new DirectionalLightPE(Vector3.Down, Color.White);
            float li = 0.5f;
            ld1.LightIntensity = li;
            ld2.LightIntensity = li;
            ld3.LightIntensity = li;
            ld4.LightIntensity = li;
            ld5.LightIntensity = li;
            this.World.AddLight(ld1);
            this.World.AddLight(ld2);
            this.World.AddLight(ld3);
            this.World.AddLight(ld4);
            this.World.AddLight(ld5);
            #endregion


            CameraFirstPerson cam = new CameraFirstPerson(MathHelper.ToRadians(-50), MathHelper.ToRadians(-15), new Vector3(-200, 300, 250), GraphicInfo);
            this.World.CameraManager.AddCamera(cam);

            SkyBoxSetTextureCube stc = new SkyBoxSetTextureCube("Textures//grassCube");
            CommandProcessor.getCommandProcessor().SendCommandAssyncronous(stc);

        }