Пример #1
0
        private void DrawShadow(Vector3 from, Vector3?up = null)
        {
            from.Normalize();
            _effect.FxLightDir.Set(from);

            DeviceContext.OutputMerger.BlendState        = null;
            DeviceContext.OutputMerger.DepthStencilState = null;
            DeviceContext.Rasterizer.SetViewports(_shadowViewport);

            DeviceContext.ClearDepthStencilView(_shadowBuffer.DepthView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1f, 0);
            DeviceContext.OutputMerger.SetTargets(_shadowBuffer.DepthView);

            _shadowCamera.LookAt(from * _shadowCamera.FarZValue * 0.5f, Vector3.Zero, up ?? Vector3.UnitY);
            _shadowCamera.UpdateViewMatrix();

            if (_flattenNodes == null)
            {
                _flattenNodes = Flatten(Scene, x => (x as Kn5RenderableDepthOnlyObject)?.OriginalNode.CastShadows != false &&
                                        IsVisible(x)).OfType <Kn5RenderableDepthOnlyObject>().ToArray();
                var states = new[] { _rasterizerStateFrontCull, _rasterizerStateBackCull };
                _flattenNodes.ForEach(x => x.SeveralRasterizerStates = states);
            }

            for (var i = 0; i < _flattenNodes.Length; i++)
            {
                _flattenNodes[i].Draw(DeviceContextHolder, _shadowCamera, SpecialRenderMode.Simple);
            }
        }
        private void DrawShadow(Vector3 from, Vector3?up = null)
        {
            DeviceContext.OutputMerger.DepthStencilState = null;
            DeviceContext.OutputMerger.BlendState        = null;
            DeviceContext.Rasterizer.State = DeviceContextHolder.States.DoubleSidedState;
            DeviceContext.Rasterizer.SetViewports(_shadowViewport);

            DeviceContext.ClearDepthStencilView(_shadowBuffer.DepthView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1f, 0);
            DeviceContext.OutputMerger.SetTargets(_shadowBuffer.DepthView);

            _shadowCamera.LookAt(Vector3.Normalize(from) * _shadowCamera.FarZValue * 0.8f, Vector3.Zero, up ?? Vector3.UnitY);
            _shadowCamera.UpdateViewMatrix();

            if (HideWheels && !_wheelMode)
            {
                var wheelNodes = new[] {
                    "WHEEL_LF", "WHEEL_LR", "WHEEL_RF", "WHEEL_RR",
                    "HUB_LF", "HUB_LR", "HUB_RF", "HUB_RR",
                    "SUSP_LF", "SUSP_LR", "SUSP_RF", "SUSP_RR",
                };
                _scene.Draw(DeviceContextHolder, _shadowCamera, SpecialRenderMode.Simple, x => !wheelNodes.Contains((x as Kn5RenderableList)?.OriginalNode.Name));
            }
            else
            {
                _scene.Draw(DeviceContextHolder, _shadowCamera, SpecialRenderMode.Simple);
            }
        }
Пример #3
0
        private void DrawShadow(Vector3 from, Vector3?up = null)
        {
            DeviceContext.OutputMerger.DepthStencilState = null;
            DeviceContext.OutputMerger.BlendState        = null;
            DeviceContext.Rasterizer.State = DeviceContextHolder.States.DoubleSidedState;
            DeviceContext.Rasterizer.SetViewports(_shadowViewport);

            DeviceContext.ClearDepthStencilView(_shadowBuffer.DepthView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1f, 0);
            DeviceContext.OutputMerger.SetTargets(_shadowBuffer.DepthView);

            _shadowCamera.LookAt(Vector3.Normalize(from) * _shadowCamera.FarZValue * 0.8f, Vector3.Zero, up ?? Vector3.UnitY);
            _shadowCamera.UpdateViewMatrix();

            if (_flattenNodes == null)
            {
                string[] ignored;

                if (HideWheels && !_wheelMode)
                {
                    ignored = WheelNodeNames.SelectMany(x => WheelNodeCorners.Select(y => $"{x}_{y}")).Append("COCKPIT_HR", "STEER_HR").ToArray();
                }
                else
                {
                    ignored = new[] {
                        "COCKPIT_HR", "STEER_HR",
                    };
                }

                if (UpDelta != 0f)
                {
                    _flattenNodesFix = new List <Tuple <Kn5RenderableList, Matrix> >();
                    foreach (var wheel in WheelNodeCorners.Select(x => WheelNodeNames.Select(y => Scene.GetDummyByName($"{y}_{x}"))
                                                                  .FirstOrDefault(y => y != null)).NonNull())
                    {
                        _flattenNodesFix.Add(Tuple.Create(wheel, wheel.ParentMatrix));
                        wheel.ParentMatrix = Matrix.Translation(0, UpDelta, 0) * wheel.ParentMatrix;
                    }
                }

                _flattenNodes = Flatten(Scene, x =>
                                        (x as Kn5RenderableDepthOnlyObject)?.OriginalNode.CastShadows != false &&
                                        !ignored.ArrayContains((x as Kn5RenderableList)?.Name) && IsVisible(x))
                                .OfType <Kn5RenderableDepthOnlyObject>().ToArray();
            }

            for (var i = 0; i < _flattenNodes.Length; i++)
            {
                _flattenNodes[i].Draw(DeviceContextHolder, _shadowCamera, SpecialRenderMode.Simple);
            }
        }
