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);
            }
        }
Beispiel #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);
            }
        }
Beispiel #4
0
            public override void LookAt(Vector3 pos, Vector3 target, Vector3 up)
            {
                base.LookAt(pos, target, up);

                if (!Equals(_innerCamera.FarZ, FarZ))
                {
                    _innerCamera.Aspect = Aspect;
                    _innerCamera.NearZ  = NearZ;
                    _innerCamera.FarZ   = FarZ;
                    _innerCamera.Width  = Width * 0.95f;
                    _innerCamera.Height = Height * 0.95f;
                    _innerCamera.SetLens(1f);
                }

                _innerCamera.LookAt(pos, target, up);
            }
Beispiel #5
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);
            }
        }