Ejemplo n.º 1
0
        private void CreatePipeline()
        {
            const int TargetWidth  = 800;
            const int TargetHeight = 480;

            // Create render targets
            textures = new []
            {
                Texture.New2D(GraphicsDevice, TargetWidth, TargetHeight, PixelFormat.R8G8B8A8_UNorm, TextureFlags.RenderTarget | TextureFlags.ShaderResource),
                Texture.New2D(GraphicsDevice, TargetWidth, TargetHeight, PixelFormat.R8G8B8A8_UNorm, TextureFlags.RenderTarget | TextureFlags.ShaderResource),
                Texture.New2D(GraphicsDevice, TargetWidth, TargetHeight, PixelFormat.R8G8B8A8_UNorm, TextureFlags.RenderTarget | TextureFlags.ShaderResource)
            };

            var depthBuffer = Texture.New2D(GraphicsDevice, TargetWidth, TargetHeight, PixelFormat.D24_UNorm_S8_UInt, TextureFlags.DepthStencil);

            var multipleRenderFrames = new DirectRenderFrameProvider(RenderFrame.FromTexture(textures, depthBuffer));

            // Setup the default rendering pipeline
            scene = new Scene
            {
                Settings =
                {
                    GraphicsCompositor              = new SceneGraphicsCompositorLayers
                    {
                        Cameras =                               { mainCamera.Get <CameraComponent>() },
                        Master  =
                        {
                            Renderers               =
                            {
                                new ClearRenderFrameRenderer {
                                    Color           = Color.Lavender, Output = multipleRenderFrames
                                },
                                new SceneCameraRenderer      {
                                    Mode            = new CameraRendererModeForward{
                                        ModelEffect = "MultipleRenderTargetsEffect"
                                    }, Output       = multipleRenderFrames
                                },
                                new ClearRenderFrameRenderer {
                                    Output          = new MasterRenderFrameProvider()
                                },
                                new SceneDelegateRenderer(DisplayGBuffer)
                                {
                                    Name            = "DisplayGBuffer"
                                },
                            }
                        }
                    }
                }
            };

            SceneSystem.SceneInstance = new SceneInstance(Services, scene);
        }
Ejemplo n.º 2
0
        public override void Initialize(Entity cameraRoot, CameraComponent leftCamera, CameraComponent rightCamera, bool requireMirror = false)
        {
            var size = RenderFrameSize;

            if (!GoogleVr.Init(size.Width, size.Height))
            {
                throw new Exception("Failed to Init Google VR SDK");
            }

            RenderFrameProvider = new DirectRenderFrameProvider(RenderFrame.FromTexture(
                                                                    Texture.New2D(GraphicsDevice, size.Width, size.Height, PixelFormat.R8G8B8A8_UNorm_SRgb, TextureFlags.RenderTarget | TextureFlags.ShaderResource)
                                                                    ));

            var compositor = (SceneGraphicsCompositorLayers)Game.SceneSystem.SceneInstance.RootScene.Settings.GraphicsCompositor;

            compositor.Master.Add(new SceneDelegateRenderer((x, y) =>
            {
                var frame = GoogleVr.GetNextFrame();
                GoogleVr.SubmitRenderTarget(x.GraphicsContext, RenderFrameProvider.RenderFrame.RenderTargets[0], frame, 0);
                if (!GoogleVr.SubmitFrame(GraphicsDevice, frame, ref headMatrix))
                {
                    throw new Exception("Failed to SubmitFrame to Google VR SDK");
                }
            }));

            leftCamera.UseCustomProjectionMatrix  = true;
            rightCamera.UseCustomProjectionMatrix = true;
            leftCamera.UseCustomViewMatrix        = true;
            rightCamera.UseCustomViewMatrix       = true;
            leftCamera.NearClipPlane  *= ViewScaling;
            rightCamera.NearClipPlane *= ViewScaling;

            if (requireMirror)
            {
                MirrorTexture = RenderFrameProvider.RenderFrame.RenderTargets[0]; //we don't really have a mirror in this case but avoid crashes
            }

            base.Initialize(cameraRoot, leftCamera, rightCamera, requireMirror);
        }