public RenderPipeline(GraphicsDevice dev, Camera c)
        {
            Device = dev;
            Camera = c;
            _visualizationEffect = new BasicEffect(this.Device)
            {
                VertexColorEnabled = true
            };
            frustumForShadow = new BoundingFrustum(Matrix.Identity);
            debugRenderer = new DebugRender.DebugRenderer(Device, _visualizationEffect);
            debugRenderArray = new MyContainer<PivotObject>(10, 3);
            EnableShadows = SmoothShadows = EnableGrass = true;
            EnableDebugRender = true;
               rs = createNewState(RasterizerState.CullClockwise);
            rs.CullMode = CullMode.None;
            Device.RasterizerState = rs;
            //EnableShadows = false;
            //SmoothShadows = false;
            if (EnableShadows)
            {
                if (dev.GraphicsProfile == GraphicsProfile.HiDef)
                {
                    shadowRenderTarget = new RenderTarget2D(Device,
                                                           shadowMapWidthHeight,
                                                           shadowMapWidthHeight,
                                                           false,
                                                           SurfaceFormat.Single,
                                                           DepthFormat.Depth16);
                }
                else
                {
                    if (GraphicsAdapter.DefaultAdapter.IsProfileSupported(GraphicsProfile.HiDef))
                    {
                        shadowRenderTarget = new RenderTarget2D(Device,
                                                               shadowMapWidthHeight,
                                                               shadowMapWidthHeight,
                                                               false,
                                                               SurfaceFormat.Color,
                                                               DepthFormat.None, 0, RenderTargetUsage.DiscardContents);
                    }
                    else
                    {
                        //TODO to cofig
                        shadowRenderTarget = new RenderTarget2D(Device,
                                                                                     dev.PresentationParameters.BackBufferWidth,
                                                                                      dev.PresentationParameters.BackBufferHeight,
                                                                                     false,
                                                                                     SurfaceFormat.Color,
                                                                                     DepthFormat.None);
                    }
                    SmoothShadows = false;
                }
            }
            arrays = new List<string>();

            if (dev.GraphicsProfile == GraphicsProfile.Reach)
            {
                Shader.AnimRenderSM = "AnimRenderSMR";
                Shader.NotAnimRenderSM = "NotAnimRenderSMR";

                Shader.AnimRenderSMSmooth = Shader.AnimRenderSM;
                Shader.NotAnimRenderSMSmooth = Shader.NotAnimRenderSM;

                Shader.CreateStaticShadowMap = "CreateStaticShadowMapR";
                Shader.CreateAnimShadowMap = "CreateAnimShadowMapR";
            }

            arrays.Add(Shader.AnimRenderNoSM);
            arrays.Add(Shader.NotAnimRenderNoSM);
            arrays.Add(Shader.AnimRenderSM);
            arrays.Add(Shader.NotAnimRenderSM);
            arrays.Add(Shader.AnimRenderSMSmooth);
            arrays.Add(Shader.NotAnimRenderSMSmooth);
            arrays.Add(Shader.CreateStaticShadowMap);
            arrays.Add(Shader.CreateAnimShadowMap);

            ArraysPerTehnique.Add(Shader.AnimRenderNoSM, new RenderArray(Shader.AnimRenderNoSM));
            ArraysPerTehnique.Add(Shader.NotAnimRenderNoSM, new RenderArray(Shader.NotAnimRenderNoSM));

            ArraysPerTehnique.Add(Shader.AnimRenderSM, new RenderArray(Shader.AnimRenderSM));
            ArraysPerTehnique.Add(Shader.NotAnimRenderSM, new RenderArray(Shader.NotAnimRenderSM));
            if (dev.GraphicsProfile == GraphicsProfile.HiDef)
            {
                ArraysPerTehnique.Add(Shader.AnimRenderSMSmooth, new RenderArray(Shader.AnimRenderSMSmooth));
                ArraysPerTehnique.Add(Shader.NotAnimRenderSMSmooth, new RenderArray(Shader.NotAnimRenderSMSmooth));
            }
            ArraysPerTehnique.Add(Shader.CreateStaticShadowMap, new RenderArray(Shader.CreateStaticShadowMap));
            ArraysPerTehnique.Add(Shader.CreateAnimShadowMap, new RenderArray(Shader.CreateAnimShadowMap));
        }
