Esempio n. 1
0
        public void Render()
        {
            //effect.View = camera.View;
            //effect.Projection = camera.Projection;
            graphics.Clear(Color.Black);

            skybox.Render(camera.View, camera.Projection, camera.Position);

            var viewProjection = camera.View * camera.Projection;
            var viewfrustum    = new BoundingFrustum(viewProjection);

            effect.Parameters["View"].SetValue(camera.View);
            instancingEffect.Parameters["View"].SetValue(camera.View);
            effect.Parameters["Projection"].SetValue(camera.Projection);
            instancingEffect.Parameters["Projection"].SetValue(camera.Projection);
            // effect.Parameters["AmbientColor"].SetValue(new Vector4(0.1f, 0.1f, 0.1f, 1));
            //effect.Parameters["AmbientIntensity"].SetValue(1f);
            effect.Parameters["DiffuseLightDirection1"].SetValue(new Vector3(-1, -1f, -1f));
            instancingEffect.Parameters["DiffuseLightDirection1"].SetValue(new Vector3(-1, -1f, -1f));
            // effect.Parameters["DiffuseLightDirection2"].SetValue(new Vector3(-0.4f, -0.4f, -0.4f));
            //effect.Parameters["DiffuseColor"].SetValue(new Vector4(1f, 1f, 1f, 1));
            //effect.Parameters["DiffuseIntensity"].SetValue(1f);

            graphics.RasterizerState = new RasterizerState()
            {
                CullMode = CullMode.CullClockwiseFace
            };
            foreach (var pass in effect.CurrentTechnique.Passes)
            {
                Objects.ForEach(a => a.Render(graphics, effect, pass, viewfrustum, false));
            }
            foreach (var pass in instancingEffect.CurrentTechnique.Passes)
            {
                Objects.ForEach(a => a.Render(graphics, instancingEffect, pass, viewfrustum, true));
            }
            graphics.RasterizerState = new RasterizerState()
            {
                CullMode = CullMode.CullCounterClockwiseFace
            };

            if (RenderDebug)
            {
                Canvas.DebugRender(spritebatch);
            }
            else
            {
                Canvas.Render(spritebatch);
            }
        }