Пример #4
0
        private void DrawShadow(Vector3 from, Vector3?up = null)
        {
            DeviceContext.OutputMerger.DepthStencilState = null;
            DeviceContext.OutputMerger.BlendState        = null;
            DeviceContext.Rasterizer.State = DeviceContextHolder.States.DoubleSidedState;
            DeviceContext.Rasterizer.SetViewports(_shadowViewport);

            DeviceContext.ClearDepthStencilView(_shadowBuffer.DepthView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1f, 0);
            DeviceContext.OutputMerger.SetTargets(_shadowBuffer.DepthView);

            _shadowCamera.LookAt(Vector3.Normalize(from) * _shadowCamera.FarZValue * 0.8f, Vector3.Zero, up ?? Vector3.UnitY);
            _shadowCamera.UpdateViewMatrix();

            if (_flattenNodes == null)
            {
                string[] ignored;

                if (HideWheels && !_wheelMode)
                {
                    ignored = new[] {
                        "WHEEL_LF", "WHEEL_LR", "WHEEL_RF", "WHEEL_RR",
                        "HUB_LF", "HUB_LR", "HUB_RF", "HUB_RR",
                        "SUSP_LF", "SUSP_LR", "SUSP_RF", "SUSP_RR",
                        "COCKPIT_HR", "STEER_HR",
                    };
                }
                else
                {
                    ignored = new[] {
                        "COCKPIT_HR", "STEER_HR",
                    };
                }

                _flattenNodes = Flatten(Scene, x =>
                                        (x as Kn5RenderableDepthOnlyObject)?.OriginalNode.CastShadows != false &&
                                        !ignored.Contains((x as Kn5RenderableList)?.Name) && IsVisible(x))
                                .ToArray();
            }

            for (var i = 0; i < _flattenNodes.Length; i++)
            {
                _flattenNodes[i].Draw(DeviceContextHolder, _shadowCamera, SpecialRenderMode.Simple);
            }
        }
Пример #5
0
            private CameraOrtho GetCamera(DeviceContextHolder holder)
            {
                if (_camera == null)
                {
                    if (_dirty)
                    {
                        Initialize(holder);
                    }

                    var laneBox = _obj.BoundingBox ?? new BoundingBox();

                    var boxWidth  = DataSize.X;
                    var boxHeight = DataSize.Y;
                    var boxMinX   = -DataOffset.X + DataMargin;
                    var boxMinY   = -DataOffset.Y + DataMargin;

                    var box = new BoundingBox(
                        new Vector3(boxMinX, laneBox.Minimum.Y, boxMinY),
                        new Vector3(boxMinX + boxWidth, laneBox.Maximum.Y, boxMinY + boxHeight));

                    _camera = new CameraOrtho {
                        Position       = new Vector3(box.GetCenter().X, box.Maximum.Y + 1f, box.GetCenter().Z),
                        FarZ           = box.GetSize().Y + 2f,
                        Target         = box.GetCenter(),
                        Up             = new Vector3(0.0f, 0.0f, -1.0f),
                        Width          = box.GetSize().X + 2 * DataMargin,
                        Height         = box.GetSize().Z + 2 * DataMargin,
                        DisableFrustum = true
                    };

                    _camera.SetLens();
                    _camera.UpdateViewMatrix();
                }

                return(_camera);
            }
Пример #6
0
 public override void UpdateViewMatrix()
 {
     base.UpdateViewMatrix();
     _innerCamera.UpdateViewMatrix();
 }