Esempio n. 2
0
        public void Initalize()
        {
            FPSCounter = new Helpers.FpsCounter();
            this.Camera = new Camera(this, new Vector3(20, 20, 10), new Vector3(0, 15, 0));
            spriteBatch = new SpriteBatch(DeviceManager.GraphicsDevice);
            #region create physic scene
            /*CoreDescription coreDesc = new CoreDescription();
            UserOutput output = new UserOutput();

            Core = new Core(coreDesc, output);
            Core.SetParameter(PhysicsParameter.ContinuousCollisionDetection, false);
            Core.SetParameter(PhysicsParameter.ContinuousCollisionDetectionEpsilon, 0.01f);

            SceneDescription sceneDesc = new SceneDescription()
            {
                SimulationType = SimulationType.Software,//Hardware,
                MaximumBounds = new Bounds3(-1000,-1000,-1000,1000,1000,1000),
                UpAxis = 2,
                Gravity = new Vector3(0.0f, -9.81f*1.3f, 0.0f),
                GroundPlaneEnabled = false
            };
            this.Scene = Core.CreateScene(sceneDesc);
            manager = Scene.CreateControllerManager();
               */
            #endregion
               // _sceneGraph = new Logic.SceneGraph.SceneGraph();
            editor = new GameEditor(gameLevel);
            GraphicPipeleine = new RenderPipeline(DeviceManager.GraphicsDevice, Camera);
            CreateShader();
            editor.SetDestEngine();
            editor.SetFont(Font1);
        }
        public void RenderToPicture(Camera Camera, Vector3 lightDir)
        {
            Device.RasterizerState = rs;
            Device.DepthStencilState = DepthStencilState.Default;
            Device.BlendState = BlendState.Opaque;

            Device.SamplerStates[0] = SamplerState.LinearWrap;
            Device.SamplerStates[1] = SamplerState.PointWrap;

            if (EnableShadows)
            {
                RenderToShadowMap(lightViewProjection, lightDir);
                Render.Materials.Material.ObjectRenderEffect.Parameters["ShadowMap"].SetValue(shadowRenderTarget);
            }

            this.Device.Clear(Color.LightGray);
            Device.RasterizerState = rs;

            ResourceCollectorXNA.Engine.Render.Materials.Material.ObjectRenderEffect.Parameters["Projection"].SetValue(Camera.Projection);
            ResourceCollectorXNA.Engine.Render.Materials.Material.ObjectRenderEffect.Parameters["View"].SetValue(Camera.View);
            string AnimTeh = "", NotAnimTeh = "";
            if (EnableShadows)
            {
                if (SmoothShadows)
                {
                    AnimTeh = Shader.AnimRenderSMSmooth;
                    NotAnimTeh = Shader.NotAnimRenderSMSmooth;
                }
                else
                {
                    AnimTeh = Shader.AnimRenderSM;
                    NotAnimTeh = Shader.NotAnimRenderSM;
                }
            }
            else
            {
                AnimTeh = Shader.AnimRenderNoSM;
                NotAnimTeh = Shader.NotAnimRenderNoSM;
            }

            MyContainer<PivotObject> Objects = ArraysPerTehnique[AnimTeh].Objects;
            if (!Objects.IsEmpty)
            {
                Materials.Material.ObjectRenderEffect.CurrentTechnique = Materials.Material.ObjectRenderEffect.Techniques[AnimTeh];
                foreach (PivotObject wo in Objects)
                {
                    Render.Materials.Material.ObjectRenderEffect.Parameters["World"].SetValue(wo.transform);
                    wo.HaveRenderAspect().SelfRender(0, wo.HaveMaterial());
                }
            }

            Objects = ArraysPerTehnique[NotAnimTeh].Objects;
            if (!Objects.IsEmpty)
            {
                Materials.Material.ObjectRenderEffect.CurrentTechnique = Materials.Material.ObjectRenderEffect.Techniques[NotAnimTeh];
                foreach (PivotObject wo in Objects)
                {
                    Render.Materials.Material.ObjectRenderEffect.Parameters["World"].SetValue(wo.transform);
                    wo.HaveRenderAspect().SelfRender(0, wo.HaveMaterial());
                }
            }

            //////////
            if (EnableShadows)
            {
                Objects = ArraysPerTehnique[Shader.AnimRenderNoSM].Objects;
                if (!Objects.IsEmpty)
                {
                    Materials.Material.ObjectRenderEffect.CurrentTechnique = Materials.Material.ObjectRenderEffect.Techniques[Shader.AnimRenderNoSM];
                    foreach (PivotObject wo in Objects)
                    {
                        Render.Materials.Material.ObjectRenderEffect.Parameters["World"].SetValue(wo.transform);
                        wo.HaveRenderAspect().SelfRender(0, wo.HaveMaterial());
                    }
                }

                Objects = ArraysPerTehnique[Shader.NotAnimRenderNoSM].Objects;
                if (!Objects.IsEmpty)
                {
                    Materials.Material.ObjectRenderEffect.CurrentTechnique = Materials.Material.ObjectRenderEffect.Techniques[Shader.NotAnimRenderNoSM];
                    foreach (PivotObject wo in Objects)
                    {
                        Render.Materials.Material.ObjectRenderEffect.Parameters["World"].SetValue(wo.transform);
                        wo.HaveRenderAspect().SelfRender(0, wo.HaveMaterial());
                    }
                }
            }

            if (EnableDebugRender)
            {
                //ДЕБАГ РЕНДЕР

                _visualizationEffect.World = Matrix.Identity;
                _visualizationEffect.View = Camera.View;
                _visualizationEffect.Projection = Camera.Projection;
                _visualizationEffect.CurrentTechnique.Passes[0].Apply();
                int a = 0;
                foreach (PivotObject wo in debugRenderArray)
                {
                    if (wo.editorAspect.isActive)
                    {
                        a++;
                    }
                   // debugRenderer.RenderTransformedBB(wo.boundingShape);
                   // debugRenderer.RenderAABR(wo.boundingShape);
                    debugRenderer.RenderAABB(wo.raycastaspect.boundingShape,wo.editorAspect.isActive);
                }
            }
        }