public void Render(DxCamera camera)
        {
            if (_vertexBuffer == null || _vertexCount == 0)
            {
                return;
            }

            _worldVar.SetMatrix(Matrix.Scaling(Scale, -Scale, Scale));
            _eyePosWVar.Set(camera.Eye);
            _viewProjVar.SetMatrix(camera.View * camera.Projection);
            _fillColorVar.Set(_fillColor);

            _resVar.Set(new Vector2(_xRes, _yRes));
            _focalLengthDepthVar.Set(_focalLengthDepth);
            _focalLengthImageVar.Set(_focalLengthImage);
            _depthToRgbVar.SetMatrix(_depthToRgb);

            _depthMapVar.SetResource(_depthMapBufferRV);
            _imageMapVar.SetResource(_imageTextureRV);

            _dxDevice.InputAssembler.SetInputLayout(_inputLayout);
            _dxDevice.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.PointList);
            _dxDevice.InputAssembler.SetVertexBuffers(0,
                                                      new VertexBufferBinding(_vertexBuffer, PointVertex.SizeOf, 0));

            for (int p = 0; p < _renderTech.Description.PassCount; p++)
            {
                _renderTech.GetPassByIndex(p).Apply();
                _dxDevice.Draw(_vertexCount, 0);
            }
        }
示例#2
0
        public DxScene()
        {
            ClientWidth  = 100;
            ClientHeight = 100;
            Camera       = new DxCamera();

            InitD3D();
        }
示例#3
0
        public DxScene()
        {
            ClientWidth = 100;
            ClientHeight = 100;
            Camera = new DxCamera();

            InitD3D();
        }
示例#4
0
        public static void SetFromWpfCamera(this DxCamera thisCamera, System.Windows.Media.Media3D.PerspectiveCamera wpfCamera)
        {
            thisCamera.At  = (wpfCamera.Position + wpfCamera.LookDirection).ToVector3();
            thisCamera.Eye = wpfCamera.Position.ToVector3();
            thisCamera.Up  = wpfCamera.UpDirection.ToVector3();

            thisCamera.NearDistance = (float)wpfCamera.NearPlaneDistance;
            thisCamera.FarDistance  = (float)wpfCamera.FarPlaneDistance;
            thisCamera.FOV          = (float)DegreeToRadian(wpfCamera.FieldOfView);
        }
        public void Render(DxCamera camera)
        {
            //
            // Set constants.
            //
            _viewProjVar.SetMatrix(camera.View * camera.Projection);
            _gameTimeVar.Set(_gameTime);
            _timeStepVar.Set(_timeStep);
            _eyePosVar.Set(camera.Eye);
            _emitPosVar.Set(_emitPosW);
            _emitDirVar.Set(_emitDirW);
            _texArrayVar.SetResource(_texArrayRV);
            _randomTexVar.SetResource(_randomTexRV);

            //
            // Set IA stage.
            //
            _dxDevice.InputAssembler.SetInputLayout(_vertexLayout);
            _dxDevice.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.PointList);
            int       stride = Marshal.SizeOf(typeof(ParticleVertex));
            const int offset = 0;

            // On the first pass, use the initialization VB. Otherwise, use
            // the VB that contains the current particle list.
            _dxDevice.InputAssembler.SetVertexBuffers(0,
                                                      new VertexBufferBinding(_firstRun ? _initVB : _drawVB, stride, offset));

            //
            // Draw the current particle list using stream output only to update
            // them. The updated vertices are streamed out to the target VB.
            //
            _dxDevice.StreamOutput.SetTargets(
                new StreamOutputBufferBinding(_streamOutVB, offset));

            for (int p = 0; p < _streamOutTech.Description.PassCount; ++p)
            {
                _streamOutTech.GetPassByIndex(p).Apply();
                if (_firstRun)
                {
                    _dxDevice.Draw(1, 0);
                    _firstRun = false;
                }
                else
                {
                    _dxDevice.DrawAuto();
                }
            }

            // done streaming out--unbind the vertex buffer
            _dxDevice.StreamOutput.SetTargets(null);

            // ping-pong the vertex buffers
            var tmpVB = _drawVB;

            _drawVB      = _streamOutVB;
            _streamOutVB = tmpVB;

            //
            // Draw the updated particle system we just streamed out.
            //
            _dxDevice.InputAssembler.SetVertexBuffers(0,
                                                      new VertexBufferBinding(_drawVB, stride, offset));

            for (int p = 0; p < _drawTech.Description.PassCount; ++p)
            {
                _drawTech.GetPassByIndex(p).Apply();
                _dxDevice.DrawAuto();
            }
        }
        public void Render(DxCamera camera)
        {
            if (_vertexBuffer == null || _vertexCount == 0)
                return;

            _worldVar.SetMatrix(Matrix.Scaling(Scale, -Scale, Scale));
            _eyePosWVar.Set(camera.Eye);
            _viewProjVar.SetMatrix(camera.View*camera.Projection);
            _fillColorVar.Set(_fillColor);

            _resVar.Set(new Vector2(_xRes, _yRes));
            _focalLengthDepthVar.Set(_focalLengthDepth);
            _focalLengthImageVar.Set(_focalLengthImage);
            _depthToRgbVar.SetMatrix(_depthToRgb);

            if (_headlight)
            {
                _light.Position = camera.Eye;
                _light.Direction = camera.At - camera.Eye;
            }
            _light.SetEffectVariable(_lightVariable);

            _depthMapVar.SetResource(_depthMapBufferRV);
            _imageMapVar.SetResource(_imageTextureRV);

            _dxDevice.InputAssembler.SetInputLayout(_inputLayout);
            _dxDevice.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
            _dxDevice.InputAssembler.SetIndexBuffer(_indexBuffer, Format.R32_UInt, 0);
            _dxDevice.InputAssembler.SetVertexBuffers(0,
                new VertexBufferBinding(_vertexBuffer, PointVertex.SizeOf, 0));

            for (int p = 0; p < _renderTech.Description.PassCount; p++)
            {
                _renderTech.GetPassByIndex(p).Apply();
                _dxDevice.DrawIndexed(_indexCount, 0, 0);
            }
        }