コード例 #1
0
 private void clearRenderTargets()
 {
     foreach (var view in views)
     {
         device.ClearRenderTargetView(view, Color.Black);
     }
 }
コード例 #2
0
        public void MainLoop(bool newScreen)
        {
            if (device != null)
            {
                //if (newScreen) //Texture seems to be destroyed after being displayed once
                {
                    unsafe
                    {
                        DataRectangle drt = texture.Map(0, MapMode.WriteDiscard, SlimDX.Direct3D10.MapFlags.None);
                        fixed(uint *screenPTR = screen)
                        {
                            imageScaler.PerformScale(screenPTR, (uint *)drt.Data.DataPointer);
                        }

                        texture.Unmap(0);
                    }
                }
                device.ClearRenderTargetView(renderTargetView, new Color4(0.0f, 0.0f, 0.0f));
                device.InputAssembler.SetInputLayout(inputLayout);
                device.InputAssembler.SetPrimitiveTopology(SlimDX.Direct3D10.PrimitiveTopology.TriangleStrip);
                device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, Marshal.SizeOf(typeof(Vertex)), 0));
                pass.Apply();
                device.Draw(4, 0);
                DrawMessageEvent(this, null);
                swapChain.Present(0, PresentFlags.None);
            }
        }
コード例 #3
0
        static public void RenderFrame()
        {
            UpdateFramerate();
            PrevTickCount = Environment.TickCount;
            device.ClearDepthStencilView(depthview, DepthStencilClearFlags.Depth, 1, 0);
            device.ClearRenderTargetView(renderview, Color.LightBlue);
            device.OutputMerger.DepthStencilState = depthstate;
            UpdateLight();
            time += 0.01f;

            //EffectTechnique t = effect.GetTechniqueByName("Blinn");
            //EffectTechnique t = effect.GetTechniqueByName("BlinnHeight");
            EffectTechnique t = effect.GetTechniqueByName("POM");

            M.Render(t);
            //L.Render(t);


            swapchain.Present(0, PresentFlags.None);
            //poczekaj
            EndTickCount = Environment.TickCount;
            while (Math.Abs(Environment.TickCount - PrevTickCount) < 16)
            {
                ;
            }
            Console.WriteLine("FPS {0:0.0} ; Light Pos: {1:0} {2:0} {3:0}", fps, LightPosition, LightPosition.Y, LightPosition.Z);
            Console.WriteLine("Rad {0:0.00}, Phi {1:0.00}, Theta {2:0.00}", radius, phi, theta);
        }
コード例 #4
0
        /// <summary>
        /// Sets the swapchain's backbuffer as the active render target and clears it.
        /// </summary>
        /// <param name="options">Clear option flags defining which buffer to clear.</param>
        /// <param name="color">Color to clear the color buffer to</param>
        /// <param name="depth">Depth value to clear the depth buffer to</param>
        /// <param name="stencil">Stencil value to clear the stencil buffer to</param>
        public override void Clear(ClearOptions options, Color color, float depth, int stencil)
        {
            if (_resetting)
            {
                return;
            }

            SlimDX.Color4 sc;
            D3D10Helper.Convert(ref color, out sc);

            _renderer.TargetManager.SetActiveSwapChain(this);

            if (_depthStencilView != null)
            {
                _graphicsDevice.OutputMerger.SetTargets(_depthStencilView, _renderTargetView);
                if (((options & ClearOptions.Depth) == ClearOptions.Depth) && ((options & ClearOptions.Stencil) == ClearOptions.Stencil))
                {
                    _graphicsDevice.ClearDepthStencilView(_depthStencilView, D3D.DepthStencilClearFlags.Depth | D3D.DepthStencilClearFlags.Stencil, depth, (byte)stencil);
                }
                else if ((options & ClearOptions.Depth) == ClearOptions.Depth)
                {
                    _graphicsDevice.ClearDepthStencilView(_depthStencilView, D3D.DepthStencilClearFlags.Depth, depth, (byte)stencil);
                }
                else if ((options & ClearOptions.Stencil) == ClearOptions.Stencil)
                {
                    _graphicsDevice.ClearDepthStencilView(_depthStencilView, D3D.DepthStencilClearFlags.Stencil, depth, (byte)stencil);
                }
                if ((options & ClearOptions.Target) == ClearOptions.Target)
                {
                    _graphicsDevice.ClearRenderTargetView(_renderTargetView, sc);
                }
            }
            else
            {
                _graphicsDevice.OutputMerger.SetTargets(_renderTargetView);
                if ((options & ClearOptions.Target) == ClearOptions.Target)
                {
                    _graphicsDevice.ClearRenderTargetView(_renderTargetView, sc);
                }
            }
        }
