Ejemplo n.º 1
0
        public void Draw(Matrix[] transformMatrices, int totalInstances, SkinnedEffect skinnedEffect, Matrix view, Matrix proj, Texture2D skin)
        {
            skinnedEffect.EnableDefaultLighting();
            skinnedEffect.Texture = skin;
            skinnedEffect.View = view;
            skinnedEffect.Projection = proj;

            graphicsDevice.SetVertexBuffer(instancedVertexBuffer);
            graphicsDevice.Indices = instancedIndexBuffer;

            for (int i = 0; i < totalInstances; i += maxInstances)
            {
                // How many instances can we fit into this batch?
                int instanceCount = totalInstances - i;

                if (instanceCount > maxInstances)
                    instanceCount = maxInstances;

                // Upload transform matrices as shader constants.
                for (int copyIndex = 0; copyIndex < instanceCount; copyIndex++)
                    Utilities.CopyMatrix(ref transformMatrices[i + copyIndex], ref tempMatrices[copyIndex]);

                skinnedEffect.SetBoneTransforms(tempMatrices);

                foreach (EffectPass pass in skinnedEffect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    graphicsDevice.DrawIndexedPrimitives(
                        PrimitiveType.TriangleList,
                        0,
                        0,
                        instanceCount * originalVertexCount,
                        0,
                        instanceCount * originalIndexCount / 3);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // register elements
            IObjectBuilder objectBuilder = Game.Services.GetService(typeof(IObjectBuilder)) as IObjectBuilder;
            if (objectBuilder != null)
            {
                registerElements(objectBuilder);
            }

            // performance
            PerformanceMonitor perfMon = Game.Services.GetService(typeof(PerformanceMonitor)) as PerformanceMonitor;
            if (perfMon != null)
            {
                m_mainTimer = perfMon.addPerformanceMeter(new XnaScrapId("CBeroRenderManager"));
                m_sceneTimer = m_mainTimer.addSubTimer("Scene");
                m_overlayTimer = m_mainTimer.addSubTimer("Overlays");
            }

            #if WINDOWS
            // register REST stuff
            NetCtrlService netCtrlService = Game.Services.GetService(typeof(NetCtrlService)) as NetCtrlService;
            if (netCtrlService != null)
            {
                netCtrlService.AddServiceNode(new RenderManagerNode(this), this);
            }
            #endif
            base.Initialize();
            m_spriteBatch = new SpriteBatch(GraphicsDevice);
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;

            #region materials
            BasicEffect basicEffect = new BasicEffect(GraphicsDevice);
            basicEffect.EnableDefaultLighting();
            basicEffect.PreferPerPixelLighting = true;
            m_basicEffectMaterial.Effect = basicEffect;
            m_basicEffectMaterial.Technique = basicEffect.Techniques.First().Name;
            Material.ParameterMapping worldviewprojection = new Material.ParameterMapping();
            worldviewprojection.name = "WorldViewProj";
            worldviewprojection.perInstance = true;
            worldviewprojection.semantic = Material.ShaderParameterSemantic.MODEL_VIEW_PROJECTION_MATRIX;
            m_basicEffectMaterial.ParameterMappings.Add(worldviewprojection);

            SkinnedEffect skinnedEffect = new SkinnedEffect(GraphicsDevice);
            skinnedEffect.EnableDefaultLighting();
            m_skinnedEffectMaterial.Effect = skinnedEffect;
            m_skinnedEffectMaterial.Technique = skinnedEffect.Techniques.First().Name;

            RenderState.PushMaterial(m_basicEffectMaterial);
            #endregion

            #region effects
            m_defaultEffect = new CBeroEffect(this);
            m_defaultCollection = new RenderTargetCollection(DefaultRenderTarget.GetInstance().Id, new IRenderTarget[] { DefaultRenderTarget.GetInstance() });
            m_defaultCollection.Effect = m_defaultEffect;
            m_defaultEffect.AddPass(new RenderSceneWithMaterialsPass(this, m_defaultCollection));
            m_defaultEffect.AddPass(new RenderOverlaysPass(this, m_defaultCollection));

            // add DefaultRenderTarget
            m_renderTargets.Add(DefaultRenderTarget.GetInstance().Id, m_defaultCollection);
            #endregion
        }
Ejemplo n.º 3
0
        public BatchRenderedAnimatedModel(GraphicsDevice graphics, Model model)
        {
            _graphicsDevice = graphics;
            _originalModel = model;
            _originalBoneCount = model.Bones.Count;

            _skinnedEffect = new SkinnedEffect(_graphicsDevice);
            _skinnedEffect.EnableDefaultLighting();
            _skinnedEffect.AmbientLightColor = Color.Gray.ToVector3();
            _skinnedEffect.SpecularColor = Color.Black.ToVector3();
            _skinnedEffect.PreferPerPixelLighting = false;

            SetupInstancedVertexData();
        }
Ejemplo n.º 4
0
        protected override void LoadContent()
        {
            ResourceLibrary.Load(content, device);

            spritebatch = new SpriteBatch(device);

            skinnedeffect = new SkinnedEffect(device);
            skinnedeffect.EnableDefaultLighting();
            skinnedeffect.FogEnabled = false;
            skinnedeffect.PreferPerPixelLighting = true;

            dude = new ExampleModelClass(ResourceLibrary.dude, skinnedeffect);
            dude.SetWorld(Matrix.CreateScale(0.05f));
            dude.PlayAnimation(0, -1.0f, true);
        }