예제 #1
0
        /// <summary>
        /// Create an instance of the game test
        /// </summary>
        public UnitTestGameBase()
        {
            StopOnFrameCount = -1;

            GraphicsDeviceManager.PreferredGraphicsProfile = new [] { GraphicsProfile.Level_11_0 };

            graphicsCompositor = new SceneGraphicsCompositorLayers
            {
                Cameras = { Camera.Get<CameraComponent>() },
                Master =
                {
                    Renderers =
                    {
                        new ClearRenderFrameRenderer { Color = Color.Green, Name = "Clear frame" },

                        new SceneDelegateRenderer(SpecificDrawBeforeUI) { Name = "Delegate before main UI" },

                        new SceneCameraRenderer { Mode = SceneCameraRenderer },
                    }
                }
            };
            Scene = new Scene { Settings = { GraphicsCompositor = graphicsCompositor } };

            Scene.AddChild(UIRoot);
            Scene.AddChild(Camera);

            Camera.Transform.Position = new Vector3(0, 0, 1000);

            UIComponent.IsFullScreen = true;
            UIComponent.VirtualResolution = new Vector3(1000, 500, 500);
            UIComponent.VirtualResolutionMode = VirtualResolutionMode.FixedWidthFixedHeight;
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SceneInstance" /> class.
        /// </summary>
        /// <param name="services">The services.</param>
        /// <param name="sceneEntityRoot">The scene entity root.</param>
        /// <param name="enableScripting">if set to <c>true</c> [enable scripting].</param>
        /// <exception cref="System.ArgumentNullException">services
        /// or
        /// sceneEntityRoot</exception>
        public SceneInstance(IServiceRegistry services, Scene sceneEntityRoot, bool enableScripting = true) : base(services)
        {
            if (services == null) throw new ArgumentNullException("services");

            this.enableScripting = enableScripting;
            Scene = sceneEntityRoot;
            RendererTypes = new EntityComponentRendererTypeCollection();
            ComponentTypeAdded += EntitySystemOnComponentTypeAdded;
            Load();
        }
예제 #3
0
        public static SceneAsset Create()
        {
            // Create a new root entity, and make sure transformation component is created
            var rootEntity = new Scene { Name = "Scene" };
            rootEntity.GetOrCreate(TransformComponent.Key);

            return new SceneAsset
            {
                Hierarchy =
                {
                    Entities = { rootEntity },
                    RootEntity = rootEntity.Id,
                }
            };
        }
예제 #4
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            Window.AllowUserResizing = true;

            // Instantiate a scene with a single entity and model component
            var scene = new Scene();

            // Create a cube entity
            cubeEntity = new Entity();

            // Create a procedural model with a diffuse material
            var model = new Model();
            var material = Material.New(
                new MaterialDescriptor
                {
                    Attributes =
                    {
                        Diffuse = new MaterialDiffuseMapFeature(new ComputeColor(Color.White)),
                        DiffuseModel = new MaterialDiffuseLambertModelFeature()
                    }
                });
            model.Materials.Add(material);
            cubeEntity.Add(new ModelComponent(model));

            var modelDescriptor = new ProceduralModelDescriptor(new CubeProceduralModel());
            modelDescriptor.GenerateModel(Services, model);

            // Add the cube to the scene
            scene.AddChild(cubeEntity);

            // Create a camera entity and add it to the scene
            var cameraEntity = new Entity { new CameraComponent() };
            cameraEntity.Transform.Position = new Vector3(0, 0, 5);
            scene.AddChild(cameraEntity);

            // Create a light
            var lightEntity = new Entity()
            {
                new LightComponent()
            };

            lightEntity.Transform.Position = new Vector3(0, 0, 1);
            lightEntity.Transform.Rotation = Quaternion.RotationY(MathUtil.DegreesToRadians(45));
            scene.AddChild(lightEntity);

            // Create a graphics compositor
            var compositor = new SceneGraphicsCompositorLayers();

            bool isLDR = false;
            if (isLDR)
            {
                compositor.Master.Renderers.Add(new ClearRenderFrameRenderer());
                compositor.Master.Renderers.Add(new SceneCameraRenderer() {});
            }
            else
            {
                var layer = new SceneGraphicsLayer();
                var renderHDROutput = new LocalRenderFrameProvider { Descriptor = { Format = RenderFrameFormat.HDR, DepthFormat = RenderFrameDepthFormat.Shared} };
                layer.Output = renderHDROutput;
                layer.Renderers.Add(new ClearRenderFrameRenderer());
                layer.Renderers.Add(new SceneCameraRenderer());
                compositor.Layers.Add(layer);
                compositor.Master.Renderers.Add(new SceneEffectRenderer()
                {
                    Effect = new PostProcessingEffects()
                });
            }
            compositor.Cameras.Add(cameraEntity.Get<CameraComponent>());

            SceneSystem.SceneInstance = new SceneInstance(Services, scene);

            // Use this graphics compositor
            scene.Settings.GraphicsCompositor = compositor;

            // Create a scene instance
            SceneSystem.SceneInstance = new SceneInstance(Services, scene);
        }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChildSceneComponent"/> class.
 /// </summary>
 /// <param name="scene">The scene.</param>
 public ChildSceneComponent(Scene scene)
 {
     Scene = scene;
 }
        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);
        }
예제 #7
0
        private void Load()
        {
            previousScene = Scene;
            RendererTypes.Clear();

            OnSceneChanged();

            // If Scene is null, early exit
            if (Scene == null)
            {
                return;
            }

            // Initialize processors
            if (enableScripting)
                AddProcessor(new ScriptProcessor());   // Order: -100000
            AddProcessor(new SceneProcessor(this));    // Order: -10000
            AddProcessor(new HierarchicalProcessor()); // Order: -1000  - Important to pre-register this processor
            AddProcessor(new TransformProcessor());    // Order: -100
            AddProcessor(new CameraProcessor());       // Order: -10    - By default, as a scene without a camera is not really possible
            Add(Scene);

            // TODO: RendererTypes could be done outside this instance.
            HandleRendererTypes();
        }