コード例 #5
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            // Don't use Direct3D in design mode
            if (DesignMode || _d3dDevice == null)
            {
                e.Graphics.Clear(Color.White);
            }
            else
            {
                if (_d3dDevice != null)
                {
                    _d3dDevice.ClearRenderTargetView(_renderTargetView, Color.LightGray);
                    _d3dDevice.ClearDepthStencilView(_depthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0);

                    _swapChain.Present(0, PresentFlags.None);
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Creates a new instance of <see cref="D3D10Texture2DImplementation"/>, for RenderTarget2D.
        /// </summary>
        /// <param name="renderer">The D3D10 renderer.</param>
        /// <param name="width">The texture width in pixels.</param>
        /// <param name="height">The texture height in pixels.</param>
        /// <param name="genMipMaps">True if a mipmap chain should be generated or not.</param>
        /// <param name="format">The surface format.</param>
        /// <param name="depthFormat">The depth-stencil format.</param>
        /// <param name="multiSampleCount">The multisample count.</param>
        /// <param name="usage">The target usage.</param>
        /// <exception cref="System.ArgumentException">Thrown if the formats are invalid to be used in a render target.</exception>
        internal D3D10Texture2DImplementation(D3D10Renderer renderer, int width, int height, bool genMipMaps, SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount, RenderTargetUsage usage)
            : base(width, height, format, depthFormat, multiSampleCount, usage)
        {
            _renderer       = renderer;
            _graphicsDevice = _renderer.GraphicsDevice;

            if (!renderer.Adapter.QueryRenderTargetFormat(format, depthFormat, multiSampleCount))
            {
                throw new ArgumentException("Format combination not supported.");
            }

            D3D.Texture2DDescription desc2D = new D3D.Texture2DDescription();
            desc2D.ArraySize      = 1;
            desc2D.BindFlags      = D3D.BindFlags.ShaderResource | D3D.BindFlags.RenderTarget;
            desc2D.CpuAccessFlags = D3D.CpuAccessFlags.None;
            desc2D.Format         = D3D10Helper.ToD3DSurfaceFormat(format);
            desc2D.Height         = height;
            desc2D.Width          = width;
            desc2D.Usage          = _usage = D3D.ResourceUsage.Default;
            if (genMipMaps)
            {
                desc2D.OptionFlags = D3D.ResourceOptionFlags.GenerateMipMaps;
            }
            else
            {
                desc2D.OptionFlags = D3D.ResourceOptionFlags.None;
            }
            desc2D.MipLevels = (genMipMaps) ? 0 : 1;
            if (multiSampleCount > 1)
            {
                desc2D.SampleDescription = new SlimDX.DXGI.SampleDescription(multiSampleCount, 0);
            }
            else
            {
                desc2D.SampleDescription = new DXGI.SampleDescription(1, 0);
            }

            _texture2D          = new D3D.Texture2D(_graphicsDevice, desc2D);
            _shaderResourceView = new D3D.ShaderResourceView(_graphicsDevice, _texture2D);
            _renderTargetView   = new D3D.RenderTargetView(_graphicsDevice, _texture2D);
            _graphicsDevice.ClearRenderTargetView(_renderTargetView, new SDX.Color4(1.0f, 0, 0, 0));

            //Add to tracker
            _renderer.Resources.AddTrackedObject(_texture2D.ComPointer, this);
            _renderer.Resources.AddTrackedObject(_shaderResourceView.ComPointer, this);
            _renderer.Resources.AddTrackedObject(_renderTargetView.ComPointer, this);

            _mipCount = _texture2D.Description.MipLevels;

            if (depthFormat != DepthFormat.None)
            {
                D3D.Texture2DDescription dbdesc = new D3D.Texture2DDescription();
                dbdesc.ArraySize      = 1;
                dbdesc.BindFlags      = D3D.BindFlags.DepthStencil;
                dbdesc.CpuAccessFlags = D3D.CpuAccessFlags.None;
                dbdesc.Format         = D3D10Helper.ToD3DDepthFormat(depthFormat);
                dbdesc.Height         = height;
                dbdesc.Width          = width;
                dbdesc.Usage          = D3D.ResourceUsage.Default;
                dbdesc.OptionFlags    = D3D.ResourceOptionFlags.None;
                dbdesc.MipLevels      = 1;
                if (multiSampleCount > 1)
                {
                    dbdesc.SampleDescription = new SlimDX.DXGI.SampleDescription(multiSampleCount, 0);
                }
                else
                {
                    dbdesc.SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0);
                }

                using (D3D.Texture2D depthBuffer = new D3D.Texture2D(_graphicsDevice, dbdesc)) {
                    _depthStencilView = new D3D.DepthStencilView(_graphicsDevice, depthBuffer);
                    if (depthFormat == Tesla.Graphics.DepthFormat.Depth24Stencil8)
                    {
                        _graphicsDevice.ClearDepthStencilView(_depthStencilView, D3D.DepthStencilClearFlags.Depth | D3D.DepthStencilClearFlags.Stencil, 1.0f, 0);
                    }
                    else
                    {
                        _graphicsDevice.ClearDepthStencilView(_depthStencilView, D3D.DepthStencilClearFlags.Depth, 1.0f, 0);
                    }

                    //Add to tracker
                    _renderer.Resources.AddTrackedObject(_depthStencilView.ComPointer, this);
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Creates a new instance of <see cref="D3D10TextureCubeImplementation"/>.
        /// </summary>
        /// <param name="renderer">The D3D10 renderer.</param>
        /// <param name="size">The size (width/height) of each cube face.</param>
        /// <param name="genMipMaps">True if a mipmap chain should be generated or not.</param>
        /// <param name="format">The surface  format.</param>
        /// <param name="depthFormat">The depth-stencil format.</param>
        /// <param name="multiSampleCount">The number of sample locations for multisampling</param>
        /// <param name="usage">Sets the render target's behavior.</param>
        internal D3D10TextureCubeImplementation(D3D10Renderer renderer, int size, bool genMipMaps, SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount, RenderTargetUsage usage)
            : base(size, format, depthFormat, multiSampleCount, usage)
        {
            _renderer       = renderer;
            _graphicsDevice = _renderer.GraphicsDevice;

            if (!renderer.Adapter.QueryRenderTargetFormat(format, depthFormat, multiSampleCount))
            {
                throw new ArgumentException("Format combination not supported.");
            }

            D3D.Texture2DDescription desc2D = new D3D.Texture2DDescription();
            desc2D.ArraySize      = 6;
            desc2D.BindFlags      = D3D.BindFlags.ShaderResource | D3D.BindFlags.RenderTarget;
            desc2D.CpuAccessFlags = D3D.CpuAccessFlags.None;
            desc2D.Format         = D3D10Helper.ToD3DSurfaceFormat(format);
            desc2D.Height         = size;
            desc2D.Width          = size;
            desc2D.Usage          = D3D.ResourceUsage.Default;
            if (genMipMaps)
            {
                desc2D.OptionFlags = D3D.ResourceOptionFlags.GenerateMipMaps | D3D.ResourceOptionFlags.TextureCube;
            }
            else
            {
                desc2D.OptionFlags = D3D.ResourceOptionFlags.TextureCube;
            }
            desc2D.MipLevels = (genMipMaps) ? 0 : 1;
            if (multiSampleCount > 1)
            {
                desc2D.SampleDescription = new SlimDX.DXGI.SampleDescription(multiSampleCount, 0);
            }
            else
            {
                desc2D.SampleDescription = new DXGI.SampleDescription(1, 0);
            }

            //Create the resources
            _texture2D          = new D3D.Texture2D(_graphicsDevice, desc2D);
            _shaderResourceView = new D3D.ShaderResourceView(_graphicsDevice, _texture2D);
            _renderTargetView   = new D3D.RenderTargetView[6];

            //Add to tracker
            _renderer.Resources.AddTrackedObject(_texture2D.ComPointer, this);
            _renderer.Resources.AddTrackedObject(_shaderResourceView.ComPointer, this);

            //Setup each render target view for each face
            for (int i = 0; i < 6; i++)
            {
                D3D.RenderTargetViewDescription rtDesc = new D3D.RenderTargetViewDescription();
                rtDesc.ArraySize       = 1;
                rtDesc.FirstArraySlice = i;
                if (multiSampleCount > 1)
                {
                    rtDesc.Dimension = D3D.RenderTargetViewDimension.Texture2DMultisampledArray;
                }
                else
                {
                    rtDesc.Dimension = D3D.RenderTargetViewDimension.Texture2DArray;
                }
                rtDesc.Format        = desc2D.Format;
                _renderTargetView[i] = new D3D.RenderTargetView(_graphicsDevice, _texture2D, rtDesc);
                _graphicsDevice.ClearRenderTargetView(_renderTargetView[i], new SDX.Color4(1.0f, 0, 0, 0));
                _renderer.Resources.AddTrackedObject(_renderTargetView[i].ComPointer, this);
            }

            _mipCount = _texture2D.Description.MipLevels;

            if (depthFormat != DepthFormat.None)
            {
                D3D.Texture2DDescription dbdesc = new D3D.Texture2DDescription();
                dbdesc.ArraySize      = 6;
                dbdesc.BindFlags      = D3D.BindFlags.DepthStencil;
                dbdesc.CpuAccessFlags = D3D.CpuAccessFlags.None;
                dbdesc.Format         = D3D10Helper.ToD3DDepthFormat(depthFormat);
                dbdesc.Height         = size;
                dbdesc.Width          = size;
                dbdesc.Usage          = D3D.ResourceUsage.Default;
                dbdesc.OptionFlags    = D3D.ResourceOptionFlags.None;
                dbdesc.MipLevels      = 1;
                if (multiSampleCount > 1)
                {
                    dbdesc.SampleDescription = new SlimDX.DXGI.SampleDescription(multiSampleCount, 0);
                }
                else
                {
                    dbdesc.SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0);
                }

                using (D3D.Texture2D depthBuffer = new D3D.Texture2D(_graphicsDevice, dbdesc)) {
                    _depthStencilView = new D3D.DepthStencilView(_graphicsDevice, depthBuffer);
                    if (depthFormat == Tesla.Graphics.DepthFormat.Depth24Stencil8)
                    {
                        _graphicsDevice.ClearDepthStencilView(_depthStencilView, D3D.DepthStencilClearFlags.Depth | D3D.DepthStencilClearFlags.Stencil, 1.0f, 0);
                    }
                    else
                    {
                        _graphicsDevice.ClearDepthStencilView(_depthStencilView, D3D.DepthStencilClearFlags.Depth, 1.0f, 0);
                    }
                    //Add to tracker
                    _renderer.Resources.AddTrackedObject(_depthStencilView.ComPointer, this);
                }
            }
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: Radeju/SlimDx-PhysX
        static public void RenderFrame()
        {
            device.ClearDepthStencilView(depthview, DepthStencilClearFlags.Depth, 1, 0);
            device.ClearRenderTargetView(renderview, Color.Blue);
            device.OutputMerger.DepthStencilState = depthstate;
            UpdateLight();
            time += 0.001f;
            // if (count == 500) AddBox();
            // if (count > 1000) { AddBall(); count = 0; }
            // count++;

            EffectTechnique            t    = effect.GetTechniqueByName("SimpleLight");
            RasterizerStateDescription desc = new RasterizerStateDescription();

            desc.CullMode = CullMode.None;
            desc.FillMode = FillMode.Wireframe;  //dlaczego to nei dziala?

            effect.GetVariableByName("xDiffuseTexture").AsResource().SetResource(DiffuseResource);
            //byle co, i tak renderuje tylko boxy i plane'y
            effect.GetVariableByName("xMaxMass").AsScalar().Set(MaxMass);
            effect.GetVariableByName("xMass").AsScalar().Set(1);


            SetMatrices(Matrix.RotationX(-(float)Math.PI / 2) * Matrix.Scaling(10, 10, 10) * Matrix.Translation(0, -0.2f, 0));
            Plane.Render(t);

            SetMatrices(Matrix.Scaling(10, 10, 10) * Matrix.Translation(0, 50f, -100));
            Plane.Render(t);


            SetMatrices(Matrix.RotationY((float)Math.PI / 2) * Matrix.Scaling(10, 10, 10) * Matrix.Translation(-100f, 50f, 0));
            Plane.Render(t);

            SetMatrices(Matrix.RotationY(-(float)Math.PI / 2) * Matrix.Scaling(10, 10, 10) * Matrix.Translation(100, 50f, 0));
            Plane.Render(t);

            SetMatrices(Matrix.RotationY(-(float)Math.PI) * Matrix.Scaling(10, 10, 10) * Matrix.Translation(0, 50f, 100));
            Plane.Render(t);

            SetMatrices(Matrix.RotationX((float)Math.PI / 2) * Matrix.Scaling(10, 10, 10) * Matrix.Translation(0, 100f, 0));
            Plane.Render(t);


            effect.GetVariableByName("xDiffuseTexture").AsResource().SetResource(Diffuse2Resource);


            int i = 0;

            foreach (var M in BoxMatrices)
            {
                SetMatrices(M.Value);
                if (i < howManyBeginningActors)
                {
                    SetMatrices(ScaleMatrixNoTranslation(M.Value, scale));
                    effect.GetVariableByName("xMass").AsScalar().Set(Engine.Actors[i + 7].Mass);
                }

                Boxes[i].Render(t);
                i++;
            }

            effect.GetVariableByName("xDiffuseTexture").AsResource().SetResource(Diffuse3Resource);

            i = 0;
            foreach (var M in BallMatrices)
            {
                SetMatrices(M.Value);
                Balls[i].Render(t);
                i++;
            }
            effect.GetVariableByName("xDiffuseTexture").AsResource().SetResource(Diffuse2Resource);
            foreach (var C in Engine.Scene.Cloths)
            {
                WavefrontLoader.WFOGeometry G = new WavefrontLoader.WFOGeometry(device, C, ClothGeometry);

                SetMatrices(Matrix.Identity);
                G.Render(device, t);
            }

            Engine.Step();  //dlaczego zmienia mi tutaj moje BoxMatrices? chyba w sumie musi zeby karta wiedziala co ma wyrenderowac


            swapchain.Present(0, PresentFlags.None);
            prevFrameX = curFrameX;
            prevFrameY = curFrameY;
        }
コード例 #9
0
        /// <summary>
        /// Clears the active targets, or back buffer if there are none.
        /// </summary>
        /// <param name="options"></param>
        /// <param name="color"></param>
        /// <param name="depth"></param>
        /// <param name="stencil"></param>
        public void ClearTargets(ClearOptions options, Color color, float depth, int stencil)
        {
            D3D10Helper.CheckDisposed(_graphicsDevice);
            SlimDX.Color4 sc;
            D3D10Helper.Convert(ref color, out sc);
            if (_currentRenderTargetCount == 0 && _activeBackBuffer != null)
            {
                D3D10Helper.CheckDisposed(_activeBackBuffer);
                if (_activeBackBuffer.D3D10DepthStencilView != null)
                {
                    if (((options & ClearOptions.Depth) == ClearOptions.Depth) && ((options & ClearOptions.Stencil) == ClearOptions.Stencil))
                    {
                        _graphicsDevice.ClearDepthStencilView(_activeBackBuffer.D3D10DepthStencilView, D3D.DepthStencilClearFlags.Depth | D3D.DepthStencilClearFlags.Stencil, depth, (byte)stencil);
                    }
                    else if ((options & ClearOptions.Depth) == ClearOptions.Depth)
                    {
                        _graphicsDevice.ClearDepthStencilView(_activeBackBuffer.D3D10DepthStencilView, D3D.DepthStencilClearFlags.Depth, depth, (byte)stencil);
                    }
                    else if ((options & ClearOptions.Stencil) == ClearOptions.Stencil)
                    {
                        _graphicsDevice.ClearDepthStencilView(_activeBackBuffer.D3D10DepthStencilView, D3D.DepthStencilClearFlags.Stencil, depth, (byte)stencil);
                    }
                }
                if ((_activeBackBuffer.D3D10RenderTargetView != null) && ((options & ClearOptions.Target) == ClearOptions.Target))
                {
                    _graphicsDevice.ClearRenderTargetView(_activeBackBuffer.D3D10RenderTargetView, sc);
                }
            }
            else
            {
                for (int i = 0; i < _currentRenderTargetCount; i++)
                {
                    RenderTargetBinding  binding = _currentRenderTargets[i];
                    D3D.DepthStencilView dsv     = null;
                    D3D.RenderTargetView rtv     = null;

                    if (!binding.IsRenderTargetCube)
                    {
                        D3D10Texture2DImplementation impl2D = binding.RenderTarget2D.Implementation as D3D10Texture2DImplementation;
                        D3D10Helper.CheckDisposed(impl2D);
                        dsv = impl2D.D3D10DepthStencilView;
                        rtv = impl2D.D3D10RenderTargetVew;
                    }
                    else
                    {
                        D3D10TextureCubeImplementation implcube = binding.RenderTargetCube.Implementation as D3D10TextureCubeImplementation;
                        D3D10Helper.CheckDisposed(implcube);
                        dsv = implcube.D3D10DepthStencilView;
                        rtv = implcube.GetRenderTargetView(binding.CubeMapFace);
                    }

                    if (dsv != null)
                    {
                        if (((options & ClearOptions.Depth) == ClearOptions.Depth) && ((options & ClearOptions.Stencil) == ClearOptions.Stencil))
                        {
                            _graphicsDevice.ClearDepthStencilView(dsv, D3D.DepthStencilClearFlags.Depth | D3D.DepthStencilClearFlags.Stencil, depth, (byte)stencil);
                        }
                        else if ((options & ClearOptions.Depth) == ClearOptions.Depth)
                        {
                            _graphicsDevice.ClearDepthStencilView(dsv, D3D.DepthStencilClearFlags.Depth, depth, (byte)stencil);
                        }
                        else if ((options & ClearOptions.Stencil) == ClearOptions.Stencil)
                        {
                            _graphicsDevice.ClearDepthStencilView(dsv, D3D.DepthStencilClearFlags.Stencil, depth, (byte)stencil);
                        }
                    }

                    if ((rtv != null) && ((options & ClearOptions.Target) == ClearOptions.Target))
                    {
                        _graphicsDevice.ClearRenderTargetView(rtv, sc);
                    }
                }
            }
        }
コード例 #10
0
        private void Render()
        {
            m_D3DDevice.ClearRenderTargetView(m_RenderTargetView, Color.Black);
            m_D3DDevice.ClearDepthStencilView(m_DepthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0);

            m_D3DDevice.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
            m_D3DDevice.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(m_Vertices, InputStride, 0));

            EffectTechnique technique = m_Effect.GetTechniqueByName("Render");

            for (int i = 0; i < technique.Description.PassCount; i++)
            {
                EffectPass pass   = technique.GetPassByIndex(i);
                var        layout = new InputLayout(m_D3DDevice, pass.Description.Signature, new[] {
                    new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                    new InputElement("TEXCOORD", 0, Format.R32G32_Float, 16, 0),
                    //new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0),
                });

                m_Effect.GetVariableByName("View").AsMatrix().SetMatrix(Matrix.Translation(m_Window.Width / 2.0f, m_ScrollPos + m_Window.Height / 2.0f, 0) * Matrix.LookAtLH(new Vector3(0, 0, 4), Vector3.Zero, Vector3.UnitY));
                m_Effect.GetVariableByName("Projection").AsMatrix().SetMatrix(Matrix.OrthoLH(m_Window.Width, m_Window.Height, 1, 10));

                m_D3DDevice.InputAssembler.SetInputLayout(layout);

                ShaderResourceView resource_view = new ShaderResourceView(m_D3DDevice, m_Tex);

                m_Effect.GetVariableByName("tex2D").AsResource().SetResource(resource_view);

                for (int j = 0; j < 4; j++)
                {
                    pass.Apply();

                    float imageAR    = (float)m_Tex.Description.Width / m_Tex.Description.Height;
                    float viewportAR = (float)m_Window.Width / m_Window.Height;

                    if (m_CurrentViewState is ZoomingViewState && (m_CurrentViewState as ZoomingViewState).ZoomPhoto == j)
                    {
                        float lerp_factor = (m_CurrentViewState as ZoomingViewState).GetLerpFactor(DateTime.Now);

                        bool zoom_in = (m_CurrentViewState as ZoomingViewState).ZoomIn;

                        if (lerp_factor > 1)
                        {
                            m_CurrentViewState = (m_CurrentViewState as ZoomingViewState).NextState;
                            lerp_factor        = 1;
                        }

                        if (!zoom_in)
                        {
                            lerp_factor = 1 - lerp_factor;
                        }

                        //m_Effect.GetVariableByName("AspectRatio").AsScalar().Set(imageAR / (float)Math.Pow(viewportAR, lerp_factor));
                        m_Effect.GetVariableByName("AspectRatio").AsScalar().Set(Lerp(imageAR, imageAR / viewportAR, lerp_factor));

                        m_Effect.GetVariableByName("World").AsMatrix().SetMatrix(Matrix.Lerp(GetWorldTransform(j), GetZoomTransform(), lerp_factor));
                    }
                    else if (m_CurrentViewState is ZoomedViewState && (m_CurrentViewState as ZoomedViewState).ZoomPhoto == j)
                    {
                        m_Effect.GetVariableByName("AspectRatio").AsScalar().Set(imageAR / viewportAR);
                        m_Effect.GetVariableByName("World").AsMatrix().SetMatrix(GetZoomTransform());
                    }
                    else
                    {
                        m_Effect.GetVariableByName("AspectRatio").AsScalar().Set(imageAR);
                        m_Effect.GetVariableByName("World").AsMatrix().SetMatrix(GetWorldTransform(j));
                    }
                    m_D3DDevice.Draw(4, 0);
                }
            }

            m_SwapChain.Present(1, PresentFlags.None);
        }