Ejemplo n.º 1
0
        private void DrawMeshPart(Mesh mesh, MeshPart part, GraphicDevice device)
        {
            device.SetVertexBuffer(0, mesh.VertexBuffer, 0);
            device.SetIndexBuffer(mesh.IndexBuffer);
            var effect = Effect;

            foreach (var pass in effect.Passes())
            {
                effect.Apply(pass);
                device.DrawIndexed(part.IndexCount, part.StartIndex, 0);
            }
        }
Ejemplo n.º 2
0
        private void DrawMesh(Mesh mesh, GraphicDevice device)
        {
            device.SetVertexBuffer(0, mesh.VertexBuffer, 0);
            device.SetIndexBuffer(mesh.IndexBuffer);
            var effect = Effect;

            foreach (var pass in effect.Passes())
            {
                effect.Apply(pass);
                device.DrawIndexed(mesh.Layers[0].IndexCount, 0, 0);
            }
        }
Ejemplo n.º 3
0
        public void Draw(GraphicDevice device, Effect effect)
        {
            device.PrimitiveTopology = IAPrimitive.TriangleList;
            device.SetVertexBuffer(0, _vb, 0);
            device.SetIndexBuffer(_ib);

            foreach (var pass in effect.Passes())
            {
                effect.Apply(pass);
                foreach (var part in _layers)
                {
                    device.DrawIndexed(part.IndexCount, part.StartIndex, 0);
                }
            }
        }
        private void RenderLayers(GraphicDevice device, MeshPart[] layers)
        {
            var effect = this.Effect;

            effect.OnRender(this);

            foreach (var pass in effect.Passes())
            {
                effect.Apply(pass);
                foreach (var layer in layers)
                {
                    device.DrawIndexed(layer.primitiveCount * 3, layer.startIndex, 0);
                }
            }
            effect.EndPasses();
        }
Ejemplo n.º 5
0
        private void RenderLayers(GraphicDevice device,
                                  MeshSkin skin,
                                  Frame[] bones,
                                  Matrix[] boneOffsetMatrices,
                                  ref Matrix bindShapePose,
                                  MeshPart[] layers)
        {
            var effect = this.Effect;

            effect.OnRender(this);

            foreach (var pass in effect.Passes())
            {
                effect.Apply(pass);
                foreach (var layer in layers)
                {
                    #region Compute Bone Matrices

                    var bonesIDs = skin.GetBones(layer);
                    if (bonesIDs != null)
                    {
                        int paletteEntry = 0;
                        for (paletteEntry = 0; paletteEntry < bonesIDs.Length; paletteEntry++)
                        {
                            int boneIndex = bonesIDs[paletteEntry];

                            Matrix globalPose = bones[boneIndex].GlobalPose;

                            Matrix.Multiply(ref bindShapePose, ref boneOffsetMatrices[boneIndex], out _boneMatrices[paletteEntry]);
                            Matrix.Multiply(ref _boneMatrices[paletteEntry], ref globalPose, out _boneMatrices[paletteEntry]);
                            //boneMatrices[paletteEntry] = skin.BindShapePose * boneOffsetMatrices[boneIndex] * bones[boneIndex].GlobalPose;
                        }

                        SkinMap.WorldArray = new SArray <Matrix>(_boneMatrices, paletteEntry);
                        //mapping.WorldArray = boneMatrices;
                    }

                    #endregion

                    device.DrawIndexed(layer.primitiveCount * 3, layer.startIndex, 0);
                }
            }
            effect.EndPasses();
        }
Ejemplo n.º 6
0
        private void RenderFrame()
        {
            //Set the render target and the depth stencil buffers
            //for rendering to the display just set the device default
            //BackBuffer and BackDepthBuffer
            device.SetRenderTarget(device.BackBuffer, device.BackDepthBuffer);

            //Set the ViewPort to used by the device during the viewport tranformation
            device.ViewPort = new ViewPort(0, 0, Width, Height);

            //Clear the render target and depth stencil buffers
            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, new Color4(0, 0, 0, 0), 1, 0);

            //Set the primitive type
            device.PrimitiveTopology = IAPrimitive.TriangleList;

            //Bind the vertex buffer to slot 0 at offset 0
            device.SetVertexBuffer(0, vertexBuffer, 0);

            //Set the index buffer
            device.SetIndexBuffer(indexBuffer);


            //Send the transformation matrices to the vertex shader
            input.World      = Matrix.RotationY(-(float)Environment.TickCount / 5000.0f);
            input.View       = view;
            input.Projection = projection;

            //Send the light info and other values to the pixel shader
            input.CameraPosition    = cameraPosition;
            input.ReflectionRatio   = 0.05f;
            input.SpecularRatio     = 0.15f;
            input.SpecularStyleLerp = 0.15f;
            input.SpecularPower     = 8;
            input.DirectionalLight  = new DirectionalLight
            {
                Color     = Color3.White,
                Direction = new Euler(45, 0, 0).ToDirection()
            };

            //Bind a texture with a sampler state. As a convetion the SamplerState
            //in the shader must have the same name as the texture with 's' as prefix
            //for example in the shader the sampler state is declared
            //SamplerState sDiffuseTexture;
            input.DiffuseTexture = diffuseTexture.ToSampler(diffuseSampler);

            device.GetShaderStage <PixelShader>().SetResource(0, diffuseTexture);
            device.GetShaderStage <PixelShader>().SetSampler(0, diffuseSampler);

            //Bind textures with default sampler state (linear filtering and wrap TextureAddressMode).
            //these statements have the same behavior that calling nightTexture.ToSampler()
            input.NightTexture     = nightTexture;
            input.NormalMapTexture = normalMapTexture;
            input.ReflectionMask   = reflectionMask;


            //Set the shader program
            device.Program = shaderProgram;

            //Draw the geometry using the indices count, the start index an the vertex base offset
            device.DrawIndexed((int)indexBuffer.SizeInBytes / indexBuffer.Stride, 0, 0);

            //Present the render target buffer to the display.
            device.Present();
        }