Exemple #1
0
        public override void RenderScene(DrawEventArgs args)
        {
            float t = 1f;

            Device.ImmediateContext.ClearRenderTargetView(this.RenderTargetView, Color.White);
            Device.ImmediateContext.ClearDepthStencilView(this.DepthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0);

            var matWorld = Matrix.RotationX(t);

            m_pConstantBuffer.Value = new Projections
            {
                Projection = Matrix.Transpose(Camera.Projection),
                View = Matrix.Transpose(Camera.View),
                World = Matrix.Transpose(matWorld),
            };

            Device.ImmediateContext.VertexShader.Set(m_pVertexShader);
            Device.ImmediateContext.VertexShader.SetConstantBuffer(0, m_pConstantBuffer.Buffer);
            Device.ImmediateContext.PixelShader.Set(m_pPixelShader);
            Device.ImmediateContext.PixelShader.SetConstantBuffer(0, m_pConstantBuffer.Buffer);
            Device.ImmediateContext.DrawIndexed(indicecount, 0, 0);
        }
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public DrawEventArgs GetDrawEventArgs()
 {
     var eargs = new DrawEventArgs
     {
         TotalTime = m_renderTimer.Elapsed,
         DeltaTime = m_lastDrawEventArgs != null ? m_renderTimer.Elapsed - m_lastDrawEventArgs.TotalTime : TimeSpan.Zero,
         RenderSize = DesiredSize,
         Target = Surface,
     };
     m_lastDrawEventArgs = eargs;
     return eargs;
 }
Exemple #3
0
        public override void RenderScene(DrawEventArgs args)
        {
            if (!modelLoaded)
                return;

            float t = 1f;

            Device.ImmediateContext.ClearRenderTargetView(this.RenderTargetView, SharpDX.Color.White);
            Device.ImmediateContext.ClearDepthStencilView(this.DepthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0);

            var matWorld = Matrix.RotationX(t);

            m_pConstantBuffer.Value = new Projections
            {
                Projection = Matrix.Transpose(Camera.Projection),
                View = Matrix.Transpose(Camera.View),
                World = Matrix.Transpose(matWorld),
            };

            Device.ImmediateContext.VertexShader.Set(m_pVertexShader);
            Device.ImmediateContext.VertexShader.SetConstantBuffer(0, m_pConstantBuffer.Buffer);
            Device.ImmediateContext.PixelShader.Set(m_pPixelShader);
            Device.ImmediateContext.PixelShader.SetConstantBuffer(0, m_pConstantBuffer.Buffer);

            if (WMOrenderBatches != null)
            {
                for (int i = 0; i < WMOrenderBatches.Count(); i++)
                {
                    var textureView = new ShaderResourceView(Device, materials[WMOrenderBatches[i].materialID].texture);
                    var sampler = new SamplerState(Device, new SamplerStateDescription()
                    {
                        Filter = Filter.MinMagMipLinear,
                        AddressU = TextureAddressMode.Wrap,
                        AddressV = TextureAddressMode.Wrap,
                        AddressW = TextureAddressMode.Wrap,
                        BorderColor = SharpDX.Color.Black,
                        ComparisonFunction = Comparison.Never,
                        MaximumAnisotropy = 16,
                        MipLodBias = 0,
                        MinimumLod = 0,
                        MaximumLod = 16,
                    });

                    Device.ImmediateContext.PixelShader.SetSampler(0, sampler);
                    Device.ImmediateContext.PixelShader.SetShaderResource(0, textureView);

                    Device.ImmediateContext.DrawIndexed((int)WMOrenderBatches[i].numFaces, (int)WMOrenderBatches[i].firstFace, 0);
                }
            }
            /*else
            {
                Device.ImmediateContext.DrawIndexed(indicecount, 0, 0);
            }*/
            if (M2renderBatches != null)
            {
                for (int i = 0; i < M2renderBatches.Count(); i++)
                {
                    if (M2renderBatches[i].materialID > m2materials.Count() - 1) //temp hackfix
                    {
                        continue;
                    }

                    var textureView = new ShaderResourceView(Device, m2materials[M2renderBatches[i].materialID].texture);
                    var sampler = new SamplerState(Device, new SamplerStateDescription()
                    {
                        Filter = Filter.MinMagMipLinear,
                        AddressU = TextureAddressMode.Wrap,
                        AddressV = TextureAddressMode.Wrap,
                        AddressW = TextureAddressMode.Wrap,
                        BorderColor = SharpDX.Color.Black,
                        ComparisonFunction = Comparison.Never,
                        MaximumAnisotropy = 16,
                        MipLodBias = 0,
                        MinimumLod = 0,
                        MaximumLod = 16,
                    });

                    Device.ImmediateContext.PixelShader.SetSampler(0, sampler);
                    Device.ImmediateContext.PixelShader.SetShaderResource(0, textureView);

                    Device.ImmediateContext.DrawIndexed((int)M2renderBatches[i].numFaces, (int)M2renderBatches[i].firstFace, 0);
                }
            }
        }
Exemple #4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="args"></param>
 public override void EndRender(DrawEventArgs args)
 {
     m_renderTarget2D.EndDraw();
     base.EndRender(args);
 }
Exemple #5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="args"></param>
 public override void BeginRender(DrawEventArgs args)
 {
     base.BeginRender(args);
     m_renderTarget2D.BeginDraw();
 }
        private void SetShaderParameters(DrawEventArgs args)
        {
            Geometry shape = core.Actor.Shape;

            if (core.UseTurntable)
            {
                float t = (float)args.TotalTime.TotalSeconds * core.TurntableSpeed;
                core.Actor.Rotation = Quaternion.RotationAxis(VSTools.UnitY, t);
            }

            // Update matrices in the constant buffer
            Matrix modelMatrix = Matrix.Scaling(core.Actor.LocalScale) * Matrix.RotationQuaternion(core.Actor.Rotation) * Matrix.Translation(core.Actor.Position);
            MatrixBuffer projectionModel = new MatrixBuffer
            {
                World = Matrix.Transpose((Camera as VSViewerCamera).World),
                View = Matrix.Transpose((Camera.View)),
                Projection = Matrix.Transpose(Camera.Projection)
            };
            m_matrixBuffer.Value = projectionModel;

            // Set Vertex shader resources
            Device.ImmediateContext.VertexShader.SetConstantBuffer(0, m_matrixBuffer.Buffer);
            Device.ImmediateContext.UpdateSubresource(shape.instancedVertices, vertexBuffer);

            // Set pixel shader resources
            Device.ImmediateContext.PixelShader.SetShaderResource(0, m_textureResourceView);
        }
        public override void RenderScene(DrawEventArgs args)
        {
            // fill the back buffer with solid black
            Device.ImmediateContext.ClearRenderTargetView(RenderTargetView, new Color4(0, 0, 0, 1));
            // clear depth buffer
            Device.ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth, 1f, 0);

            // tick the core to update all render required actions
            core.TickRendered(args.DeltaTime);

            if (core.Actor.Shape == null) { return; }

            UpdateAnimation();
            ApplySkinning();
            UpdateTexture();
            UpdateVertexAndIndiceBuffers();
            SetShaderParameters(args);
            PushShaders();
        }